massive Update
This commit is contained in:
106
Software/src/ledcontrol.cpp
Normal file
106
Software/src/ledcontrol.cpp
Normal file
@@ -0,0 +1,106 @@
|
||||
|
||||
// === ledcontrol.cpp ===
|
||||
#include "ledcontrol.h"
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
#include "globals.h"
|
||||
|
||||
static Adafruit_NeoPixel leds(1, GPIO_LED, NEO_RGB + NEO_KHZ800);
|
||||
|
||||
static uint32_t basicColor = 0x000000;
|
||||
static LedPattern basicPattern = LED_PATTERN_ON;
|
||||
|
||||
static uint32_t overrideColor = 0;
|
||||
static LedPattern overridePattern = LED_PATTERN_ON;
|
||||
static uint32_t overrideEndTime = 0;
|
||||
static bool overrideActive = false;
|
||||
|
||||
void LEDControl_Init(uint8_t pin)
|
||||
{
|
||||
leds.begin();
|
||||
leds.setBrightness(LubeConfig.LED_Max_Brightness);
|
||||
leds.setPixelColor(0, 0);
|
||||
leds.show();
|
||||
}
|
||||
|
||||
void LEDControl_SetBasic(uint32_t color, LedPattern pattern)
|
||||
{
|
||||
basicColor = color;
|
||||
basicPattern = pattern;
|
||||
}
|
||||
|
||||
void LEDControl_SetOverride(uint32_t color, LedPattern pattern, uint32_t durationMs)
|
||||
{
|
||||
overrideColor = color;
|
||||
overridePattern = pattern;
|
||||
overrideEndTime = millis() + durationMs;
|
||||
overrideActive = true;
|
||||
if (durationMs == 0)
|
||||
overrideEndTime = 0xFFFFFFFF; // Kein Timeout
|
||||
}
|
||||
|
||||
void LEDControl_ClearOverride()
|
||||
{
|
||||
overrideActive = false;
|
||||
overrideEndTime = 0;
|
||||
}
|
||||
|
||||
void LEDControl_Update()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
uint32_t color = basicColor;
|
||||
LedPattern pattern = basicPattern;
|
||||
|
||||
// Check override
|
||||
if (overrideActive)
|
||||
{
|
||||
if (overrideEndTime != 0xFFFFFFFF && now >= overrideEndTime)
|
||||
{
|
||||
LEDControl_ClearOverride();
|
||||
}
|
||||
else
|
||||
{
|
||||
color = overrideColor;
|
||||
pattern = overridePattern;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t brightness = LubeConfig.LED_Min_Brightness;
|
||||
bool on = true;
|
||||
|
||||
switch (pattern)
|
||||
{
|
||||
case LED_PATTERN_ON:
|
||||
brightness = LubeConfig.LED_Max_Brightness;
|
||||
break;
|
||||
|
||||
case LED_PATTERN_FLASH:
|
||||
on = (now % 1000) < 100;
|
||||
brightness = LubeConfig.LED_Max_Brightness;
|
||||
break;
|
||||
|
||||
case LED_PATTERN_FLASH_FAST:
|
||||
on = (now % 500) < 50;
|
||||
brightness = LubeConfig.LED_Max_Brightness;
|
||||
break;
|
||||
|
||||
case LED_PATTERN_BLINK:
|
||||
on = (now % 1000) < 500;
|
||||
brightness = on ? LubeConfig.LED_Max_Brightness : 0;
|
||||
break;
|
||||
|
||||
case LED_PATTERN_BLINK_FAST:
|
||||
on = (now % 400) < 200;
|
||||
brightness = on ? LubeConfig.LED_Max_Brightness : 0;
|
||||
break;
|
||||
|
||||
case LED_PATTERN_BREATH:
|
||||
brightness = map(now % 2000, 0, 1000, LubeConfig.LED_Min_Brightness, LubeConfig.LED_Max_Brightness);
|
||||
if ((now % 2000) >= 1000)
|
||||
brightness = LubeConfig.LED_Max_Brightness - (brightness - LubeConfig.LED_Min_Brightness);
|
||||
break;
|
||||
}
|
||||
|
||||
leds.setBrightness(brightness);
|
||||
leds.setPixelColor(0, on ? color : 0);
|
||||
leds.show();
|
||||
}
|
Reference in New Issue
Block a user