Skip to content

Commit a73951b

Browse files
markirbMarkus Kirberg
authored and
Markus Kirberg
committed
add i4
1 parent 3790a94 commit a73951b

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

mos.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,12 @@ conds:
683683
- when: build_vars.MODEL == "ShellyPlusI4"
684684
apply:
685685
name: PlusI4
686+
sources:
687+
- src/DS18XXX
688+
- src/DHT
689+
libs:
690+
- location: https://github.com/mongoose-os-libs/onewire
691+
- location: https://github.com/mongoose-os-libs/dht
686692
build_vars:
687693
MGOS_ROOT_FS_TYPE: LFS
688694
MGOS_ROOT_FS_SIZE: 458752
@@ -716,6 +722,12 @@ conds:
716722
- ["in4", "in", {title: "Input 4 settings"}]
717723
- ["in4.ssw.name", "Shelly SSW4"]
718724
- ["in4.sensor.name", "Shelly S4"]
725+
- ["ts1", "ts", {title: "TS1 settings"}]
726+
- ["ts1.name", "Shelly TS1"]
727+
- ["ts2", "ts", {title: "TS2 settings"}]
728+
- ["ts2.name", "Shelly TS2"]
729+
- ["ts3", "ts", {title: "TS3 settings"}]
730+
- ["ts3.name", "Shelly TS3"]
719731

720732
- when: build_vars.MODEL == "ShellyRGBW2"
721733
apply:

src/ShellyPlusI4/shelly_init.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,20 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include "shelly_dht_sensor.hpp"
1819
#include "shelly_hap_input.hpp"
1920
#include "shelly_hap_stateless_switch.hpp"
2021
#include "shelly_main.hpp"
2122
#include "shelly_noisy_input_pin.hpp"
2223
#include "shelly_sys_led_btn.hpp"
2324
#include "shelly_temp_sensor_ntc.hpp"
25+
#include "shelly_temp_sensor_ow.hpp"
2426

2527
namespace shelly {
2628

29+
static std::unique_ptr<Onewire> s_onewire;
30+
static std::vector<std::unique_ptr<TempSensor>> sensors;
31+
2732
void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
2833
std::vector<std::unique_ptr<Output>> *outputs UNUSED_ARG,
2934
std::vector<std::unique_ptr<PowerMeter>> *pms UNUSED_ARG,
@@ -47,7 +52,18 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
4752

4853
sys_temp->reset(new TempSensorSDNT1608X103F3950(32, 3.3f, 10000.0f));
4954

50-
InitSysLED(LED_GPIO, LED_ON);
55+
int pin_in = 19;
56+
int pin_out = LED_GPIO;
57+
if (DetectAddon(pin_in, pin_out)) {
58+
s_onewire.reset(new Onewire(pin_in, pin_out));
59+
sensors = s_onewire->DiscoverAll();
60+
if (sensors.empty()) {
61+
s_onewire.reset();
62+
sensors = DiscoverDHTSensors(pin_in, pin_out);
63+
}
64+
} else {
65+
InitSysLED(LED_GPIO, LED_ON);
66+
}
5167
InitSysBtn(BTN_GPIO, BTN_DOWN);
5268
}
5369

@@ -58,6 +74,10 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
5874
hap::CreateHAPInput(2, mgos_sys_config_get_in2(), comps, accs, svr);
5975
hap::CreateHAPInput(3, mgos_sys_config_get_in3(), comps, accs, svr);
6076
hap::CreateHAPInput(4, mgos_sys_config_get_in4(), comps, accs, svr);
77+
78+
if (!sensors.empty()) {
79+
CreateHAPSensors(&sensors, comps, accs, svr);
80+
}
6181
}
6282

6383
} // namespace shelly

0 commit comments

Comments
 (0)