Feature simply tracks last active time. After x minutes of no activity, lcd.noBacklight() is called (assuming FEATURE_DISPLAY), which turns off the LCD's backlight. Additionally, analogWrite(keyer_power_led,keyer_power_led_asleep_duty); is called to dim the optional Power LED. If anything is written to the LCD, or button is pressed, or encoder is turned, or keyboard key is pressed, then lcd.backlight() is called to switch on the backlight, and keyer_power_led_awake_duty is used for PWM to LED.
To save cycles, check_backlight() usually returns immediately and will only dim/brighten once per second.
Defines are added to all of: keyer_debug.h, keyer_features_and_options.h, keyer_pin_settings.h, and keyer_settings*.h.
Feature is commented out by default.
Default LED pin is zero (not used).
Default LED asleep duty cycle is 25/255 (pretty dim).
Default LED awake is 255/255 (full on).
I added an last active time update at the end of check_sleep() after CPU awakens so backlight also comes on.
I added #ifdef'd calls to lcd.backlight() in service_display() to ensure that paths that were about to write characters did so to a lit LCD. I didn't add active time updates there, since it's taken care of elsewhere -- I just didn't want a second to go by with a dim LCD.
I also added an active time update check in check_rotary_encoder(). I mention this because there was not a update for Sleep time, but maybe there should be? I think you can turn the encoder just seconds before it sleeps, and maybe the CPU would still Sleep rather than be put off another 10 minutes? I needed it because otherwise you could touch the encoder and the lights stayed off.
Otherwise, I just dropped in an #ifdef'd last active time update where there was one for Sleep. I use a different variable so that you can use both features together (dim in 5 minutes, sleep in 10 minutes).
Potential Issues
I only tested with FEATURE_LDC_YDv1. Specifically, I'm not certain the non-I2C boards use lcd.noBacklight() and lcd.backlight().
I see the Adafruit has a colored backlight. I didn't do anything about saving / restoring that color.
At first I thought about running the backlight off PWM as well (so you could control brightness when awake or asleep), but that seemed needlessly complex in circuitry (might need a transistor if board PWM pin can't supply enough current) for little value.
I don't see how to update documentation, or I'd happily add a sentence to the DISPLAY doc pages to mention this possibility.
…minutes
Feature simply tracks last active time. After x minutes of no activity,
lcd.noBacklight()
is called (assuming FEATURE_DISPLAY), which turns off the LCD's backlight. Additionally,analogWrite(keyer_power_led,keyer_power_led_asleep_duty);
is called to dim the optional Power LED. If anything is written to the LCD, or button is pressed, or encoder is turned, or keyboard key is pressed, thenlcd.backlight()
is called to switch on the backlight, andkeyer_power_led_awake_duty
is used for PWM to LED.To save cycles,
check_backlight()
usually returns immediately and will only dim/brighten once per second.Defines are added to all of: keyer_debug.h, keyer_features_and_options.h, keyer_pin_settings.h, and keyer_settings*.h.
Feature is commented out by default.
Default LED pin is zero (not used).
Default LED asleep duty cycle is 25/255 (pretty dim).
Default LED awake is 255/255 (full on).
I added an last active time update at the end of check_sleep() after CPU awakens so backlight also comes on.
I added #ifdef'd calls to lcd.backlight() in service_display() to ensure that paths that were about to write characters did so to a lit LCD. I didn't add active time updates there, since it's taken care of elsewhere -- I just didn't want a second to go by with a dim LCD.
I also added an active time update check in check_rotary_encoder(). I mention this because there was not a update for Sleep time, but maybe there should be? I think you can turn the encoder just seconds before it sleeps, and maybe the CPU would still Sleep rather than be put off another 10 minutes? I needed it because otherwise you could touch the encoder and the lights stayed off.
Otherwise, I just dropped in an #ifdef'd last active time update where there was one for Sleep. I use a different variable so that you can use both features together (dim in 5 minutes, sleep in 10 minutes).
Potential Issues