mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-24 23:07:17 +00:00
Refactor LedPwm code
This commit is contained in:
parent
dc9ce42888
commit
aafa0862ab
@ -358,17 +358,17 @@ void SetLedPowerIdx(uint32_t led, uint32_t state)
|
|||||||
} else {
|
} else {
|
||||||
led_power &= (0xFF ^ mask);
|
led_power &= (0xFF ^ mask);
|
||||||
}
|
}
|
||||||
uint16_t pwm = 0;
|
uint16_t pwm = 0;
|
||||||
if (bitRead(Settings.ledpwm_mask, led)) {
|
if (bitRead(Settings.ledpwm_mask, led)) {
|
||||||
#ifdef USE_LIGHT
|
#ifdef USE_LIGHT
|
||||||
pwm = changeUIntScale(ledGamma10(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 1023, 0, Settings.pwm_range); // gamma corrected
|
pwm = changeUIntScale(ledGamma10(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 1023, 0, Settings.pwm_range); // gamma corrected
|
||||||
#else //USE_LIGHT
|
#else //USE_LIGHT
|
||||||
pwm = changeUIntScale((uint16_t)(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 255, 0, Settings.pwm_range); // linear
|
pwm = changeUIntScale((uint16_t)(state ? Settings.ledpwm_on : Settings.ledpwm_off), 0, 255, 0, Settings.pwm_range); // linear
|
||||||
#endif //USE_LIGHT
|
#endif //USE_LIGHT
|
||||||
analogWrite(Pin(GPIO_LED1, led), bitRead(led_inverted, led) ? Settings.pwm_range - pwm : pwm);
|
analogWrite(Pin(GPIO_LED1, led), bitRead(led_inverted, led) ? Settings.pwm_range - pwm : pwm);
|
||||||
} 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
|
||||||
if (led == 0) {
|
if (led == 0) {
|
||||||
@ -403,8 +403,9 @@ void SetLedLink(uint32_t state)
|
|||||||
uint32_t led_pin = Pin(GPIO_LEDLNK);
|
uint32_t led_pin = Pin(GPIO_LEDLNK);
|
||||||
uint32_t led_inv = ledlnk_inverted;
|
uint32_t led_inv = ledlnk_inverted;
|
||||||
if (99 == led_pin) { // Legacy - LED1 is status
|
if (99 == led_pin) { // Legacy - LED1 is status
|
||||||
SetLedPowerIdx(0, state);
|
SetLedPowerIdx(0, state);
|
||||||
} else if (led_pin < 99) {
|
}
|
||||||
|
else if (led_pin < 99) {
|
||||||
if (state) { state = 1; }
|
if (state) { state = 1; }
|
||||||
digitalWrite(led_pin, (led_inv) ? !state : state);
|
digitalWrite(led_pin, (led_inv) ? !state : state);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
/*
|
/*
|
||||||
tasmota.ino - Tasmota firmware for iTead Sonoff, Wemos and NodeMCU hardware
|
tasmota.ino - Tasmota firmware for iTead Sonoff, Wemos and NodeMCU hardware
|
||||||
|
|
||||||
Copyright (C) 2020 Theo Arends
|
Copyright (C) 2020 Theo Arends
|
||||||
|
Loading…
x
Reference in New Issue
Block a user