Add Light skip_light_fade flag and Dimmer3 command, Ignore MCU dimmer changes after sending dimmer command

This commit is contained in:
Paul C Diem 2020-03-05 17:51:22 -06:00
parent c52680f836
commit d16f1a7a0f
4 changed files with 31 additions and 15 deletions

View File

@ -511,9 +511,7 @@ void ProcessDeviceGroupMessage(char * packet, int packet_length)
*/ */
XdrvMailbox.command = nullptr; // Indicates the source is a device group update XdrvMailbox.command = nullptr; // Indicates the source is a device group update
XdrvMailbox.index = flags | device_group_index << 16; XdrvMailbox.index = flags | device_group_index << 16;
if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) skip_light_fade = true;
light_fade = Settings.light_fade;
if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) Settings.light_fade = false;
for (;;) { for (;;) {
if (packet_length - (message_ptr - packet) < 1) goto badmsg; // Malformed message if (packet_length - (message_ptr - packet) < 1) goto badmsg; // Malformed message
@ -549,9 +547,6 @@ void ProcessDeviceGroupMessage(char * packet, int packet_length)
value |= *message_ptr++ << 24; value |= *message_ptr++ << 24;
} }
} }
else if (item == DGR_ITEM_LIGHT_FADE) {
light_fade = value;
}
#ifdef DEVICE_GROUPS_DEBUG #ifdef DEVICE_GROUPS_DEBUG
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("<item=%u, value=%u"), item, value); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("<item=%u, value=%u"), item, value);
#endif // DEVICE_GROUPS_DEBUG #endif // DEVICE_GROUPS_DEBUG
@ -595,7 +590,7 @@ void ProcessDeviceGroupMessage(char * packet, int packet_length)
XdrvMailbox.command_code = DGR_ITEM_EOL; XdrvMailbox.command_code = DGR_ITEM_EOL;
XdrvCall(FUNC_DEVICE_GROUP_REQUEST); XdrvCall(FUNC_DEVICE_GROUP_REQUEST);
Settings.light_fade = light_fade; skip_light_fade = false;
processing_remote_device_message = false; processing_remote_device_message = false;
#ifdef DEVICE_GROUPS_DEBUG #ifdef DEVICE_GROUPS_DEBUG

View File

@ -159,6 +159,7 @@ bool spi_flg = false; // SPI configured
bool soft_spi_flg = false; // Software SPI configured bool soft_spi_flg = false; // Software SPI configured
bool ntp_force_sync = false; // Force NTP sync bool ntp_force_sync = false; // Force NTP sync
bool is_8285 = false; // Hardware device ESP8266EX (0) or ESP8285 (1) bool is_8285 = false; // Hardware device ESP8266EX (0) or ESP8285 (1)
bool skip_light_fade; // Temporarily skip light fading
myio my_module; // Active copy of Module GPIOs (17 x 8 bits) myio my_module; // Active copy of Module GPIOs (17 x 8 bits)
gpio_flag my_module_flag; // Active copy of Template GPIO flags gpio_flag my_module_flag; // Active copy of Template GPIO flags
StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits) StateBitfield global_state; // Global states (currently Wifi and Mqtt) (8 bits)

View File

@ -1832,7 +1832,7 @@ void LightAnimate(void)
cur_col_10[i] = orig_col_10bits[Light.color_remap[i]]; cur_col_10[i] = orig_col_10bits[Light.color_remap[i]];
} }
if (!Settings.light_fade || power_off || (!Light.fade_initialized)) { // no fade if (!Settings.light_fade || skip_light_fade || power_off || (!Light.fade_initialized)) { // no fade
// record the current value for a future Fade // record the current value for a future Fade
memcpy(Light.fade_start_10, cur_col_10, sizeof(Light.fade_start_10)); memcpy(Light.fade_start_10, cur_col_10, sizeof(Light.fade_start_10));
// push the final values at 8 and 10 bits resolution to the PWMs // push the final values at 8 and 10 bits resolution to the PWMs
@ -2149,6 +2149,12 @@ void LightHandleDeviceGroupRequest()
send_state = true; send_state = true;
} }
break; break;
case DGR_ITEM_LIGHT_FADE:
if (Settings.light_fade != value) {
Settings.light_fade = value;
send_state = true;
}
break;
case DGR_ITEM_LIGHT_SPEED: case DGR_ITEM_LIGHT_SPEED:
if (Settings.light_speed != value && value > 0 && value <= 40) { if (Settings.light_speed != value && value > 0 && value <= 40) {
Settings.light_speed = value; Settings.light_speed = value;
@ -2488,10 +2494,17 @@ void CmndDimmer(void)
// Dimmer0 0..100 - Change both RGB and W(W) Dimmers // Dimmer0 0..100 - Change both RGB and W(W) Dimmers
// Dimmer1 0..100 - Change RGB Dimmer // Dimmer1 0..100 - Change RGB Dimmer
// Dimmer2 0..100 - Change W(W) Dimmer // Dimmer2 0..100 - Change W(W) Dimmer
// Dimmer3 0..100 - Change both RGB and W(W) Dimmers with no fading
// Dimmer<x> + - Incerement Dimmer in steps of 10 // Dimmer<x> + - Incerement Dimmer in steps of 10
// Dimmer<x> - - Decrement Dimmer in steps of 10 // Dimmer<x> - - Decrement Dimmer in steps of 10
uint32_t dimmer; uint32_t dimmer;
if (XdrvMailbox.index > 2) { XdrvMailbox.index = 1; } if (XdrvMailbox.index == 3) {
skip_light_fade = true;
XdrvMailbox.index = 0;
}
else if (XdrvMailbox.index > 2) {
XdrvMailbox.index = 1;
}
if ((light_controller.isCTRGBLinked()) || (0 == XdrvMailbox.index)) { if ((light_controller.isCTRGBLinked()) || (0 == XdrvMailbox.index)) {
dimmer = light_state.getDimmer(); dimmer = light_state.getDimmer();
@ -2524,9 +2537,11 @@ void CmndDimmer(void)
} }
} }
Light.update = true; Light.update = true;
if (skip_light_fade) LightAnimate();
} else { } else {
ResponseCmndNumber(dimmer); ResponseCmndNumber(dimmer);
} }
skip_light_fade = false;
} }
#endif // USE_LIGHT #endif // USE_LIGHT

View File

@ -68,6 +68,7 @@ struct TUYA {
int byte_counter = 0; // Index in serial receive buffer int byte_counter = 0; // Index in serial receive buffer
bool low_power_mode = false; // Normal or Low power mode protocol bool low_power_mode = false; // Normal or Low power mode protocol
bool send_success_next_second = false; // Second command success in low power mode bool send_success_next_second = false; // Second command success in low power mode
uint32_t ignore_dimmer_cmd_timeout = 0;// Time until which received dimmer commands should be ignored
} Tuya; } Tuya;
@ -366,6 +367,7 @@ bool TuyaSetPower(void)
if (source != SRC_SWITCH && TuyaSerial) { // ignore to prevent loop from pushing state from faceplate interaction if (source != SRC_SWITCH && TuyaSerial) { // ignore to prevent loop from pushing state from faceplate interaction
TuyaSendBool(dpid, bitRead(rpower, active_device-1) ^ bitRead(rel_inverted, active_device-1)); TuyaSendBool(dpid, bitRead(rpower, active_device-1) ^ bitRead(rel_inverted, active_device-1));
delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out.
status = true; status = true;
} }
return status; return status;
@ -374,7 +376,7 @@ bool TuyaSetPower(void)
bool TuyaSetChannels(void) bool TuyaSetChannels(void)
{ {
LightSerialDuty(((uint8_t*)XdrvMailbox.data)[0]); LightSerialDuty(((uint8_t*)XdrvMailbox.data)[0]);
delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out. //delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out.
return true; return true;
} }
@ -386,6 +388,7 @@ void LightSerialDuty(uint16_t duty)
if (duty < Settings.dimmer_hw_min) { duty = Settings.dimmer_hw_min; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself if (duty < Settings.dimmer_hw_min) { duty = Settings.dimmer_hw_min; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself
if (Tuya.new_dim != duty) { if (Tuya.new_dim != duty) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, dpid); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, dpid);
Tuya.ignore_dimmer_cmd_timeout = millis() + 250; // Ignore serial received dim commands for the next 250ms
TuyaSendValue(dpid, duty); TuyaSendValue(dpid, duty);
} }
} else if (dpid > 0) { } else if (dpid > 0) {
@ -456,12 +459,14 @@ void TuyaProcessStatePacket(void) {
if (fnId == TUYA_MCU_FUNC_DIMMER) { if (fnId == TUYA_MCU_FUNC_DIMMER) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), packetValue); AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), packetValue);
Tuya.new_dim = changeUIntScale(packetValue, 0, Settings.dimmer_hw_max, 0, 100); Tuya.new_dim = changeUIntScale(packetValue, 0, Settings.dimmer_hw_max, 0, 100);
if ((power || Settings.flag3.tuya_apply_o20) && // SetOption54 - Apply SetOption20 settings to Tuya device if (Tuya.ignore_dimmer_cmd_timeout < millis()) {
(Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) { if ((power || Settings.flag3.tuya_apply_o20) && // SetOption54 - Apply SetOption20 settings to Tuya device
Tuya.ignore_dim = true; (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) {
Tuya.ignore_dim = true;
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER " %d"), Tuya.new_dim ); snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER "3 %d"), Tuya.new_dim );
ExecuteCommand(scmnd, SRC_SWITCH); ExecuteCommand(scmnd, SRC_SWITCH);
}
} }
} }