diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 993c285d4..5eef31626 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -82,3 +82,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c - Add web page sliders when ``SetOption37 128`` is active allowing control of white(s) - Add most SetOptions as defines to my_user_config.h - Add SoftwareSerial to CSE7766 driver allowing different GPIOs (#7563) +- Add optional parameter to command ``Scheme , `` to control initial start color diff --git a/tasmota/CHANGELOG.md b/tasmota/CHANGELOG.md index 98f48c7a8..9285bdda1 100644 --- a/tasmota/CHANGELOG.md +++ b/tasmota/CHANGELOG.md @@ -8,6 +8,7 @@ - Add Zigbee persistence and friendly names - Add most SetOptions as defines to my_user_config.h - Add SoftwareSerial to CSE7766 driver allowing different GPIOs (#7563) +- Add optional parameter to command ``Scheme , `` to control initial start color ### 8.1.0.3 20200106 diff --git a/tasmota/support.ino b/tasmota/support.ino index 94def5a6f..0a281bc68 100644 --- a/tasmota/support.ino +++ b/tasmota/support.ino @@ -493,6 +493,17 @@ bool ParseIp(uint32_t* addr, const char* str) return (3 == i); } +uint32_t ParseParameters(uint32_t count, uint32_t *params) +{ + char *p; + uint32_t i = 0; + for (char *str = strtok_r(XdrvMailbox.data, ", ", &p); str && i < count; str = strtok_r(nullptr, ", ", &p)) { + params[i] = strtoul(str, nullptr, 0); + i++; + } + return i; +} + // Function to parse & check if version_str is newer than our currently installed version. bool NewerVersion(char* version_str) { diff --git a/tasmota/tasmota_template.h b/tasmota/tasmota_template.h index 1793902eb..9bb98ce6e 100644 --- a/tasmota/tasmota_template.h +++ b/tasmota/tasmota_template.h @@ -169,7 +169,7 @@ enum UserSelectablePins { GPIO_SM16716_SEL, // SM16716 SELECT GPIO_DI, // my92x1 PWM input GPIO_DCKI, // my92x1 CLK input - GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) + GPIO_CSE7766_TX, // CSE7766 Serial interface (S31 and Pow R2) - Not used anymore 20200121 GPIO_CSE7766_RX, // CSE7766 Serial interface (S31 and Pow R2) GPIO_ARIRFRCV, // AriLux RF Receive input GPIO_TXD, // Serial interface diff --git a/tasmota/xdrv_03_energy.ino b/tasmota/xdrv_03_energy.ino index 166fd7aa8..4573d2406 100644 --- a/tasmota/xdrv_03_energy.ino +++ b/tasmota/xdrv_03_energy.ino @@ -522,26 +522,19 @@ void CmndEnergyReset(void) } } else if ((XdrvMailbox.index > 3) && (XdrvMailbox.index <= 5)) { - char *p; - char *str = strtok_r(XdrvMailbox.data, ", ", &p); - int32_t position = -1; - uint32_t values[2]; - - while ((str != nullptr) && (position < 1)) { - uint32_t value = strtoul(str, nullptr, 10); - position++; - values[position] = value *100; - str = strtok_r(nullptr, ", ", &p); - } + uint32_t values[2] = { 0 }; + uint32_t position = ParseParameters(2, values); + values[0] *= 100; + values[1] *= 100; switch (XdrvMailbox.index) { case 4: // Reset energy_usage.usage totals - if (position > -1) { + if (position > 0) { RtcSettings.energy_usage.usage1_kWhtotal = values[0]; } - if (position > 0) { + if (position > 1) { RtcSettings.energy_usage.usage2_kWhtotal = values[1]; } Settings.energy_usage.usage1_kWhtotal = RtcSettings.energy_usage.usage1_kWhtotal; @@ -549,10 +542,10 @@ void CmndEnergyReset(void) break; case 5: // Reset energy_usage.return totals - if (position > -1) { + if (position > 0) { RtcSettings.energy_usage.return1_kWhtotal = values[0]; } - if (position > 0) { + if (position > 1) { RtcSettings.energy_usage.return2_kWhtotal = values[1]; } Settings.energy_usage.return1_kWhtotal = RtcSettings.energy_usage.return1_kWhtotal; diff --git a/tasmota/xdrv_04_light.ino b/tasmota/xdrv_04_light.ino index d217b75c7..48cc2d283 100644 --- a/tasmota/xdrv_04_light.ino +++ b/tasmota/xdrv_04_light.ino @@ -2311,6 +2311,10 @@ void CmndScheme(void) } } if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload <= max_scheme)) { + uint32_t parm[2]; + if (ParseParameters(2, parm) > 1) { + Light.wheel = parm[1]; + } Settings.light_scheme = XdrvMailbox.payload; if (LS_WAKEUP == Settings.light_scheme) { Light.wakeup_active = 3; @@ -2403,16 +2407,10 @@ void CmndDimmer(void) void CmndDimmerRange(void) { if (XdrvMailbox.data_len > 0) { - char *p; - uint8_t i = 0; - uint16_t parm[2]; + uint32_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++; - } - + ParseParameters(2, parm); if (parm[0] < parm[1]) { Settings.dimmer_hw_min = parm[0]; Settings.dimmer_hw_max = parm[1]; diff --git a/tasmota/xdrv_24_buzzer.ino b/tasmota/xdrv_24_buzzer.ino index 9cfa7e111..78246f0f6 100644 --- a/tasmota/xdrv_24_buzzer.ino +++ b/tasmota/xdrv_24_buzzer.ino @@ -155,13 +155,8 @@ void CmndBuzzer(void) if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.payload > 0) { - char *p; - uint32_t i = 0; uint32_t parm[4] = { 0 }; - for (char *str = strtok_r(XdrvMailbox.data, ", ", &p); str && i < 4; str = strtok_r(nullptr, ", ", &p)) { - parm[i] = strtoul(str, nullptr, 0); - i++; - } + ParseParameters(4, parm); for (uint32_t i = 0; i < 3; i++) { if (parm[i] < 1) { parm[i] = 1; } // Default Count, On time, Off time }