From 86ffa2d5fe93f6a333e91fa978b0b466f9a7722d Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 11 Oct 2019 11:23:53 +0200 Subject: [PATCH] Fix JSON and functionality Fix JSON and functionality --- sonoff/settings.ino | 14 ++++++++------ sonoff/sonoff.h | 3 +-- sonoff/support_command.ino | 17 ++++++----------- sonoff/xdrv_04_light.ino | 15 ++++++++++----- sonoff/xdrv_16_tuyamcu.ino | 4 ++-- 5 files changed, 27 insertions(+), 26 deletions(-) diff --git a/sonoff/settings.ino b/sonoff/settings.ino index faf17ff54..7109f20b1 100644 --- a/sonoff/settings.ino +++ b/sonoff/settings.ino @@ -126,14 +126,12 @@ #define ENERGY_OVERTEMP 90 // Overtemp in Celsius #endif #ifndef DEFAULT_DIMMER_MAX -#define DEFAULT_DIMMER_MAX 100 +#define DEFAULT_DIMMER_MAX 100 #endif #ifndef DEFAULT_DIMMER_MIN -#define DEFAULT_DIMMER_MIN 10 +#define DEFAULT_DIMMER_MIN 0 #endif - - enum WebColors { COL_TEXT, COL_BACKGROUND, COL_FORM, COL_INPUT_TEXT, COL_INPUT, COL_CONSOLE_TEXT, COL_CONSOLE, @@ -1146,16 +1144,20 @@ void SettingsDelta(void) if (Settings.version < 0x06060011) { Settings.param[P_BACKLOG_DELAY] = MIN_BACKLOG_DELAY; } - if (Settings.version < 0x06060012) { - Settings.dimmer_hw_max = Settings.param[P_ex_DIMMER_MAX]; Settings.dimmer_hw_min = DEFAULT_DIMMER_MIN; + Settings.dimmer_hw_max = DEFAULT_DIMMER_MAX; if (TUYA_DIMMER == Settings.module) { if (Settings.flag3.ex_tuya_dimmer_min_limit) { Settings.dimmer_hw_min = 25; } else { Settings.dimmer_hw_min = 1; } + Settings.dimmer_hw_max = Settings.param[P_ex_DIMMER_MAX]; + } + else if (PS_16_DZ == Settings.module) { + Settings.dimmer_hw_min = 10; + Settings.dimmer_hw_max = Settings.param[P_ex_DIMMER_MAX]; } } diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index a075cef0f..2ec5267e0 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -247,8 +247,7 @@ enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; enum SettingsParamIndex { P_HOLD_TIME, P_MAX_POWER_RETRY, P_BACKLOG_DELAY, 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_ex_DIMMER_MAX, - P_ex_TUYA_VOLTAGE_ID, P_ex_TUYA_CURRENT_ID, P_ex_TUYA_POWER_ID, // SetOption43 .. SetOption46 + P_ex_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 781bd5769..f9ebd855a 100644 --- a/sonoff/support_command.ino +++ b/sonoff/support_command.ino @@ -700,21 +700,16 @@ void CmndSetoption(void) } if ((XdrvMailbox.payload >= param_low) && (XdrvMailbox.payload <= param_high)) { Settings.param[pindex] = XdrvMailbox.payload; - switch (pindex) { #ifdef USE_LIGHT - case P_RGB_REMAP: - LightUpdateColorMapping(); - break; + if (P_RGB_REMAP == pindex) { + LightUpdateColorMapping(); + } #endif #if (defined(USE_IR_REMOTE) && defined(USE_IR_RECEIVE)) || defined(USE_IR_REMOTE_FULL) - case P_IR_UNKNOW_THRESHOLD: - IrReceiveUpdateThreshold(); - break; -#endif - case P_ex_DIMMER_MAX: - restart_flag = 2; // Need a restart to update GUI - break; + if (P_IR_UNKNOW_THRESHOLD == pindex) { + IrReceiveUpdateThreshold(); } +#endif } } } diff --git a/sonoff/xdrv_04_light.ino b/sonoff/xdrv_04_light.ino index f64e021a0..0df5ca81a 100644 --- a/sonoff/xdrv_04_light.ino +++ b/sonoff/xdrv_04_light.ino @@ -2063,7 +2063,9 @@ void CmndDimmerRange(void) if (XdrvMailbox.data_len > 0) { char *p; uint8_t i = 0; - uint16_t parm[2] = { 0 }; + uint16_t parm[2]; + parm[0] = Settings.dimmer_hw_min; + parm[1] = Settings.dimmer_hw_max; for (char *str = strtok_r(XdrvMailbox.data, ", ", &p); str && i < 2; str = strtok_r(nullptr, ", ", &p)) { parm[i] = strtoul(str, nullptr, 0); i++; @@ -2072,13 +2074,13 @@ void CmndDimmerRange(void) if (parm[0] < parm[1]) { Settings.dimmer_hw_min = parm[0]; Settings.dimmer_hw_max = parm[1]; - restart_flag = 2; } else { - AddLog_P2(LOG_LEVEL_ERROR, PSTR("Light: Dimmer minimum %d should be less than maximum %d"), parm[0], parm[1]); + Settings.dimmer_hw_min = parm[1]; + Settings.dimmer_hw_max = parm[0]; } + restart_flag = 2; } - - Response_P(PSTR("{" D_CMND_DIMMER_RANGE ":{\"min\":%d, \"max\":%d}}"), Settings.dimmer_hw_min, Settings.dimmer_hw_max); + Response_P(PSTR("{\"" D_CMND_DIMMER_RANGE "\":{\"Min\":%d,\"Max\":%d}}"), Settings.dimmer_hw_min, Settings.dimmer_hw_max); } void CmndLedTable(void) @@ -2187,6 +2189,9 @@ bool Xdrv04(uint8_t function) } else if (light_type) { switch (function) { + case FUNC_SERIAL: + result = XlgtCall(FUNC_SERIAL); + break; case FUNC_EVERY_50_MSECOND: LightAnimate(); break; diff --git a/sonoff/xdrv_16_tuyamcu.ino b/sonoff/xdrv_16_tuyamcu.ino index 61d01daa8..fa9b7a22c 100644 --- a/sonoff/xdrv_16_tuyamcu.ino +++ b/sonoff/xdrv_16_tuyamcu.ino @@ -124,14 +124,14 @@ void CmndTuyaMcu(void) { } - Response_P(PSTR("{" D_CMND_TUYA_MCU ":[")); + Response_P(PSTR("{\"" D_CMND_TUYA_MCU "\":[")); bool added = false; for (uint8_t i = 0; i < MAX_TUYA_FUNCTIONS; i++) { if (Settings.tuya_fnid_map[i].fnid != 0) { if (added) { ResponseAppend_P(PSTR(",")); } - ResponseAppend_P(PSTR("{\"fnId\":%d, \"dpId\":%d}" ), Settings.tuya_fnid_map[i].fnid, Settings.tuya_fnid_map[i].dpid); + ResponseAppend_P(PSTR("{\"fnId\":%d,\"dpId\":%d}" ), Settings.tuya_fnid_map[i].fnid, Settings.tuya_fnid_map[i].dpid); added = true; } }