From f946ebaf7b558f996a1adb0db003afc0fa6817b3 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Wed, 2 Oct 2019 11:11:50 +0100 Subject: [PATCH 1/2] Dimmer: Change SetOption43 (Dimmer Max) generic instead of Tuya only --- sonoff/settings.ino | 10 +++++----- sonoff/sonoff.h | 2 +- sonoff/support_command.ino | 2 +- sonoff/xdrv_16_tuyamcu.ino | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sonoff/settings.ino b/sonoff/settings.ino index 289c8392b..f16273f7c 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -125,8 +125,8 @@ #ifndef ENERGY_OVERTEMP #define ENERGY_OVERTEMP 90 // Overtemp in Celsius #endif -#ifndef TUYA_DIMMER_MAX -#define TUYA_DIMMER_MAX 100 +#ifndef DEFAULT_DIMMER_MAX +#define DEFAULT_DIMMER_MAX 100 #endif enum WebColors { @@ -774,7 +774,7 @@ void SettingsDefaultSet2(void) // Settings.light_rotation = 0; SettingsDefaultSet_5_8_1(); // Clock color - Settings.param[P_TUYA_DIMMER_MAX] = TUYA_DIMMER_MAX; + Settings.param[P_DIMMER_MAX] = DEFAULT_DIMMER_MAX; // Display SettingsDefaultSet_5_10_1(); // Display settings @@ -1084,9 +1084,9 @@ void SettingsDelta(void) if (Settings.version < 0x06060008) { // Move current tuya dimmer range to the new param. if (Settings.flag3.tuya_dimmer_range_255) { - Settings.param[P_TUYA_DIMMER_MAX] = 100; + Settings.param[P_DIMMER_MAX] = 100; } else { - Settings.param[P_TUYA_DIMMER_MAX] = 255; + Settings.param[P_DIMMER_MAX] = 255; } } if (Settings.version < 0x06060009) { diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index 46c0868e2..c1c19f3fe 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -249,7 +249,7 @@ enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; enum SettingsParamIndex { P_HOLD_TIME, P_MAX_POWER_RETRY, P_ex_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, // SetOption32 .. SetOption38 P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_ex_TUYA_RELAYS, P_OVER_TEMP, // SetOption39 .. SetOption42 - P_TUYA_DIMMER_MAX, + P_DIMMER_MAX, P_ex_TUYA_VOLTAGE_ID, P_ex_TUYA_CURRENT_ID, P_ex_TUYA_POWER_ID, // SetOption43 .. SetOption46 P_ex_ENERGY_TARIFF1, P_ex_ENERGY_TARIFF2, // SetOption47 .. SetOption48 P_MAX_PARAM8 }; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 diff --git a/sonoff/support_command.ino b/sonoff/support_command.ino index 0e2f6d4e6..9e2fd5fcb 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -687,7 +687,7 @@ void CmndSetoption(void) break; #endif #ifdef USE_TUYA_MCU - case P_TUYA_DIMMER_MAX: + case P_DIMMER_MAX: restart_flag = 2; // Need a restart to update GUI break; #endif diff --git a/sonoff/xdrv_16_tuyamcu.ino b/sonoff/xdrv_16_tuyamcu.ino index d849d4712..db190f58f 100644 --- a/sonoff/xdrv_16_tuyamcu.ino +++ b/sonoff/xdrv_16_tuyamcu.ino @@ -297,14 +297,14 @@ void LightSerialDuty(uint8_t duty) if (Settings.flag3.tuya_dimmer_min_limit) { // Enable dimming limit SetOption69: Enabled by default if (duty < 25) { duty = 25; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself } - duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]); + duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_DIMMER_MAX]); if (Tuya.new_dim != duty) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, dpid); TuyaSendValue(dpid, duty); } } else if (dpid > 0) { Tuya.ignore_dim = false; // reset flag - duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]); + duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_DIMMER_MAX]); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim skipped value=%d"), duty); // due to 0 or already set } else { AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: Cannot set dimmer. Dimmer Id unknown")); // @@ -375,7 +375,7 @@ void TuyaPacketProcess(void) bool tuya_energy_enabled = (XNRG_16 == energy_flg); if (fnId == TUYA_MCU_FUNC_DIMMER) { AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]); - Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_TUYA_DIMMER_MAX], 0, 100); + Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_DIMMER_MAX], 0, 100); if ((power || Settings.flag3.tuya_apply_o20) && (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) { Tuya.ignore_dim = true; From 39b201898d7bfc2a4838b04899db19594f573db7 Mon Sep 17 00:00:00 2001 From: Shantur Rathore Date: Wed, 2 Oct 2019 11:12:51 +0100 Subject: [PATCH 2/2] PS_16_DZ: Implement SetOption43 (Dimmer Max) for PS_16_DZ dimmers. Fixes #6544 --- sonoff/xdrv_19_ps16dz_dimmer.ino | 1 + 1 file changed, 1 insertion(+) diff --git a/sonoff/xdrv_19_ps16dz_dimmer.ino b/sonoff/xdrv_19_ps16dz_dimmer.ino index b0dc80190..0c637a2ae 100644 --- a/sonoff/xdrv_19_ps16dz_dimmer.ino +++ b/sonoff/xdrv_19_ps16dz_dimmer.ino @@ -83,6 +83,7 @@ void PS16DZSerialSendUpdateCommand(void) uint8_t light_state_dimmer = light_state.getDimmer(); // Dimming acts odd below 10% - this mirrors the threshold set on the faceplate itself light_state_dimmer = (light_state_dimmer < 10) ? 10 : light_state_dimmer; + light_state_dimmer = (light_state_dimmer > Settings.param[P_DIMMER_MAX]) ? Settings.param[P_DIMMER_MAX] : light_state_dimmer; snprintf_P(Ps16dz.tx_buffer, PS16DZ_BUFFER_SIZE, PSTR("AT+UPDATE=\"sequence\":\"%d%03d\",\"switch\":\"%s\",\"bright\":%d"), LocalTime(), millis()%1000, power?"on":"off", light_state_dimmer);