mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-28 13:16:32 +00:00
Tuya Dimmer: Add support for dimmers with max 24
New Tuya Dimmer has dim values from 0 to 24. Currently the code expects it to be 0-100 or 0-255. With this change we move the flag to a param and use that to calculate correct dim percentage. This change also makes sure to update settings on version upgrade.
This commit is contained in:
parent
0ef45c1fa3
commit
579f68cf2f
@ -125,6 +125,9 @@
|
||||
#ifndef ENERGY_OVERTEMP
|
||||
#define ENERGY_OVERTEMP 90 // Overtemp in Celsius
|
||||
#endif
|
||||
#ifndef TUYA_DIMMER_MAX
|
||||
#define TUYA_DIMMER_MAX 100
|
||||
#endif
|
||||
|
||||
enum WebColors {
|
||||
COL_TEXT, COL_BACKGROUND, COL_FORM,
|
||||
@ -761,6 +764,8 @@ void SettingsDefaultSet2(void)
|
||||
// Settings.light_rotation = 0;
|
||||
SettingsDefaultSet_5_8_1(); // Clock color
|
||||
|
||||
Settings.param[P_TUYA_DIMMER_MAX] = TUYA_DIMMER_MAX;
|
||||
|
||||
// Display
|
||||
SettingsDefaultSet_5_10_1(); // Display settings
|
||||
|
||||
@ -1065,6 +1070,13 @@ void SettingsDelta(void)
|
||||
}
|
||||
if (Settings.version < 0x06060007) {
|
||||
memset((char*)&Settings +0xE00, 0x00, sizeof(SYSCFG) -0xE00);
|
||||
|
||||
// Move current tuya dimmer range to the new param.
|
||||
if (Settings.flag3.tuya_dimmer_range_255) {
|
||||
Settings.param[P_TUYA_DIMMER_MAX] = 100;
|
||||
} else {
|
||||
Settings.param[P_TUYA_DIMMER_MAX] = 255;
|
||||
}
|
||||
}
|
||||
|
||||
Settings.version = VERSION;
|
||||
|
@ -232,7 +232,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED };
|
||||
enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER };
|
||||
|
||||
enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, 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_TUYA_RELAYS, P_OVER_TEMP, // SetOption39 .. SetOption42
|
||||
P_CSE7766_INVALID_POWER, P_HOLD_IGNORE, P_TUYA_RELAYS, P_OVER_TEMP, P_TUYA_DIMMER_MAX, // SetOption39 .. SetOption43
|
||||
P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49
|
||||
|
||||
enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_P1_SMART_METER, DZ_MAX_SENSORS};
|
||||
|
@ -654,6 +654,7 @@ void CmndSetoption(void)
|
||||
#endif
|
||||
#ifdef USE_TUYA_DIMMER
|
||||
case P_TUYA_RELAYS:
|
||||
case P_TUYA_DIMMER_MAX:
|
||||
restart_flag = 2; // Need a restart to update GUI
|
||||
break;
|
||||
#endif
|
||||
|
@ -151,9 +151,7 @@ void LightSerialDuty(uint8_t duty)
|
||||
}
|
||||
|
||||
if (Settings.flag3.tuya_disable_dimmer == 0) {
|
||||
if(Settings.flag3.tuya_dimmer_range_255 == 0) {
|
||||
duty = changeUIntScale(duty, 0, 255, 0, 100);
|
||||
}
|
||||
duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]);
|
||||
if (Tuya.new_dim != duty) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, Settings.param[P_TUYA_DIMMER_ID]);
|
||||
TuyaSendValue(Settings.param[P_TUYA_DIMMER_ID], duty);
|
||||
@ -162,9 +160,7 @@ void LightSerialDuty(uint8_t duty)
|
||||
} else {
|
||||
Tuya.ignore_dim = false; // reset flag
|
||||
if (Settings.flag3.tuya_disable_dimmer == 0) {
|
||||
if(Settings.flag3.tuya_dimmer_range_255 == 0) {
|
||||
duty = changeUIntScale(duty, 0, 255, 0, 100);
|
||||
}
|
||||
duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim skipped value=%d"), duty); // due to 0 or already set
|
||||
}
|
||||
}
|
||||
@ -214,20 +210,16 @@ void TuyaPacketProcess(void)
|
||||
ExecuteCommandPower(Tuya.buffer[6], Tuya.buffer[10], SRC_SWITCH); // send SRC_SWITCH? to use as flag to prevent loop from inbound states from faceplate interaction
|
||||
}
|
||||
}
|
||||
else if (Tuya.buffer[5] == 8) { // dim packet
|
||||
else if (Tuya.buffer[5] == 8) { // Long value packet
|
||||
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]);
|
||||
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];
|
||||
}
|
||||
if (Settings.param[P_TUYA_DIMMER_ID] == Tuya.buffer[6]) {
|
||||
if(Settings.flag3.tuya_dimmer_range_255 == 0) {
|
||||
Tuya.new_dim = (uint8_t) Tuya.buffer[13];
|
||||
} else {
|
||||
Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, 255, 0, 100);
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: RX Dim State=%d"), Tuya.buffer[13]);
|
||||
Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_TUYA_DIMMER_MAX], 0, 100);
|
||||
if ((power || Settings.flag3.tuya_apply_o20) && (Tuya.new_dim > 0) && (abs(Tuya.new_dim - Settings.light_dimmer) > 1)) {
|
||||
Tuya.ignore_dim = true;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user