diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 4811e0073..f29d95cb8 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -3,6 +3,7 @@ * Change pubsubclient MQTT_KEEPALIVE from 10 to 30 seconds in preparation of AWS IoT support * Add support for AWS IoT with TLS 1.2 on core 2.5.2. Full doc here: https://github.com/arendst/Sonoff-Tasmota/wiki/AWS-IoT * Add some MQTT housekeeping which might solve issue (#5755) + * Add command SetOption65 0/1 and more Tuya Serial based device support (#5815) * * 6.5.0.14 20190602 * Change webserver HTML input, button, textarea, and select name based on id diff --git a/sonoff/settings.h b/sonoff/settings.h index fcb58a174..0fa7f5d48 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -78,7 +78,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t no_hold_retain : 1; // bit 12 (v6.4.1.19) - SetOption62 - Don't use retain flag on HOLD messages uint32_t no_power_feedback : 1; // bit 13 (v6.5.0.9) - SetOption63 - Don't scan relay power state at restart uint32_t use_underscore : 1; // bit 14 (v6.5.0.12) - SetOption64 - Enable "_" instead of "-" as sensor index separator - uint32_t tuya_show_dimmer : 1; // bit 15 (v6.5.0.12) - SetOption65 - Enable or Disable Dimmer slider control + uint32_t tuya_show_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - Enable or Disable Dimmer slider control uint32_t spare16 : 1; uint32_t spare17 : 1; uint32_t spare18 : 1; diff --git a/sonoff/sonoff.ino b/sonoff/sonoff.ino index 614d9fd8f..da0c83db1 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -109,7 +109,6 @@ unsigned long pulse_timer[MAX_PULSETIMERS] = { 0 }; // Power off timer unsigned long blink_timer = 0; // Power cycle timer unsigned long backlog_delay = 0; // Command backlog delay power_t power = 0; // Current copy of Settings.power -power_t deviceid = 1; // hold current deviceid power_t blink_power; // Blink power state power_t blink_mask = 0; // Blink relay active mask power_t blink_powersave; // Blink start power save state @@ -143,6 +142,7 @@ uint8_t backlog_pointer = 0; // Command backlog pointer uint8_t sleep; // Current copy of Settings.sleep uint8_t blinkspeed = 1; // LED blink rate uint8_t pin[GPIO_MAX]; // Possible pin configurations +uint8_t active_device = 1; // Active device in ExecuteCommandPower uint8_t leds_present = 0; // Max number of LED supported uint8_t led_inverted = 0; // LED inverted flag (1 = (0 = On, 1 = Off)) uint8_t led_power = 0; // LED power state @@ -1653,8 +1653,6 @@ void ExecuteCommandPower(uint8_t device, uint8_t state, int source) // ShowSource(source); - deviceid = device; - if (SONOFF_IFAN02 == my_module_type) { blink_mask &= 1; // No blinking on the fan relays Settings.flag.interlock = 0; // No interlock mode as it is already done by the microcontroller @@ -1668,7 +1666,10 @@ void ExecuteCommandPower(uint8_t device, uint8_t state, int source) state &= 1; publish_power = 0; } + if ((device < 1) || (device > devices_present)) device = 1; + active_device = device; + if (device <= MAX_PULSETIMERS) { SetPulseTimer(device -1, 0); } power_t mask = 1 << (device -1); // Device to control if (state <= POWER_TOGGLE) { diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index cde0feb28..939ab5b7c 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -922,8 +922,7 @@ void HandleRoot(void) if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) { WSContentSend_P(HTTP_MSG_SLIDER1, LightGetColorTemp()); } - if(Settings.flag3.tuya_show_dimmer == 0) - { + if (!Settings.flag3.tuya_show_dimmer) { WSContentSend_P(HTTP_MSG_SLIDER2, Settings.light_dimmer); } } diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index 667d0d458..286d901fe 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -123,7 +123,7 @@ bool TuyaSetPower(void) int16_t source = XdrvMailbox.payload; if (source != SRC_SWITCH && TuyaSerial) { // ignore to prevent loop from pushing state from faceplate interaction - TuyaSendBool(deviceid, bitRead(rpower, deviceid-1)); + TuyaSendBool(active_device, bitRead(rpower, active_device-1)); status = true; } return status; @@ -207,7 +207,7 @@ void TuyaPacketProcess(void) else if (tuya_buffer[5] == 8) { // dim packet AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), tuya_buffer[13]); - if(Settings.flag3.tuya_show_dimmer == 0) // + if(Settings.flag3.tuya_show_dimmer == 0) // { if (!Settings.param[P_TUYA_DIMMER_ID]) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]);