Просмотр исходного кода

led config params commands

master
gituser 1 месяц назад
Родитель
Сommit
fd4a087d75
6 измененных файлов: 70 добавлений и 59 удалений
  1. 5
    0
      Commands.h
  2. 0
    39
      ConfigManager.cpp
  3. 11
    3
      LEDLamp.ino
  4. 50
    15
      LEDStripManager.cpp
  5. 3
    1
      LEDStripManager.h
  6. 1
    1
      sloeber.ino.cpp

+ 5
- 0
Commands.h Просмотреть файл

@@ -14,6 +14,7 @@ enum Commands {
CMD_SWITCH_LED,
CMD_CHG_COLOR,
CMD_CHG_BRIGHTNESS,
CMD_CHG_CFG_PARAM,
CMD_RESET_WIFI_CFG
};

@@ -27,6 +28,8 @@ static const char* cmdToString(Commands cmd) {
return "CHG_COLOR";
case CMD_CHG_BRIGHTNESS:
return "CHG_BRIGHTNESS";
case CMD_CHG_CFG_PARAM:
return "CHG_CFG_PARAM";
case CMD_RESET_WIFI_CFG:
return "RESET_WIFI_CFG";
default:
@@ -47,6 +50,8 @@ static Commands strToCommand(const char *cmd) {
return CMD_CHG_COLOR;
if (strcmp(cmd, "CHG_BRIGHTNESS") == 0)
return CMD_CHG_BRIGHTNESS;
if (strcmp(cmd, "CHG_CFG_PARAM") == 0)
return CMD_CHG_CFG_PARAM;
if (strcmp(cmd, "RESET_WIFI_CFG") == 0)
return CMD_RESET_WIFI_CFG;


+ 0
- 39
ConfigManager.cpp Просмотреть файл

@@ -55,45 +55,6 @@ Config& ConfigManager::setToDefaultConfig() {
_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.put(0, _config);
EEPROM.commit();

+ 11
- 3
LEDLamp.ino Просмотреть файл

@@ -146,9 +146,10 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length)

} else if (strToCommand(cmd) == CMD_CHG_COLOR) {
const char *value = doc["val"];
const char *color = doc["clr"];
unsigned int r, g, b, w;
if (sscanf(value, "%u,%u,%u,%u", &r, &g, &b, &w) == 4) {
ledMngr.onColorChange(r, g, b, w);
if (sscanf(color, "%u,%u,%u,%u", &r, &g, &b, &w) == 4) {
ledMngr.onColorChange(value, r, g, b, w);
}
} else if (strToCommand(cmd) == CMD_CHG_BRIGHTNESS) {
const char *value = doc["val"];
@@ -156,10 +157,17 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t *payload, size_t length)
if (sscanf(value, "%u", &br) == 1) {
ledMngr.onBrightnessChange(br);
}
} else if (strToCommand(cmd) == CMD_CHG_CFG_PARAM) {
const char *value = doc["val"];
const char *amount = doc["amt"];
uint32_t amountVal;
if (sscanf(amount, "%u", &amountVal) == 1) {
ledMngr.onCfgParamChange(value, amountVal);
}

} else if (strToCommand(cmd) == CMD_RESET_WIFI_CFG) {

resetWifiConfiguration(num);

} else {

String s = "ACK UNKNOWN: " + msg;

+ 50
- 15
LEDStripManager.cpp Просмотреть файл

@@ -126,15 +126,34 @@ void LEDStripManager::onModeChange(LEDModes mode) {
}
}

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

this->setAll(red, green, blue, white);
RGBWColor *color = nullptr;

if (cfgVal == "singleColor")
color = &cfg.singleColor;
else if (cfgVal == "segmentColor1")
color = &cfg.segmentColor1;
else if (cfgVal == "segmentColor2")
color = &cfg.segmentColor2;
else if (cfgVal == "segmentColor3")
color = &cfg.segmentColor3;

if (color != nullptr) {
color->r = red;
color->g = green;
color->b = blue;
color->w = white;

configManager.saveConfig(cfg);
}

if (cfgVal == "singleColor") {
this->setAll(red, green, blue, white);
} else {
setSegments();
}
}

void LEDStripManager::onBrightnessChange(uint8_t brightness) {
@@ -145,6 +164,25 @@ void LEDStripManager::onBrightnessChange(uint8_t brightness) {
this->setBrightness(brightness);
}

void LEDStripManager::onCfgParamChange(String cfgVal, uint32_t amount) {
Config cfg = configManager.getConfig();

if (cfgVal == "rainbowDelay")
cfg.rainbowDelay = amount;
else if (cfgVal == "spectralStepTime")
cfg.spectralStepTime = amount;
else if (cfgVal == "fadingHoldTime")
cfg.fadingHoldTime = amount;
else if (cfgVal == "fadingFadeTime")
cfg.fadingFadeTime = amount;
else if (cfgVal == "flashOnTime")
cfg.flashOnTime = amount;
else if (cfgVal == "flashOffTime")
cfg.flashOffTime = amount;

configManager.saveConfig(cfg);
}

void LEDStripManager::setSegments() {

Config cfg = configManager.getConfig();
@@ -208,7 +246,6 @@ void LEDStripManager::rainbow() {
}
}


void LEDStripManager::doSpectral() {

Config cfg = configManager.getConfig();
@@ -262,11 +299,11 @@ void LEDStripManager::fade() {
static uint8_t currentColor = 0;
static uint32_t stateStart = millis();

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

if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) {

uint32_t holdTime = cfg.fadingHoldTime;
uint32_t fadeTime = cfg.fadingFadeTime;
uint32_t now = millis();
uint32_t elapsed = now - stateStart;

@@ -321,17 +358,14 @@ void LEDStripManager::fade() {

void LEDStripManager::flash() {

Config cfg = configManager.getConfig();

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

static bool ledOn = false;
static uint32_t lastChange = 0;

if (digitalRead(LED_STRIP_POWER_PIN) == HIGH) {

Config cfg = configManager.getConfig();
uint32_t onMillis = cfg.flashOnTime;
uint32_t offMillis = cfg.flashOffTime;
uint32_t now = millis();

if (ledOn) {
@@ -352,3 +386,4 @@ void LEDStripManager::flash() {
}
}
}


+ 3
- 1
LEDStripManager.h Просмотреть файл

@@ -44,10 +44,12 @@ class LEDStripManager {

void onModeChange(LEDModes mode);

void onColorChange(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);
void onColorChange(String cfgVal, uint8_t red, uint8_t green, uint8_t blue, uint8_t white);

void onBrightnessChange(uint8_t brightness);

void onCfgParamChange(String cfgVal, uint32_t amount);

private:
Adafruit_NeoPixel strip;


+ 1
- 1
sloeber.ino.cpp Просмотреть файл

@@ -2,7 +2,7 @@
//This is a automatic generated file
//Please do not modify this file
//If you touch this file your change will be overwritten during the next build
//This file has been generated on 2026-06-29 13:40:40
//This file has been generated on 2026-06-29 15:24:39

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

Загрузка…
Отмена
Сохранить