diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index f4bf1d67..7c438b16 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -22,18 +22,19 @@ jobs: - ShellyColorBulb - ShellyDuo - ShellyI3 + - ShellyMini1Gen3 + - ShellyMini1PMGen3 - ShellyPlug - ShellyPlugS - ShellyPlus1 + - ShellyPlus1Mini - ShellyPlus1PM + - ShellyPlus1PMMini - ShellyPlus2PM - ShellyPlusI4 - ShellyPlusPlugS - ShellyPlusRGBWPM - - ShellyPlus1Mini - - ShellyPlus1PMMini - - ShellyMini1Gen3 - - ShellyMini1PMGen3 + - ShellyPlusUni - ShellyRGBW2 - ShellyUNI - ShellyVintage diff --git a/Makefile b/Makefile index bfd8a110..ded7e7d0 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ MAKEFLAGS += --warn-undefined-variables --no-builtin-rules .PHONY: build check-format format release upload \ - Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI ShellyPlus1Mini ShellyPlusRGBWPM ShellyMini1Gen3 ShellyMini1PMGen3 + Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI ShellyPlus1Mini ShellyPlusRGBWPM ShellyMini1Gen3 ShellyMini1PMGen3 ShellyPlusUni .SUFFIXES: MOS ?= mos @@ -110,6 +110,10 @@ ShellyRGBW2: build-ShellyRGBW2 ShellyUNI: build-ShellyUNI @true +ShellyPlusUni: PLATFORM=esp32 +ShellyPlusUni: build-ShellyPlusUni + @true + ShellyVintage: build-ShellyVintage @true diff --git a/mos.yml b/mos.yml index 35ca7c57..d9cbf59d 100644 --- a/mos.yml +++ b/mos.yml @@ -1179,16 +1179,25 @@ conds: - when: build_vars.MODEL == "ShellyUNI" apply: name: uni + sources: + - src/DS18XXX + - src/DHT libs: + - location: https://github.com/mongoose-os-libs/onewire + - location: https://github.com/mongoose-os-libs/dht - location: https://github.com/mongoose-os-libs/mongoose variant: esp8266-nossl - - location: https://github.com/mongoose-os-libs/ade7953 build_vars: FLASH_SIZE: 2097152 FS_SIZE: 262144 BOOT_CONFIG_ADDR: 0x1000 MGOS_ROOT_FS_TYPE: SPIFFS cdefs: + RELAY1_GPIO: 15 + RELAY2_GPIO: 4 + SWITCH1_GPIO: 12 + SWITCH2_GPIO: 13 + SENSOR_GPIO: 5 LED_GPIO: 0 LED_ON: 0 BTN_GPIO: 2 @@ -1213,6 +1222,74 @@ conds: - ["gdo1", "gdo", {title: "GDO1 settings"}] - ["gdo1.name", "Garage Door"] + - ["ts1", "ts", {title: "TS1 settings"}] + - ["ts1.name", "Shelly TS1"] + - ["ts2", "ts", {title: "TS2 settings"}] + - ["ts2.name", "Shelly TS2"] + - ["ts3", "ts", {title: "TS3 settings"}] + - ["ts3.name", "Shelly TS3"] + + - when: build_vars.MODEL == "ShellyPlusUni" + apply: + name: PlusUni + sources: + - src/DS18XXX + - src/DHT + - src/ShellyUNI + libs: + - location: https://github.com/mongoose-os-libs/onewire + - location: https://github.com/mongoose-os-libs/dht + - location: https://github.com/mongoose-os-libs/mongoose + build_vars: + ESP_IDF_EXTRA_PARTITION: "aux,0x55,0x00,0x3f0000,48K" + ESP_IDF_EXTRA_PARTITION_2: "shelly,data,0x88,0x3fc000,16K,encrypted" + ESP_IDF_SDKCONFIG_OPTS: > + ${build_vars.ESP_IDF_SDKCONFIG_OPTS} + CONFIG_FREERTOS_UNICORE=y + CONFIG_ESPTOOLPY_FLASHMODE_DIO=y + cdefs: + LED_GPIO: 18 + LED_ON: 0 + BTN_GPIO: -1 + BTN_DOWN: 0 + RELAY1_GPIO: 21 + RELAY2_GPIO: 19 + SWITCH1_GPIO: 37 + SWITCH2_GPIO: 38 + SENSOR_GPIO: 13 + PRODUCT_HW_REV: "0.1.4" + STOCK_FW_MODEL: PlusUni + MAX_NUM_HAP_SESSIONS: 16 + config_schema: + - ["device.id", "ShellyPlusUni-????????????"] + - ["shelly.name", "ShellyPlusUni--????????????"] + - ["wifi.ap.ssid", "ShellyPlusUni--????????????"] + + - ["sw1", "sw", {title: "SW1 settings"}] + - ["sw1.name", "Shelly SW1"] + - ["in1", "in", {title: "Input 1 settings"}] + - ["in1.ssw.name", "Shelly SSW1"] + - ["in1.sensor.name", "Shelly S1"] + - ["sw2", "sw", {title: "SW2 settings"}] + - ["sw2.name", "Shelly SW2"] + - ["in2", "in", {title: "Input 2 settings"}] + - ["in2.ssw.name", "Shelly SSW2"] + - ["in2.sensor.name", "Shelly S2"] + - ["gdo1", "gdo", {title: "GDO1 settings"}] + - ["gdo1.name", "Garage Door"] + + - ["ts1", "ts", {title: "TS1 settings"}] + - ["ts1.name", "Shelly TS1"] + - ["ts2", "ts", {title: "TS2 settings"}] + - ["ts2.name", "Shelly TS2"] + - ["ts3", "ts", {title: "TS3 settings"}] + - ["ts3.name", "Shelly TS3"] + - ["ts4", "ts", {title: "TS4 settings"}] + - ["ts4.name", "Shelly TS4"] + - ["ts5", "ts", {title: "TS5 settings"}] + - ["ts5.name", "Shelly TS5"] + + - when: build_vars.MODEL == "ShellyVintage" apply: name: bulb6w # To allow OTA from stock fw. diff --git a/src/ShellyUNI/shelly_init.cpp b/src/ShellyUNI/shelly_init.cpp index 1f70956e..32dfbc4c 100644 --- a/src/ShellyUNI/shelly_init.cpp +++ b/src/ShellyUNI/shelly_init.cpp @@ -23,22 +23,35 @@ #include "shelly_main.hpp" #include "shelly_noisy_input_pin.hpp" #include "shelly_sys_led_btn.hpp" +#include "shelly_temp_sensor_ow.hpp" +#include "shelly_dht_sensor.hpp" namespace shelly { +static std::unique_ptr s_onewire; +static std::vector> sensors; + void CreatePeripherals(std::vector> *inputs, std::vector> *outputs, std::vector> *pms, std::unique_ptr *sys_temp) { - outputs->emplace_back(new OutputPin(1, 15, 1)); - outputs->emplace_back(new OutputPin(2, 4, 1)); - auto *in1 = new NoisyInputPin(1, 12, 1, MGOS_GPIO_PULL_NONE, true); - in1->AddHandler(std::bind(&HandleInputResetSequence, in1, 4, _1, _2)); + outputs->emplace_back(new OutputPin(1, RELAY1_GPIO, 1)); + outputs->emplace_back(new OutputPin(2, RELAY2_GPIO, 1)); + auto *in1 = new NoisyInputPin(1, SWITCH1_GPIO, 1, MGOS_GPIO_PULL_NONE, true); + in1->AddHandler(std::bind(&HandleInputResetSequence, in1, LED_GPIO, _1, _2)); in1->Init(); inputs->emplace_back(in1); - auto *in2 = new NoisyInputPin(2, 13, 1, MGOS_GPIO_PULL_NONE, false); + auto *in2 = new NoisyInputPin(2, SWITCH2_GPIO, 1, MGOS_GPIO_PULL_NONE, false); in2->Init(); inputs->emplace_back(in2); + + s_onewire.reset(new Onewire(SENSOR_GPIO, SENSOR_GPIO)); + sensors = s_onewire->DiscoverAll(); + if (sensors.empty()) { + s_onewire.reset(); + sensors = DiscoverDHTSensors(SENSOR_GPIO, SENSOR_GPIO); + } + InitSysLED(LED_GPIO, LED_ON); InitSysBtn(BTN_GPIO, BTN_DOWN); } @@ -46,26 +59,22 @@ void CreatePeripherals(std::vector> *inputs, void CreateComponents(std::vector> *comps, std::vector> *accs, HAPAccessoryServerRef *svr) { - // Garage door opener mode. - if (mgos_sys_config_get_shelly_mode() == 2) { - auto *gdo_cfg = (struct mgos_config_gdo *) mgos_sys_config_get_gdo1(); - std::unique_ptr gdo(new hap::GarageDoorOpener( - 1, FindInput(1), FindInput(2), FindOutput(1), FindOutput(2), gdo_cfg)); - if (gdo == nullptr || !gdo->Init().ok()) { - return; - } - gdo->set_primary(true); - mgos::hap::Accessory *pri_acc = (*accs)[0].get(); - pri_acc->SetCategory(kHAPAccessoryCategory_GarageDoorOpeners); - pri_acc->AddService(gdo.get()); - comps->emplace_back(std::move(gdo)); - return; + bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor; + + if (gdo_mode) { + hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1), + FindOutput(2), mgos_sys_config_get_gdo1(), comps, accs, + svr, true); + } else { + CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(), + comps, accs, svr, false /* to_pri_acc */); + CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_in2(), + comps, accs, svr, false /* to_pri_acc */); } - CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(), - comps, accs, svr, false /* to_pri_acc */); - CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_in2(), - comps, accs, svr, false /* to_pri_acc */); + if (!sensors.empty()) { + CreateHAPSensors(&sensors, comps, accs, svr); + } } } // namespace shelly