diff --git a/sonoff/settings.h b/sonoff/settings.h index 5f6350116..fcb58a174 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 spare15 : 1; + uint32_t tuya_show_dimmer : 1; // bit 15 (v6.5.0.12) - 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 318802b80..614d9fd8f 100755 --- a/sonoff/sonoff.ino +++ b/sonoff/sonoff.ino @@ -109,6 +109,7 @@ 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 @@ -1652,6 +1653,8 @@ 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 diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index c79e6c908..cde0feb28 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -922,7 +922,10 @@ void HandleRoot(void) if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) { WSContentSend_P(HTTP_MSG_SLIDER1, LightGetColorTemp()); } - WSContentSend_P(HTTP_MSG_SLIDER2, Settings.light_dimmer); + if(Settings.flag3.tuya_show_dimmer == 0) + { + WSContentSend_P(HTTP_MSG_SLIDER2, Settings.light_dimmer); + } } WSContentSend_P(HTTP_TABLE100); WSContentSend_P(PSTR("")); diff --git a/sonoff/xdrv_16_tuyadimmer.ino b/sonoff/xdrv_16_tuyadimmer.ino index ffb44adab..667d0d458 100644 --- a/sonoff/xdrv_16_tuyadimmer.ino +++ b/sonoff/xdrv_16_tuyadimmer.ino @@ -123,11 +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 - - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: SetDevicePower.rpower=%d"), rpower); - - TuyaSendBool(TUYA_POWER_ID, rpower); - + TuyaSendBool(deviceid, bitRead(rpower, deviceid-1)); status = true; } return status; @@ -146,14 +142,19 @@ void LightSerialDuty(uint8_t duty) duty = 25; // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } - AddLog_P2(LOG_LEVEL_DEBUG, PSTR( "TYA: Send Serial Packet Dim Value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]); - TuyaSendValue(Settings.param[P_TUYA_DIMMER_ID], duty); + if(Settings.flag3.tuya_show_dimmer == 0) + { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR( "TYA: Send Serial Packet Dim Value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]); + TuyaSendValue(Settings.param[P_TUYA_DIMMER_ID], duty); + } } else { tuya_ignore_dim = false; // reset flag - + if(Settings.flag3.tuya_show_dimmer == 0) + { AddLog_P2(LOG_LEVEL_DEBUG, PSTR( "TYA: Send Dim Level skipped due to 0 or already set. Value=%d"), duty); + } } } @@ -194,30 +195,35 @@ void TuyaPacketProcess(void) case TUYA_CMD_STATE: if (tuya_buffer[5] == 5) { // on/off packet - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX - %s State"),tuya_buffer[10]?"On":"Off"); - - if((power || Settings.light_dimmer > 0) && (power != tuya_buffer[10])) { + /*if((power || Settings.light_dimmer > 0) && (power != tuya_buffer[10])) { ExecuteCommandPower(1, tuya_buffer[10], SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction - } + }*/ + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Device-%d --> MCU State: %s Current State:%s"),tuya_buffer[6],tuya_buffer[10]?"On":"Off",bitRead(power, tuya_buffer[6]-1)?"On":"Off"); + if((power || Settings.light_dimmer > 0) && (tuya_buffer[10] != bitRead(power, tuya_buffer[6]-1))) + { + ExecuteCommandPower(tuya_buffer[6], tuya_buffer[10], SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction + } } 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.param[P_TUYA_DIMMER_ID]) { + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]); + Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6]; + } - if (!Settings.param[P_TUYA_DIMMER_ID]) { - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), tuya_buffer[6]); - Settings.param[P_TUYA_DIMMER_ID] = tuya_buffer[6]; - } + tuya_new_dim = round(tuya_buffer[13] * (100. / 255.)); + if((power || Settings.flag3.tuya_apply_o20) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 1)) { - tuya_new_dim = round(tuya_buffer[13] * (100. / 255.)); - if((power || Settings.flag3.tuya_apply_o20) && (tuya_new_dim > 0) && (abs(tuya_new_dim - Settings.light_dimmer) > 1)) { + snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), tuya_new_dim ); - snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), tuya_new_dim ); + AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send CMND_DIMMER_STR=%s"), scmnd ); - AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send CMND_DIMMER_STR=%s"), scmnd ); - - tuya_ignore_dim = true; - ExecuteCommand(scmnd, SRC_SWITCH); + tuya_ignore_dim = true; + ExecuteCommand(scmnd, SRC_SWITCH); + } } } break; @@ -281,6 +287,7 @@ bool TuyaModuleSelected(void) void TuyaInit(void) { + devices_present = Settings.param[6] == 0 ? 1 : Settings.param[6]; if (!Settings.param[P_TUYA_DIMMER_ID]) { Settings.param[P_TUYA_DIMMER_ID] = TUYA_DIMMER_ID; } @@ -416,7 +423,7 @@ bool Xdrv16(uint8_t function) if (tuya_heartbeat_timer > 10) { tuya_heartbeat_timer = 0; TuyaSendCmd(TUYA_CMD_HEARTBEAT); - } + } break; case FUNC_SET_CHANNELS: result = TuyaSetChannels();