From 5212db42275ab3320fd94140ddbfe316087eddf1 Mon Sep 17 00:00:00 2001 From: Markus Kirberg Date: Fri, 14 Jun 2024 12:19:42 +0200 Subject: [PATCH] fix logic and restore uart --- src/ShellyPlus1/shelly_init.cpp | 10 +++++++++- src/ShellyPlus1PM/shelly_init.cpp | 11 ++++++++++- src/ShellyPlus2PM/shelly_init.cpp | 16 ++++++++++++---- src/ShellyPlusI4/shelly_init.cpp | 9 +++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) diff --git a/src/ShellyPlus1/shelly_init.cpp b/src/ShellyPlus1/shelly_init.cpp index e56794bb..5a746aea 100644 --- a/src/ShellyPlus1/shelly_init.cpp +++ b/src/ShellyPlus1/shelly_init.cpp @@ -56,6 +56,14 @@ void CreatePeripherals(std::vector> *inputs, inputs->emplace_back(in2); } else { + // restore uart tx on pin 1 + 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)); + } + InitSysLED(LED_GPIO, LED_ON); } InitSysBtn(BTN_GPIO, BTN_DOWN); @@ -67,7 +75,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..a5ca554b 100644 --- a/src/ShellyPlus1PM/shelly_init.cpp +++ b/src/ShellyPlus1PM/shelly_init.cpp @@ -118,6 +118,15 @@ void CreatePeripherals(std::vector> *inputs, inputs->emplace_back(in2); } else { + // restore uart tx on pin 1 + 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)); + } + InitSysLED(LED_GPIO, LED_ON); } InitSysBtn(BTN_GPIO, BTN_DOWN); @@ -129,7 +138,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..db8afbaf 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,16 @@ void CreatePeripherals(std::vector> *inputs, inputs->emplace_back(in_digital); } else { + // restore uart tx on pin 1 + // restore uart tx on pin 1 + 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)); + } + InitSysLED(LED_GPIO, LED_ON); } @@ -237,8 +245,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 +253,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..968e0e4d 100644 --- a/src/ShellyPlusI4/shelly_init.cpp +++ b/src/ShellyPlusI4/shelly_init.cpp @@ -63,6 +63,15 @@ void CreatePeripherals(std::vector> *inputs, sensors = DiscoverDHTSensors(pin_in, pin_out); } } else { + // restore uart tx on pin 1 + 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)); + } + InitSysLED(LED_GPIO, LED_ON); } InitSysBtn(BTN_GPIO, BTN_DOWN);