Add support for night mode

This commit is contained in:
2020-11-19 18:05:49 +01:00
parent 0f2dca5ec7
commit 8b47ed295e
12 changed files with 173 additions and 30 deletions

View File

@@ -3,10 +3,14 @@
#include "config.h"
#include "led.h"
volatile struct TIME led_display = { 0, 0, 0 };
volatile struct TIME_HMS led_display = { 0, 0, 0 };
volatile uint8_t led_btnes;
void led_init(void)
{
// Set brightness
led_btnes = 1<<(ram_cfg.led_brightness);
// Set outputs
ANODES_DIR |= HOUR_ANODE | MINUTE_ANODE | SECOND_ANODE;
LED_DIR |= 0x3F; // 0b00111111
@@ -19,17 +23,18 @@ void led_init(void)
TIMSK |= (1<<TOIE0);
}
void led_set_btness(uint8_t btness)
void led_set_btness(uint8_t btnes)
{
ram_cfg.led_brightness = (1<<btness);
if(!ram_cfg.led_brightness) ram_cfg.led_brightness = 1;
if(btnes > 7) btnes = 0;
led_btnes = 1<<btnes;
ram_cfg.led_brightness = btnes;
dump_ram2eem();
}
void led_inc_btness(void)
{
ram_cfg.led_brightness <<= 1;
if(!ram_cfg.led_brightness) ram_cfg.led_brightness = 1;
if(++(ram_cfg.led_brightness) > 7) ram_cfg.led_brightness = 0;
led_btnes = 1<<(ram_cfg.led_brightness);
dump_ram2eem();
}
@@ -44,15 +49,15 @@ ISR(TIMER0_OVF_vect)
{
case 1:
LED_PORT = ~led_display.hour;
ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~HOUR_ANODE : 0xFF;
ANODES_PORT = led_btnes >= pwm_counter ? ~HOUR_ANODE : 0xFF;
break;
case 2:
LED_PORT = ~led_display.minute;
ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~MINUTE_ANODE : 0xFF;
ANODES_PORT = led_btnes >= pwm_counter ? ~MINUTE_ANODE : 0xFF;
break;
case 4:
LED_PORT = ~led_display.second;
ANODES_PORT = ram_cfg.led_brightness >= pwm_counter ? ~SECOND_ANODE : 0xFF;
ANODES_PORT = led_btnes >= pwm_counter ? ~SECOND_ANODE : 0xFF;
break;
}