Skip to content

Commit

Permalink
Dimmer: Change SetOption43 (Dimmer Max) generic instead of Tuya only
Browse files Browse the repository at this point in the history
  • Loading branch information
Shantur Rathore committed Oct 2, 2019
1 parent 37fc7d2 commit f946eba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
10 changes: 5 additions & 5 deletions sonoff/settings.ino
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@
#ifndef ENERGY_OVERTEMP
#define ENERGY_OVERTEMP 90 // Overtemp in Celsius
#endif
#ifndef TUYA_DIMMER_MAX
#define TUYA_DIMMER_MAX 100
#ifndef DEFAULT_DIMMER_MAX
#define DEFAULT_DIMMER_MAX 100
#endif

enum WebColors {
Expand Down Expand Up @@ -774,7 +774,7 @@ void SettingsDefaultSet2(void)
// Settings.light_rotation = 0;
SettingsDefaultSet_5_8_1(); // Clock color

Settings.param[P_TUYA_DIMMER_MAX] = TUYA_DIMMER_MAX;
Settings.param[P_DIMMER_MAX] = DEFAULT_DIMMER_MAX;

// Display
SettingsDefaultSet_5_10_1(); // Display settings
Expand Down Expand Up @@ -1084,9 +1084,9 @@ void SettingsDelta(void)
if (Settings.version < 0x06060008) {
// Move current tuya dimmer range to the new param.
if (Settings.flag3.tuya_dimmer_range_255) {
Settings.param[P_TUYA_DIMMER_MAX] = 100;
Settings.param[P_DIMMER_MAX] = 100;
} else {
Settings.param[P_TUYA_DIMMER_MAX] = 255;
Settings.param[P_DIMMER_MAX] = 255;
}
}
if (Settings.version < 0x06060009) {
Expand Down
2 changes: 1 addition & 1 deletion sonoff/sonoff.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER };

enum SettingsParamIndex { P_HOLD_TIME, P_MAX_POWER_RETRY, P_ex_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_ex_TUYA_RELAYS, P_OVER_TEMP, // SetOption39 .. SetOption42
P_TUYA_DIMMER_MAX,
P_DIMMER_MAX,
P_ex_TUYA_VOLTAGE_ID, P_ex_TUYA_CURRENT_ID, P_ex_TUYA_POWER_ID, // SetOption43 .. SetOption46
P_ex_ENERGY_TARIFF1, P_ex_ENERGY_TARIFF2, // SetOption47 .. SetOption48
P_MAX_PARAM8 }; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49
Expand Down
2 changes: 1 addition & 1 deletion sonoff/support_command.ino
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ void CmndSetoption(void)
break;
#endif
#ifdef USE_TUYA_MCU
case P_TUYA_DIMMER_MAX:
case P_DIMMER_MAX:
restart_flag = 2; // Need a restart to update GUI
break;
#endif
Expand Down
6 changes: 3 additions & 3 deletions sonoff/xdrv_16_tuyamcu.ino
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ void LightSerialDuty(uint8_t duty)
if (Settings.flag3.tuya_dimmer_min_limit) { // Enable dimming limit SetOption69: Enabled by default
if (duty < 25) { duty = 25; } // dimming acts odd below 25(10%) - this mirrors the threshold set on the faceplate itself
}
duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]);
duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_DIMMER_MAX]);
if (Tuya.new_dim != duty) {
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim value=%d (id=%d)"), duty, dpid);
TuyaSendValue(dpid, duty);
}
} else if (dpid > 0) {
Tuya.ignore_dim = false; // reset flag
duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_TUYA_DIMMER_MAX]);
duty = changeUIntScale(duty, 0, 255, 0, Settings.param[P_DIMMER_MAX]);
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("TYA: Send dim skipped value=%d"), duty); // due to 0 or already set
} else {
AddLog_P(LOG_LEVEL_DEBUG, PSTR("TYA: Cannot set dimmer. Dimmer Id unknown")); //
Expand Down Expand Up @@ -375,7 +375,7 @@ void TuyaPacketProcess(void)
bool tuya_energy_enabled = (XNRG_16 == energy_flg);
if (fnId == TUYA_MCU_FUNC_DIMMER) {
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);
Tuya.new_dim = changeUIntScale((uint8_t) Tuya.buffer[13], 0, Settings.param[P_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;

Expand Down

0 comments on commit f946eba

Please sign in to comment.