diff --git a/src/ShellyPlus1/shelly_init.cpp b/src/ShellyPlus1/shelly_init.cpp index e56794bb..1bc8a67b 100644 --- a/src/ShellyPlus1/shelly_init.cpp +++ b/src/ShellyPlus1/shelly_init.cpp @@ -56,6 +56,7 @@ void CreatePeripherals(std::vector> *inputs, inputs->emplace_back(in2); } else { + RestoreUART(); InitSysLED(LED_GPIO, LED_ON); } InitSysBtn(BTN_GPIO, BTN_DOWN); @@ -67,7 +68,7 @@ void CreateComponents(std::vector> *comps, bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor; bool ext_sensor_switch = (FindInput(2) != nullptr); bool detatched_sensor = - (mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached) && + (mgos_sys_config_get_sw1_in_mode() == (int) InMode::kDetached) && !gdo_mode && ext_sensor_switch; bool single_accessory = sensors.empty() && !detatched_sensor; if (gdo_mode) { diff --git a/src/ShellyPlus1PM/shelly_init.cpp b/src/ShellyPlus1PM/shelly_init.cpp index 7b66eebf..5772751a 100644 --- a/src/ShellyPlus1PM/shelly_init.cpp +++ b/src/ShellyPlus1PM/shelly_init.cpp @@ -118,6 +118,7 @@ void CreatePeripherals(std::vector> *inputs, inputs->emplace_back(in2); } else { + RestoreUART(); InitSysLED(LED_GPIO, LED_ON); } InitSysBtn(BTN_GPIO, BTN_DOWN); @@ -129,7 +130,7 @@ void CreateComponents(std::vector> *comps, bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor; bool ext_sensor_switch = (FindInput(2) != nullptr); bool detatched_sensor = - (mgos_sys_config_get_sw1_in_mode() != (int) InMode::kDetached) && + (mgos_sys_config_get_sw1_in_mode() == (int) InMode::kDetached) && !gdo_mode && ext_sensor_switch; bool single_accessory = sensors.empty() && !detatched_sensor; if (gdo_mode) { diff --git a/src/ShellyPlus2PM/shelly_init.cpp b/src/ShellyPlus2PM/shelly_init.cpp index bfee113d..b3c45953 100644 --- a/src/ShellyPlus2PM/shelly_init.cpp +++ b/src/ShellyPlus2PM/shelly_init.cpp @@ -213,8 +213,6 @@ void CreatePeripherals(std::vector> *inputs, int pin_out = 0; int pin_in = 1; - // TODO: this blocks UART as UART TX is GPIO1. We should release if there is - // no if (DetectAddon(pin_in, pin_out)) { s_onewire.reset(new Onewire(pin_in, pin_out)); sensors = s_onewire->DiscoverAll(); @@ -228,6 +226,7 @@ void CreatePeripherals(std::vector> *inputs, inputs->emplace_back(in_digital); } else { + RestoreUART(); InitSysLED(LED_GPIO, LED_ON); } @@ -237,8 +236,6 @@ void CreatePeripherals(std::vector> *inputs, void CreateComponents(std::vector> *comps, std::vector> *accs, HAPAccessoryServerRef *svr) { - bool single_accessory = sensors.empty(); - if (mgos_sys_config_get_shelly_mode() == (int) Mode::kRollerShutter) { hap::CreateHAPWC(1, FindInput(1), FindInput(2), FindOutput(1), FindOutput(2), FindPM(1), FindPM(2), @@ -247,6 +244,8 @@ void CreateComponents(std::vector> *comps, return; } + bool single_accessory = sensors.empty(); + if (mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor) { hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1), FindOutput(2), mgos_sys_config_get_gdo1(), comps, accs, diff --git a/src/ShellyPlusI4/shelly_init.cpp b/src/ShellyPlusI4/shelly_init.cpp index 79ad225d..1da619b7 100644 --- a/src/ShellyPlusI4/shelly_init.cpp +++ b/src/ShellyPlusI4/shelly_init.cpp @@ -63,6 +63,7 @@ void CreatePeripherals(std::vector> *inputs, sensors = DiscoverDHTSensors(pin_in, pin_out); } } else { + RestoreUART(); InitSysLED(LED_GPIO, LED_ON); } InitSysBtn(BTN_GPIO, BTN_DOWN); diff --git a/src/shelly_main.cpp b/src/shelly_main.cpp index 92b5681a..2d1fdb87 100644 --- a/src/shelly_main.cpp +++ b/src/shelly_main.cpp @@ -121,6 +121,16 @@ static std::vector s_hap_accs; static std::unique_ptr s_sys_temp_sensor; std::vector> g_comps; +void RestoreUART() { + struct mgos_uart_config ucfg; + int uart_no = 0; + mgos_uart_config_set_defaults(uart_no, &ucfg); + + if (!mgos_uart_configure(uart_no, &ucfg)) { + LOG(LL_ERROR, ("Failed to configure UART%d", uart_no)); + } +} + bool DetectAddon(int pin_in, int pin_out) { // case 1: input with pull up mgos_gpio_setup_input(pin_in, MGOS_GPIO_PULL_UP); diff --git a/src/shelly_main.hpp b/src/shelly_main.hpp index fc7ce188..cf7acdb7 100644 --- a/src/shelly_main.hpp +++ b/src/shelly_main.hpp @@ -41,6 +41,7 @@ namespace shelly { extern std::vector> g_comps; bool DetectAddon(int pin_in, int pin_out); +void RestoreUART(); Input *FindInput(int id); Output *FindOutput(int id); PowerMeter *FindPM(int id);