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:
George 2020-05-23 17:13:04 +10:00
parent 833d89203f
commit e780f25283
4 changed files with 18 additions and 26 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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