Merge pull request #6284 from shantur/tuya-serial-fixes

Tuya serial dimmer and switch fixes
This commit is contained in:
Theo Arends 2019-08-23 17:17:33 +02:00 committed by GitHub
commit e2b71af4df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 8 deletions

View File

@ -78,7 +78,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
uint32_t no_hold_retain : 1; // bit 12 (v6.4.1.19) - SetOption62 - Don't use retain flag on HOLD messages
uint32_t no_power_feedback : 1; // bit 13 (v6.5.0.9) - SetOption63 - Don't scan relay power state at restart
uint32_t use_underscore : 1; // bit 14 (v6.5.0.12) - SetOption64 - Enable "_" instead of "-" as sensor index separator
uint32_t tuya_show_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - Enable or Disable Dimmer slider control
uint32_t tuya_disable_dimmer : 1; // bit 15 (v6.5.0.15) - SetOption65 - Enable or Disable Tuya Serial Dimmer control
uint32_t tuya_dimmer_range_255 : 1; // bit 16 (v6.6.0.1) - SetOption66 - Enable or Disable Dimmer range 255 slider control
uint32_t buzzer_enable : 1; // bit 17 (v6.6.0.1) - SetOption67 - Enable buzzer when available
uint32_t pwm_multi_channels : 1; // bit 18 (v6.6.0.3) - SetOption68 - Enable multi-channels PWM instead of Color PWM

View File

@ -621,6 +621,9 @@ void CmndSetoption(void)
if (18 == pindex) { // SetOption68 for multi-channel PWM, requires a reboot
restart_flag = 2;
}
if (15 == pindex) { // SetOption65 for tuya_disable_dimmer requires a reboot
restart_flag = 2;
}
}
}
else { // SetOption32 .. 49

View File

@ -942,9 +942,7 @@ void HandleRoot(void)
if ((LST_COLDWARM == (light_type &7)) || (LST_RGBWC == (light_type &7))) {
WSContentSend_P(HTTP_MSG_SLIDER1, LightGetColorTemp());
}
if (!Settings.flag3.tuya_show_dimmer) {
WSContentSend_P(HTTP_MSG_SLIDER2, Settings.light_dimmer);
}
WSContentSend_P(HTTP_MSG_SLIDER2, Settings.light_dimmer);
}
#endif
WSContentSend_P(HTTP_TABLE100);

View File

@ -139,6 +139,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.
return true;
}
@ -149,7 +150,7 @@ void LightSerialDuty(uint8_t duty)
if (duty < 25) { duty = 25; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself
}
if (Settings.flag3.tuya_show_dimmer == 0) {
if (Settings.flag3.tuya_disable_dimmer == 0) {
if(Settings.flag3.tuya_dimmer_range_255 == 0) {
duty = changeUIntScale(duty, 0, 255, 0, 100);
}
@ -160,7 +161,7 @@ void LightSerialDuty(uint8_t duty)
}
} else {
Tuya.ignore_dim = false; // reset flag
if (Settings.flag3.tuya_show_dimmer == 0) {
if (Settings.flag3.tuya_disable_dimmer == 0) {
if(Settings.flag3.tuya_dimmer_range_255 == 0) {
duty = changeUIntScale(duty, 0, 255, 0, 100);
}
@ -216,7 +217,7 @@ void TuyaPacketProcess(void)
else if (Tuya.buffer[5] == 8) { // dim packet
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]);
if (Settings.flag3.tuya_show_dimmer == 0) {
if (Settings.flag3.tuya_disable_dimmer == 0) {
if (!Settings.param[P_TUYA_DIMMER_ID]) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Autoconfiguring Dimmer ID %d"), Tuya.buffer[6]);
Settings.param[P_TUYA_DIMMER_ID] = Tuya.buffer[6];
@ -291,7 +292,12 @@ bool TuyaModuleSelected(void)
Settings.my_gp.io[3] = GPIO_TUYA_RX;
restart_flag = 2;
}
light_type = LT_SERIAL1;
if (Settings.flag3.tuya_disable_dimmer == 0) {
light_type = LT_SERIAL1;
} else {
light_type = LT_BASIC;
}
return true;
}