Ver código fonte

color and brightness commands

master
gituser 1 mês atrás
pai
commit
5b8c26fe0f
5 arquivos alterados com 84 adições e 31 exclusões
  1. 20
    2
      HtmlPages.h
  2. 14
    1
      LEDLamp.ino
  3. 43
    25
      LEDStripManager.cpp
  4. 6
    2
      LEDStripManager.h
  5. 1
    1
      sloeber.ino.cpp

+ 20
- 2
HtmlPages.h Ver arquivo

input { input {
width: 100%; width: 100%;
padding: 12px; padding: 12px;
margin: 8px 0;
margin-top: 10px;
border-radius: 10px; border-radius: 10px;
border: none; border: none;
outline: none; outline: none;
align-items: center; align-items: center;
margin-top: 10px; margin-top: 10px;
} }

.rowTop {
margin-top: 20px;
}
.mac { .mac {
font-size: 11px; font-size: 11px;
+ R"rawliteral(</div> + R"rawliteral(</div>
<div class="btn-row"> <div class="btn-row">
<button type="button" onclick="ledOn()">LED EIN</button>
<div id="led_status">⚫</div> <div id="led_status">⚫</div>
<button type="button" onclick="ledOn()">LED EIN</button>
<button type="button" onclick="ledOff()">LED AUS</button> <button type="button" onclick="ledOff()">LED AUS</button>
</div> </div>
<input id="id_cmd" class="rowTop" placeholder="Commad...">

<div class="btn-row"> <div class="btn-row">
<button type="button" onclick="sendCommand()">Command senden</button>
</div>
<div class="btn-row rowTop">
<button type="button" onclick="resetWifiCfg()">Wifi-Konfiguration löschen</button> <button type="button" onclick="resetWifiCfg()">Wifi-Konfiguration löschen</button>
</div> </div>
<div id="reset_status" class="info">-</div> <div id="reset_status" class="info">-</div>
ws.send("{\"cmd\":\"RESET_WIFI_CFG\",\"val\":\"\"}"); ws.send("{\"cmd\":\"RESET_WIFI_CFG\",\"val\":\"\"}");
} }
} }

function sendCommand() {
if (ws && ws.readyState === 1) {
cmd = document.getElementById('id_cmd').value
ws.send(cmd);
}
}

</script> </script>



+ 14
- 1
LEDLamp.ino Ver arquivo

Serial.print("WS empfangen: "); Serial.print("WS empfangen: ");
Serial.println(msg); Serial.println(msg);


JsonDocument doc;
JsonDocument doc; // e.g: {"cmd":"SWITCH_LED","val":"on"}
deserializeJson(doc, msg); deserializeJson(doc, msg);
const char *cmd = doc["cmd"]; const char *cmd = doc["cmd"];


LEDModes mode = parseMode(value); LEDModes mode = parseMode(value);
ledMngr.onModeChange(mode); ledMngr.onModeChange(mode);


} else if (strToCommand(cmd) == CMD_CHG_COLOR) {
const char *value = doc["val"];
unsigned int r, g, b, w;
if (sscanf(value, "%u,%u,%u,%u", &r, &g, &b, &w) == 4) {
ledMngr.onColorChange(r, g, b, w);
}
} else if (strToCommand(cmd) == CMD_CHG_BRIGHTNESS) {
const char *value = doc["val"];
unsigned int br;
if (sscanf(value, "%u", &br) == 1) {
ledMngr.onBrightnessChange(br);
}

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


resetWifiConfiguration(num); resetWifiConfiguration(num);

+ 43
- 25
LEDStripManager.cpp Ver arquivo

if (cfg.version != CONFIG_VERSION) { if (cfg.version != CONFIG_VERSION) {
// Initalize cfg with defaults // Initalize cfg with defaults
cfg = configManager.setToDefaultConfig(); cfg = configManager.setToDefaultConfig();
configManager.loadConfig();
cfg = configManager.getConfig();
} }


strip.begin(); // Initialisiert den NeoPixel-Streifen strip.begin(); // Initialisiert den NeoPixel-Streifen
strip.clear(); strip.clear();
strip.show(); // Setzt alle LEDs auf "aus" 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() { void LEDStripManager::clear() {
delay(50); delay(50);
digitalWrite(LED_STRIP_DATA_PIN, HIGH); digitalWrite(LED_STRIP_DATA_PIN, HIGH);
delay(50); 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() { void LEDStripManager::off() {


void LEDStripManager::setBrightness(uint8_t brightness) { void LEDStripManager::setBrightness(uint8_t brightness) {
strip.setBrightness(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()) { if (index >= strip.numPixels()) {
return; 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++) { 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(); strip.show();
} }


configManager.saveConfig(cfg); configManager.saveConfig(cfg);


//TODO: react on mode change on strip //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 uint32_t
delay(wait); delay(wait);
} }
} }


+ 6
- 2
LEDStripManager.h Ver arquivo



void setBrightness(uint8_t brightness); void setBrightness(uint8_t brightness);


void setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue);
void setPixel(uint16_t index, uint8_t red, uint8_t green, uint8_t blue, uint8_t white);


void setAll(uint8_t red, uint8_t green, uint8_t blue);
void setAll(uint8_t red, uint8_t green, uint8_t blue, uint8_t white);


void rainbow(uint8_t wait); void rainbow(uint8_t wait);


void onModeChange(LEDModes mode); void onModeChange(LEDModes mode);


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

void onBrightnessChange(uint8_t brightness);

private: private:
Adafruit_NeoPixel strip; Adafruit_NeoPixel strip;



+ 1
- 1
sloeber.ino.cpp Ver arquivo

//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-23 22:04:18
//This file has been generated on 2026-06-27 09:18:25


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

Carregando…
Cancelar
Salvar