Merge pull request #7860 from pcdiem/tuya-mcu1

Add Light skip_light_fade flag and Dimmer3 command, Ignore MCU dimmer…
This commit is contained in:
Theo Arends 2020-03-06 11:49:56 +01:00 committed by GitHub
commit 59408b453e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.index = flags | device_group_index << 16;
light_fade = Settings.light_fade;
if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) Settings.light_fade = false;
if (flags & (DGR_FLAG_MORE_TO_COME | DGR_FLAG_DIRECT)) skip_light_fade = true;
for (;;) {
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;
}
}
else if (item == DGR_ITEM_LIGHT_FADE) {
light_fade = value;
}
#ifdef DEVICE_GROUPS_DEBUG
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("<item=%u, value=%u"), item, value);
#endif // DEVICE_GROUPS_DEBUG
@ -595,7 +590,7 @@ void ProcessDeviceGroupMessage(char * packet, int packet_length)
XdrvMailbox.command_code = DGR_ITEM_EOL;
XdrvCall(FUNC_DEVICE_GROUP_REQUEST);
Settings.light_fade = light_fade;
skip_light_fade = false;
processing_remote_device_message = false;
#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 ntp_force_sync = false; // Force NTP sync
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)
gpio_flag my_module_flag; // Active copy of Template GPIO flags
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]];
}
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
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
@ -2149,6 +2149,12 @@ void LightHandleDeviceGroupRequest()
send_state = true;
}
break;
case DGR_ITEM_LIGHT_FADE:
if (Settings.light_fade != value) {
Settings.light_fade = value;
send_state = true;
}
break;
case DGR_ITEM_LIGHT_SPEED:
if (Settings.light_speed != value && value > 0 && value <= 40) {
Settings.light_speed = value;
@ -2488,10 +2494,17 @@ void CmndDimmer(void)
// Dimmer0 0..100 - Change both RGB and W(W) Dimmers
// Dimmer1 0..100 - Change RGB 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> - - Decrement Dimmer in steps of 10
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)) {
dimmer = light_state.getDimmer();
@ -2524,9 +2537,11 @@ void CmndDimmer(void)
}
}
Light.update = true;
if (skip_light_fade) LightAnimate();
} else {
ResponseCmndNumber(dimmer);
}
skip_light_fade = false;
}
#endif // USE_LIGHT

View File

@ -68,6 +68,7 @@ struct TUYA {
int byte_counter = 0; // Index in serial receive buffer
bool low_power_mode = false; // Normal or Low power mode protocol
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;
@ -366,6 +367,7 @@ bool TuyaSetPower(void)
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));
delay(20); // Hack when power is off and dimmer is set then both commands go too soon to Serial out.
status = true;
}
return status;
@ -374,7 +376,7 @@ bool TuyaSetPower(void)
bool TuyaSetChannels(void)
{
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;
}
@ -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 (Tuya.new_dim != duty) {
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);
}
} else if (dpid > 0) {
@ -456,12 +459,14 @@ void TuyaProcessStatePacket(void) {
if (fnId == TUYA_MCU_FUNC_DIMMER) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), packetValue);
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
(Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) {
Tuya.ignore_dim = true;
if (Tuya.ignore_dimmer_cmd_timeout < millis()) {
if ((power || Settings.flag3.tuya_apply_o20) && // SetOption54 - Apply SetOption20 settings to Tuya device
(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 );
ExecuteCommand(scmnd, SRC_SWITCH);
snprintf_P(scmnd, sizeof(scmnd), PSTR(D_CMND_DIMMER "3 %d"), Tuya.new_dim );
ExecuteCommand(scmnd, SRC_SWITCH);
}
}
}