static mode and broken glow animation

This commit is contained in:
2025-11-08 22:16:45 +01:00
parent a66a3ce2dc
commit a13381603b

74
main.c
View File

@ -20,7 +20,7 @@
#define MAIN_LOOP_SLEEP 10U // Main loop delay in ms
#define BUTTON_LONG_PRESS_DURATION_MS 1000U // Long press threshold
#define BUTTON_SHORT_PRESS_DURATION_MS 100U // Short press threshold
#define BUTTON_SHORT_PRESS_DURATION_MS 50U // Short press threshold
#define BUTTON_IGNORE_DURATION_MS 2000U // Time button ignored after long press
#define BUTTON_CONFIRMATION_BLINK_LOOPS 10U // Blink animation for confirmation
#define BUTTON_CONFIRMATION_BLINK_DURATION_MS 50U
@ -30,8 +30,8 @@
typedef enum _Mode
{
ANIMATION,
STATIC_GLOW,
ANIMATION_BLINK,
ANIMATION_GLOW,
STATIC_FULL,
MAX_COUNT,
} eMode;
@ -39,11 +39,13 @@ typedef enum _Mode
/** Global flags */
volatile bool bLedEnabled = true;
volatile bool bBtnLongPressed = false;
volatile eMode eModeCurrent = ANIMATION;
volatile eMode eModeCurrent = ANIMATION_BLINK;
// Forward declarations
static inline void toggleMode(void);
void blinkLed(bool resetCounters);
void ledAnimationBlink(bool resetCounters);
void ledAnimationGlow(void);
void ledStaticFull(void);
static inline void leds_off(void);
static inline void leds_on(void);
static void battery_level_indicator(void);
@ -68,7 +70,7 @@ int main(void)
battery_level_indicator(); // TODO: Implement
bool bLedEnabledOld = bLedEnabled;
eModeCurrent = ANIMATION;
eModeCurrent = ANIMATION_BLINK;
while (true)
{
@ -117,14 +119,14 @@ int main(void)
{
switch (eModeCurrent)
{
case ANIMATION:
blinkLed(false); // run normal blink
case ANIMATION_BLINK:
ledAnimationBlink(false); // run normal blink
break;
case STATIC_GLOW:
blinkLed(false); // run normal blink
case ANIMATION_GLOW:
ledAnimationGlow();
break;
case STATIC_FULL:
blinkLed(false); // run normal blink
ledStaticFull();
break;
default:
break;
@ -247,7 +249,7 @@ ISR(PORTA_PORT_vect)
* 18: all off, wait 250 ms → restart
* Special: every 3rd cycle, all LEDs ON for 250 ms
*/
void blinkLed(bool resetCounters)
void ledAnimationBlink(bool resetCounters)
{
const uint8_t T50 = MS_TO_TICKS(50);
const uint8_t T100 = MS_TO_TICKS(100);
@ -367,3 +369,51 @@ void blinkLed(bool resetCounters)
break;
}
}
/**
* @brief All LEDs with static full power
*/
void ledStaticFull(void)
{
leds_on();
}
/**
* @brief Outer LEDs with glow animation
*/
void ledAnimationGlow(void)
{
static uint8_t brightness = 0;
static int8_t direction = 1;
static uint8_t pwm_counter = 0;
pwm_counter++;
if (pwm_counter >= 100)
{
pwm_counter = 0;
// Update brightness level
brightness += direction;
if (brightness >= 100)
{
brightness = 100;
direction = -1;
}
else if (brightness == 0)
{
direction = 1;
}
}
// Software PWM: compare pwm_counter with brightness
if (pwm_counter < brightness)
{
VPORTA.OUT |= (PA1_SET_MASK | PA3_SET_MASK);
}
else
{
VPORTA.OUT &= ~(PA1_SET_MASK | PA3_SET_MASK);
}
}