Parcourir la source

enhanced config for LED strip driving

master
gituser il y a 1 mois
Parent
révision
88e5db782f
5 fichiers modifiés avec 137 ajouts et 40 suppressions
  1. 90
    12
      ConfigManager.cpp
  2. 13
    2
      ConfigManager.h
  3. 1
    6
      LEDLamp.ino
  4. 32
    19
      LEDStripManager.cpp
  5. 1
    1
      sloeber.ino.cpp

+ 90
- 12
ConfigManager.cpp Voir le fichier

Config& ConfigManager::setToDefaultConfig() { Config& ConfigManager::setToDefaultConfig() {
memset(&_config, 0, sizeof(Config)); memset(&_config, 0, sizeof(Config));


String ssid = "";
String pass = "";
ssid.toCharArray(_config.ssid, sizeof(_config.ssid));
pass.toCharArray(_config.pass, sizeof(_config.pass));

_config.wifiValid = false;
_config.version = CONFIG_VERSION; _config.version = CONFIG_VERSION;
_config.mode = LM_SINGLE_COLOR;
_config.color.r = 0;
_config.color.g = 0;
_config.color.b = 0;
_config.color.w = 255;
_config.brightness = 128;

_config = setToDefaultWiFiConfig(_config);
_config = setToDefaultLEDConfig(_config);

// String ssid = "";
// String pass = "";
// ssid.toCharArray(_config.ssid, sizeof(_config.ssid));
// pass.toCharArray(_config.pass, sizeof(_config.pass));
//
// _config.wifiValid = false;
// _config.mode = LM_SINGLE_COLOR;
// _config.singleColor.r = 0;
// _config.singleColor.g = 0;
// _config.singleColor.b = 0;
// _config.singleColor.w = 255;
//
// _config.brightness = 128;
//
// _config.segmentColor1.r = 255;
// _config.segmentColor1.g = 0;
// _config.segmentColor1.b = 0;
// _config.segmentColor1.w = 0;
//
// _config.segmentColor2.r = 0;
// _config.segmentColor2.g = 255;
// _config.segmentColor2.b = 0;
// _config.segmentColor2.w = 0;
//
// _config.segmentColor3.r = 0;
// _config.segmentColor3.g = 0;
// _config.segmentColor3.b = 255;
// _config.segmentColor3.w = 0;
//
// _config.rainbowDelay = 20;
//
// _config.spectralStepTime = 10000;
//
// _config.fadingHoldTime = 5000;
// _config.fadingFadeTime = 1000;
//
// _config.flashOnTime = 1000;
// _config.flashOffTime = 500;


EEPROM.begin(sizeof(Config)); EEPROM.begin(sizeof(Config));
EEPROM.put(0, _config); EEPROM.put(0, _config);
return _config; return _config;
} }


Config& ConfigManager::setToDefaultWiFiConfig(Config &config) {
String ssid = "";
String pass = "";
ssid.toCharArray(config.ssid, sizeof(config.ssid));
pass.toCharArray(config.pass, sizeof(config.pass));
config.wifiValid = false;

return config;
}

Config& ConfigManager::setToDefaultLEDConfig(Config &config) {
config.mode = LM_SINGLE_COLOR;
config.singleColor.r = 0;
config.singleColor.g = 0;
config.singleColor.b = 0;
config.singleColor.w = 255;

config.brightness = 128;

config.segmentColor1.r = 255;
config.segmentColor1.g = 0;
config.segmentColor1.b = 0;
config.segmentColor1.w = 0;

config.segmentColor2.r = 0;
config.segmentColor2.g = 255;
config.segmentColor2.b = 0;
config.segmentColor2.w = 0;

config.segmentColor3.r = 0;
config.segmentColor3.g = 0;
config.segmentColor3.b = 255;
config.segmentColor3.w = 0;

config.rainbowDelay = 20;

config.spectralStepTime = 10000;

config.fadingHoldTime = 5000;
config.fadingFadeTime = 1000;

config.flashOnTime = 1000;
config.flashOffTime = 500;

return config;
}


Config& ConfigManager::getConfig() { Config& ConfigManager::getConfig() {
return _config; return _config;
} }

+ 13
- 2
ConfigManager.h Voir le fichier

#include <EEPROM.h> #include <EEPROM.h>
#include "LEDModes.h" #include "LEDModes.h"


#define CONFIG_VERSION 1
#define CONFIG_VERSION 3


typedef struct __attribute__((packed)) { typedef struct __attribute__((packed)) {
uint8_t r; uint8_t r;
bool wifiValid; bool wifiValid;
LEDModes mode; LEDModes mode;
uint8_t brightness; uint8_t brightness;
RGBWColor color;
RGBWColor singleColor;
RGBWColor segmentColor1;
RGBWColor segmentColor2;
RGBWColor segmentColor3;
uint32_t rainbowDelay;
uint32_t spectralStepTime;
uint32_t fadingHoldTime;
uint32_t fadingFadeTime;
uint32_t flashOnTime;
uint32_t flashOffTime;
} Config; } Config;


class ConfigManager { class ConfigManager {
bool saveConfig(const Config &config); bool saveConfig(const Config &config);
void resetConfig(); void resetConfig();
Config& setToDefaultConfig(); Config& setToDefaultConfig();
Config& setToDefaultWiFiConfig(Config &config);
Config& setToDefaultLEDConfig(Config &config);
Config& getConfig(); Config& getConfig();


private: private:

+ 1
- 6
LEDLamp.ino Voir le fichier

pass.toCharArray(cfg.pass, sizeof(cfg.pass)); pass.toCharArray(cfg.pass, sizeof(cfg.pass));
cfg.wifiValid = true; cfg.wifiValid = true;
cfg.version = CONFIG_VERSION; cfg.version = CONFIG_VERSION;
cfg.mode = LM_SINGLE_COLOR;
cfg.color.r = 0;
cfg.color.g = 0;
cfg.color.b = 0;
cfg.color.w = 255;
cfg.brightness = 128;
cfg = configManager.setToDefaultLEDConfig(cfg);
configManager.saveConfig(cfg); configManager.saveConfig(cfg);


webServer.send(200, "text/html", getConnectionSuccessPage()); webServer.send(200, "text/html", getConnectionSuccessPage());

+ 32
- 19
LEDStripManager.cpp Voir le fichier

switch (cfg.mode) { switch (cfg.mode) {
case LM_SINGLE_COLOR: case LM_SINGLE_COLOR:
this->setBrightness(cfg.brightness); this->setBrightness(cfg.brightness);
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w);
setAll(cfg.singleColor.r, cfg.singleColor.g, cfg.singleColor.b, cfg.singleColor.w);
return; return;
case LM_SEGMENTS: case LM_SEGMENTS:
this->setBrightness(cfg.brightness); this->setBrightness(cfg.brightness);
switch (mode) { switch (mode) {
case LM_SINGLE_COLOR: case LM_SINGLE_COLOR:
this->setBrightness(cfg.brightness); this->setBrightness(cfg.brightness);
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w);
setAll(cfg.singleColor.r, cfg.singleColor.g, cfg.singleColor.b, cfg.singleColor.w);
return; return;
case LM_SEGMENTS: case LM_SEGMENTS:
this->setBrightness(cfg.brightness); this->setBrightness(cfg.brightness);


void LEDStripManager::onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) { void LEDStripManager::onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white) {
Config cfg = configManager.getConfig(); Config cfg = configManager.getConfig();
cfg.color.r = red;
cfg.color.g = green;
cfg.color.b = blue;
cfg.color.w = white;
cfg.singleColor.r = red;
cfg.singleColor.g = green;
cfg.singleColor.b = blue;
cfg.singleColor.w = white;
configManager.saveConfig(cfg); configManager.saveConfig(cfg);


this->setAll(red, green, blue, white); this->setAll(red, green, blue, white);
} }


void LEDStripManager::setSegments() { void LEDStripManager::setSegments() {

Config cfg = configManager.getConfig();
RGBWColor c1 = cfg.segmentColor1;
RGBWColor c2 = cfg.segmentColor2;
RGBWColor c3 = cfg.segmentColor3;

int nbrPixel = strip.numPixels(); int nbrPixel = strip.numPixels();
int third = nbrPixel / 3; int third = nbrPixel / 3;


for (int i = 0; i < nbrPixel; i++) { for (int i = 0; i < nbrPixel; i++) {
if (i < third) if (i < third)
setPixel(i, 255, 0, 0, 0);
setPixel(i, c1.r, c1.g, c1.b, c1.w);
else if (i < 2 * third) else if (i < 2 * third)
setPixel(i, 0, 255, 0, 0);
setPixel(i, c2.r, c2.g, c2.b, c2.w);
else else
setPixel(i, 0, 0, 255, 0);
setPixel(i, c3.r, c3.g, c3.b, c3.w);
} }
show(); show();
} }


void LEDStripManager::rainbow() { void LEDStripManager::rainbow() {


static uint8_t delay = 20;
Config cfg = configManager.getConfig();

const uint32_t delay = cfg.rainbowDelay;
static uint32_t lastUpdate = 0; static uint32_t lastUpdate = 0;


if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) {
} }
} }



void LEDStripManager::doSpectral() { void LEDStripManager::doSpectral() {

Config cfg = configManager.getConfig();

static uint16_t hue = 0; static uint16_t hue = 0;
static uint32_t lastUpdate = 0; static uint32_t lastUpdate = 0;

const uint32_t stepTime = 10000; // 5 s bis zur nächsten Farbe
const uint16_t hueStep = 65536 / 6; // Abstand der Hauptfarben const uint16_t hueStep = 65536 / 6; // Abstand der Hauptfarben
const uint32_t stepTime = cfg.spectralStepTime; // Zeit bis zur nächsten Farbe


if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) {


FADE_IN FADE_IN
}; };


Config cfg = configManager.getConfig();

static State state = HOLD; static State state = HOLD;
static uint8_t currentColor = 0; static uint8_t currentColor = 0;
static uint32_t stateStart = millis(); static uint32_t stateStart = millis();


const uint32_t holdTime = 5000;
const uint32_t fadeTime = 1000;
const uint32_t holdTime = cfg.fadingHoldTime;
const uint32_t fadeTime = cfg.fadingFadeTime;


if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) { if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) {


Config cfg = configManager.getConfig();

uint32_t now = millis(); uint32_t now = millis();
uint32_t elapsed = now - stateStart; uint32_t elapsed = now - stateStart;




void LEDStripManager::flash() { void LEDStripManager::flash() {


static const uint32_t onMillis = 1000;
static const uint32_t offMillis = 500;
Config cfg = configManager.getConfig();

static const uint32_t onMillis = cfg.flashOnTime;
static const uint32_t offMillis = cfg.flashOffTime;


static bool ledOn = false; static bool ledOn = false;
static uint32_t lastChange = 0; static uint32_t lastChange = 0;
} else { } else {
if (now - lastChange >= offMillis) { if (now - lastChange >= offMillis) {
// LEDs einschalten // LEDs einschalten
setAll(cfg.color.r, cfg.color.g, cfg.color.b, cfg.color.w);
setAll(cfg.singleColor.r, cfg.singleColor.g, cfg.singleColor.b, cfg.singleColor.w);
ledOn = true; ledOn = true;
lastChange = now; lastChange = now;
} }

+ 1
- 1
sloeber.ino.cpp Voir le fichier

//This is a automatic generated file //This is a automatic generated file
//Please do not modify this file //Please do not modify this file
//If you touch this file your change will be overwritten during the next build //If you touch this file your change will be overwritten during the next build
//This file has been generated on 2026-06-29 10:34:17
//This file has been generated on 2026-06-29 13:40:40


#include "Arduino.h" #include "Arduino.h"
#include "Arduino.h" #include "Arduino.h"

Chargement…
Annuler
Enregistrer