diff --git a/tasmota/settings.h b/tasmota/settings.h index 0cc171601..e8bae5182 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -570,12 +570,12 @@ struct { int16_t windmeter_speed_factor; // F3C uint8_t windmeter_tele_pchange; // F3E uint8_t ledpwm_mask; // F3F - - uint8_t free_f40[116]; // F40 - Decrement if adding new Setting variables just above and below + uint8_t ledpwm_on; // F40 + uint8_t ledpwm_off; // F41 + + uint8_t free_f42[118]; // F42 - Decrement if adding new Setting variables just above and below // Only 32 bit boundary variables below - uint16_t ledpwm_on; // FB4 - uint16_t ledpwm_off; // FB6 uint16_t pulse_counter_debounce_low; // FB8 uint16_t pulse_counter_debounce_high; // FBA uint32_t keeloq_master_msb; // FBC diff --git a/tasmota/settings.ino b/tasmota/settings.ino index 85a205da2..8d771a109 100644 --- a/tasmota/settings.ino +++ b/tasmota/settings.ino @@ -1058,7 +1058,7 @@ void SettingsDefaultSet2(void) // Led PWM Settings.ledpwm_off = 0; - Settings.ledpwm_on = 1023; + Settings.ledpwm_on = 255; Settings.ledpwm_mask = 0; } @@ -1420,7 +1420,7 @@ void SettingsDelta(void) // ledpwm if (Settings.version < 0x08030001) { Settings.ledpwm_off = 0; - Settings.ledpwm_on = 1023; + Settings.ledpwm_on = 255; Settings.ledpwm_mask = 0; } diff --git a/tasmota/support_command.ino b/tasmota/support_command.ino index 2f327b9a1..f52fb7ea5 100644 --- a/tasmota/support_command.ino +++ b/tasmota/support_command.ino @@ -1896,8 +1896,8 @@ void CmndSetLedPwmOff(void) if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.payload < 0) { Settings.ledpwm_off = 0; - } else if (XdrvMailbox.payload > Settings.pwm_range) { - Settings.ledpwm_off = Settings.pwm_range; + } else if (XdrvMailbox.payload > 255) { + Settings.ledpwm_off = 255; } else { Settings.ledpwm_off = XdrvMailbox.payload; } @@ -1911,8 +1911,8 @@ void CmndSetLedPwmOn(void) if (XdrvMailbox.data_len > 0) { if (XdrvMailbox.payload < 0) { Settings.ledpwm_on = 0; - } else if (XdrvMailbox.payload > Settings.pwm_range) { - Settings.ledpwm_on = Settings.pwm_range; + } else if (XdrvMailbox.payload > 255) { + Settings.ledpwm_on = 255; } else { Settings.ledpwm_on = XdrvMailbox.payload; } diff --git a/tasmota/support_tasmota.ino b/tasmota/support_tasmota.ino index d96751e32..374cb6884 100644 --- a/tasmota/support_tasmota.ino +++ b/tasmota/support_tasmota.ino @@ -358,24 +358,16 @@ void SetLedPowerIdx(uint32_t led, uint32_t state) } else { led_power &= (0xFF ^ mask); } - uint16_t led_pwm_set = 0; + uint16_t pwm = 0; if (bitRead(Settings.ledpwm_mask, led)) { - if (bitRead(led_inverted, led)) { - if (state) { - led_pwm_set = Settings.pwm_range - Settings.ledpwm_on; - } else { - led_pwm_set = Settings.pwm_range - Settings.ledpwm_off; - } - } else { - if (state) { - led_pwm_set = Settings.ledpwm_on; - } else { - led_pwm_set = Settings.ledpwm_off; - } - } - analogWrite(Pin(GPIO_LED1, led), led_pwm_set); + #ifdef USE_LIGHT + pwm = changeUIntScale(ledGamma10(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 1023, 0, Settings.pwm_range); // gamma corrected + #else //USE_LIGHT + pwm = changeUIntScale((uint16_t)(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 255, 0, Settings.pwm_range); // linear + #endif //USE_LIGHT + analogWrite(Pin(GPIO_LED1, led), bitRead(led_inverted, led) ? Settings.pwm_range - pwm : pwm); } else { - DigitalWrite(GPIO_LED1, led, bitRead(led_inverted, led) ? !state : state); + DigitalWrite(GPIO_LED1, led, bitRead(led_inverted, led) ? !state : state); } } #ifdef USE_BUZZER