15
15
* limitations under the License.
16
16
*/
17
17
18
+ #include " shelly_dht_sensor.hpp"
18
19
#include " shelly_hap_input.hpp"
19
20
#include " shelly_hap_stateless_switch.hpp"
20
21
#include " shelly_main.hpp"
21
22
#include " shelly_noisy_input_pin.hpp"
22
23
#include " shelly_sys_led_btn.hpp"
23
24
#include " shelly_temp_sensor_ntc.hpp"
25
+ #include " shelly_temp_sensor_ow.hpp"
24
26
25
27
namespace shelly {
26
28
29
+ static std::unique_ptr<Onewire> s_onewire;
30
+ static std::vector<std::unique_ptr<TempSensor>> sensors;
31
+
27
32
void CreatePeripherals (std::vector<std::unique_ptr<Input>> *inputs,
28
33
std::vector<std::unique_ptr<Output>> *outputs UNUSED_ARG,
29
34
std::vector<std::unique_ptr<PowerMeter>> *pms UNUSED_ARG,
@@ -47,7 +52,18 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
47
52
48
53
sys_temp->reset (new TempSensorSDNT1608X103F3950 (32 , 3 .3f , 10000 .0f ));
49
54
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
+ }
51
67
InitSysBtn (BTN_GPIO, BTN_DOWN);
52
68
}
53
69
@@ -58,6 +74,10 @@ void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
58
74
hap::CreateHAPInput (2 , mgos_sys_config_get_in2 (), comps, accs, svr);
59
75
hap::CreateHAPInput (3 , mgos_sys_config_get_in3 (), comps, accs, svr);
60
76
hap::CreateHAPInput (4 , mgos_sys_config_get_in4 (), comps, accs, svr);
77
+
78
+ if (!sensors.empty ()) {
79
+ CreateHAPSensors (&sensors, comps, accs, svr);
80
+ }
61
81
}
62
82
63
83
} // namespace shelly
0 commit comments