|
|
|
@@ -33,21 +33,28 @@ void LEDStripManager::begin() { |
|
|
|
if (cfg.version != CONFIG_VERSION) { |
|
|
|
// Initalize cfg with defaults |
|
|
|
cfg = configManager.setToDefaultConfig(); |
|
|
|
configManager.loadConfig(); |
|
|
|
cfg = configManager.getConfig(); |
|
|
|
} |
|
|
|
|
|
|
|
strip.begin(); // Initialisiert den NeoPixel-Streifen |
|
|
|
strip.clear(); |
|
|
|
strip.show(); // Setzt alle LEDs auf "aus" |
|
|
|
strip.setBrightness(cfg.brightness); // Helligkeit (0 bis 255) |
|
|
|
|
|
|
|
// Setzt die erste LED (Index 0) auf rotes Licht (Rot, Grün, Blau, Weiss) |
|
|
|
strip.setPixelColor(0, strip.Color(255, 0, 0, 0)); |
|
|
|
// Setzt die zweite LED auf grün |
|
|
|
strip.setPixelColor(1, strip.Color(0, 255, 0, 0)); |
|
|
|
strip.setPixelColor(2, strip.Color(0, 0, 255, 0)); |
|
|
|
strip.setPixelColor(3, strip.Color(0, 0, 0, 255)); |
|
|
|
// Schickt die Farbinformationen zum LED-Streifen |
|
|
|
show(); |
|
|
|
|
|
|
|
if (cfg.mode == LM_SINGLE_COLOR) { |
|
|
|
strip.setBrightness(cfg.brightness); // Helligkeit (0 bis 255) |
|
|
|
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w); |
|
|
|
} else { |
|
|
|
// Setzt die erste LED (Index 0) auf rotes Licht (Rot, Grün, Blau, Weiss) |
|
|
|
strip.setPixelColor(0, strip.Color(255, 0, 0, 0)); |
|
|
|
// Setzt die zweite LED auf grün |
|
|
|
strip.setPixelColor(1, strip.Color(0, 255, 0, 0)); |
|
|
|
strip.setPixelColor(2, strip.Color(0, 0, 255, 0)); |
|
|
|
strip.setPixelColor(3, strip.Color(0, 0, 0, 255)); |
|
|
|
// Schickt die Farbinformationen zum LED-Streifen |
|
|
|
show(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::clear() { |
|
|
|
@@ -65,14 +72,8 @@ void LEDStripManager::on() { |
|
|
|
delay(50); |
|
|
|
digitalWrite(LED_STRIP_DATA_PIN, HIGH); |
|
|
|
delay(50); |
|
|
|
strip.begin(); |
|
|
|
strip.show(); |
|
|
|
// TODO: Load the state from the eeprom |
|
|
|
strip.setPixelColor(0, strip.Color(255, 0, 0, 0)); |
|
|
|
strip.setPixelColor(1, strip.Color(0, 255, 0, 0)); |
|
|
|
strip.setPixelColor(2, strip.Color(0, 0, 255, 0)); |
|
|
|
strip.setPixelColor(3, strip.Color(0, 0, 0, 255)); |
|
|
|
strip.show(); |
|
|
|
|
|
|
|
begin(); |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::off() { |
|
|
|
@@ -86,21 +87,21 @@ void LEDStripManager::off() { |
|
|
|
|
|
|
|
void LEDStripManager::setBrightness(uint8_t brightness) { |
|
|
|
strip.setBrightness(brightness); |
|
|
|
strip.show(); |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue) { |
|
|
|
void LEDStripManager::setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue, uint8_t white) { |
|
|
|
if (index >= strip.numPixels()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
strip.setPixelColor(index, strip.Color(red, green, blue)); |
|
|
|
strip.setPixelColor(index, strip.Color(red, green, blue, white)); |
|
|
|
strip.show(); |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::setAll(uint8_t red, uint8_t green, uint8_t blue) { |
|
|
|
void LEDStripManager::setAll(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) { |
|
|
|
for (uint16_t i = 0; i < strip.numPixels(); i++) { |
|
|
|
strip.setPixelColor(i, strip.Color(red, green, blue)); |
|
|
|
strip.setPixelColor(i, strip.Color(red, green, blue, white)); |
|
|
|
} |
|
|
|
|
|
|
|
strip.show(); |
|
|
|
} |
|
|
|
|
|
|
|
@@ -110,7 +111,25 @@ void LEDStripManager::onModeChange(LEDModes mode) { |
|
|
|
configManager.saveConfig(cfg); |
|
|
|
|
|
|
|
//TODO: react on mode change on strip |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) { |
|
|
|
Config cfg = configManager.getConfig(); |
|
|
|
cfg.color.r = red; |
|
|
|
cfg.color.g = green; |
|
|
|
cfg.color.b = blue; |
|
|
|
cfg.color.w = white; |
|
|
|
configManager.saveConfig(cfg); |
|
|
|
|
|
|
|
this->setAll(red, green, blue, white); |
|
|
|
} |
|
|
|
|
|
|
|
void LEDStripManager::onBrightnessChange(uint8_t brightness) { |
|
|
|
Config cfg = configManager.getConfig(); |
|
|
|
cfg.brightness = brightness; |
|
|
|
configManager.saveConfig(cfg); |
|
|
|
|
|
|
|
this->setBrightness(brightness); |
|
|
|
} |
|
|
|
|
|
|
|
uint32_t |
|
|
|
@@ -142,4 +161,3 @@ void LEDStripManager::rainbow(uint8_t wait) { |
|
|
|
delay(wait); |
|
|
|
} |
|
|
|
} |
|
|
|
|