mirror of https://github.com/arendst/Tasmota.git
Gamma correction
Implement changes proposed by @s-hadinger review. * Use 0-255 range in settings * Apply gamma correction from xdrv_light & use changuintscale helper fn (as per pwm light routine)
This commit is contained in:
parent
833d89203f
commit
e780f25283
|
@ -570,12 +570,12 @@ struct {
|
||||||
int16_t windmeter_speed_factor; // F3C
|
int16_t windmeter_speed_factor; // F3C
|
||||||
uint8_t windmeter_tele_pchange; // F3E
|
uint8_t windmeter_tele_pchange; // F3E
|
||||||
uint8_t ledpwm_mask; // F3F
|
uint8_t ledpwm_mask; // F3F
|
||||||
|
uint8_t ledpwm_on; // F40
|
||||||
uint8_t free_f40[116]; // F40 - Decrement if adding new Setting variables just above and below
|
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
|
// 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_low; // FB8
|
||||||
uint16_t pulse_counter_debounce_high; // FBA
|
uint16_t pulse_counter_debounce_high; // FBA
|
||||||
uint32_t keeloq_master_msb; // FBC
|
uint32_t keeloq_master_msb; // FBC
|
||||||
|
|
|
@ -1058,7 +1058,7 @@ void SettingsDefaultSet2(void)
|
||||||
|
|
||||||
// Led PWM
|
// Led PWM
|
||||||
Settings.ledpwm_off = 0;
|
Settings.ledpwm_off = 0;
|
||||||
Settings.ledpwm_on = 1023;
|
Settings.ledpwm_on = 255;
|
||||||
Settings.ledpwm_mask = 0;
|
Settings.ledpwm_mask = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1420,7 +1420,7 @@ void SettingsDelta(void)
|
||||||
// ledpwm
|
// ledpwm
|
||||||
if (Settings.version < 0x08030001) {
|
if (Settings.version < 0x08030001) {
|
||||||
Settings.ledpwm_off = 0;
|
Settings.ledpwm_off = 0;
|
||||||
Settings.ledpwm_on = 1023;
|
Settings.ledpwm_on = 255;
|
||||||
Settings.ledpwm_mask = 0;
|
Settings.ledpwm_mask = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1896,8 +1896,8 @@ void CmndSetLedPwmOff(void)
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
if (XdrvMailbox.payload < 0) {
|
if (XdrvMailbox.payload < 0) {
|
||||||
Settings.ledpwm_off = 0;
|
Settings.ledpwm_off = 0;
|
||||||
} else if (XdrvMailbox.payload > Settings.pwm_range) {
|
} else if (XdrvMailbox.payload > 255) {
|
||||||
Settings.ledpwm_off = Settings.pwm_range;
|
Settings.ledpwm_off = 255;
|
||||||
} else {
|
} else {
|
||||||
Settings.ledpwm_off = XdrvMailbox.payload;
|
Settings.ledpwm_off = XdrvMailbox.payload;
|
||||||
}
|
}
|
||||||
|
@ -1911,8 +1911,8 @@ void CmndSetLedPwmOn(void)
|
||||||
if (XdrvMailbox.data_len > 0) {
|
if (XdrvMailbox.data_len > 0) {
|
||||||
if (XdrvMailbox.payload < 0) {
|
if (XdrvMailbox.payload < 0) {
|
||||||
Settings.ledpwm_on = 0;
|
Settings.ledpwm_on = 0;
|
||||||
} else if (XdrvMailbox.payload > Settings.pwm_range) {
|
} else if (XdrvMailbox.payload > 255) {
|
||||||
Settings.ledpwm_on = Settings.pwm_range;
|
Settings.ledpwm_on = 255;
|
||||||
} else {
|
} else {
|
||||||
Settings.ledpwm_on = XdrvMailbox.payload;
|
Settings.ledpwm_on = XdrvMailbox.payload;
|
||||||
}
|
}
|
||||||
|
|
|
@ -358,24 +358,16 @@ void SetLedPowerIdx(uint32_t led, uint32_t state)
|
||||||
} else {
|
} else {
|
||||||
led_power &= (0xFF ^ mask);
|
led_power &= (0xFF ^ mask);
|
||||||
}
|
}
|
||||||
uint16_t led_pwm_set = 0;
|
uint16_t pwm = 0;
|
||||||
if (bitRead(Settings.ledpwm_mask, led)) {
|
if (bitRead(Settings.ledpwm_mask, led)) {
|
||||||
if (bitRead(led_inverted, led)) {
|
#ifdef USE_LIGHT
|
||||||
if (state) {
|
pwm = changeUIntScale(ledGamma10(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 1023, 0, Settings.pwm_range); // gamma corrected
|
||||||
led_pwm_set = Settings.pwm_range - Settings.ledpwm_on;
|
#else //USE_LIGHT
|
||||||
} else {
|
pwm = changeUIntScale((uint16_t)(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 255, 0, Settings.pwm_range); // linear
|
||||||
led_pwm_set = Settings.pwm_range - Settings.ledpwm_off;
|
#endif //USE_LIGHT
|
||||||
}
|
analogWrite(Pin(GPIO_LED1, led), bitRead(led_inverted, led) ? Settings.pwm_range - pwm : pwm);
|
||||||
} else {
|
|
||||||
if (state) {
|
|
||||||
led_pwm_set = Settings.ledpwm_on;
|
|
||||||
} else {
|
|
||||||
led_pwm_set = Settings.ledpwm_off;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
analogWrite(Pin(GPIO_LED1, led), led_pwm_set);
|
|
||||||
} else {
|
} else {
|
||||||
DigitalWrite(GPIO_LED1, led, bitRead(led_inverted, led) ? !state : state);
|
DigitalWrite(GPIO_LED1, led, bitRead(led_inverted, led) ? !state : state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef USE_BUZZER
|
#ifdef USE_BUZZER
|
||||||
|
|
Loading…
Reference in New Issue