More sensible behaviour

* When setting PWM values, updates all the LEDs (instant response). Uses led_power values.
* If LEDLINK not set, but LED1 is, LED1 is the status led. When turning on/off, setledlink uses digitalwrite (which does not respect the new pwm operation). In this case only, we will use the setledpoweridx instead of digitalwrite - costly (every 250ms this runs), but edge case / legacy. Allows more intuitive operation - if we blink an LED with the max and min PWM limits, we'd expect it to respect these. In this case, blink will also now update the led_power status, which keeps this accurate e.g. if ledpower 1 cmnd was sent, then blink occurred, led_state would read a 1 for that bit but the led would be off (but nothing was reading it for status so it didn't cause any trouble). Leaving digitalwrite when LEDLINK is defined as this is more efficient and the use case for pwm leds is to find buttons - link indicator would become more ambiguous for no benefit.
This commit is contained in:
George 2020-05-20 11:25:32 +10:00
parent bea58f223f
commit e21cbfdc5d
3 changed files with 12 additions and 5 deletions

View File

@ -1901,6 +1901,7 @@ void CmndSetLedPwmOff(void)
} else {
Settings.ledpwm_off = XdrvMailbox.payload;
}
UpdateLedPowerAll();
}
ResponseCmndNumber(Settings.ledpwm_off);
}
@ -1915,6 +1916,7 @@ void CmndSetLedPwmOn(void)
} else {
Settings.ledpwm_on = XdrvMailbox.payload;
}
UpdateLedPowerAll();
}
ResponseCmndNumber(Settings.ledpwm_on);
}

View File

@ -336,6 +336,13 @@ void SetPowerOnState(void)
blink_powersave = power;
}
void UpdateLedPowerAll()
{
for (uint32_t i = 0; i < leds_present; i++) {
SetLedPowerIdx(i, bitRead(led_power, i));
}
}
void SetLedPowerIdx(uint32_t led, uint32_t state)
{
if (!PinUsed(GPIO_LEDLNK) && (0 == led)) { // Legacy - LED1 is link led only if LED2 is present
@ -400,10 +407,8 @@ void SetLedLink(uint32_t state)
uint32_t led_pin = Pin(GPIO_LEDLNK);
uint32_t led_inv = ledlnk_inverted;
if (99 == led_pin) { // Legacy - LED1 is status
led_pin = Pin(GPIO_LED1);
led_inv = bitRead(led_inverted, 0);
}
if (led_pin < 99) {
SetLedPowerIdx(0, state);
} else if (led_pin < 99) {
if (state) { state = 1; }
digitalWrite(led_pin, (led_inv) ? !state : state);
}

View File

@ -1,4 +1,4 @@
/*
/*
tasmota.ino - Tasmota firmware for iTead Sonoff, Wemos and NodeMCU hardware
Copyright (C) 2020 Theo Arends