Skip to content

Commit

Permalink
Merge pull request #5 from MadMax2506/3-helligkeit-steuern
Browse files Browse the repository at this point in the history
3 helligkeit steuern
  • Loading branch information
MadMax2506 authored Sep 19, 2022
2 parents 3a9a9e7 + ede7eec commit f5b4964
Show file tree
Hide file tree
Showing 12 changed files with 131 additions and 390 deletions.
52 changes: 22 additions & 30 deletions Roomlight/Roomlight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,48 @@
#include "./src/network/Network.h"
#include "./src/mqttCallbackHandler/MqttCallbackHandler.h"

WlanESP* p_wlan;
WiFiClient p_espClient;
OTA_ESP* p_ota;
MQTT_ESP* p_mqtt;
Network* p_network;

Colors* p_color;
Device* p_keyboardDevice;
Device* p_bedWallDevice;
Device* p_bedSideDevice;

MqttCallbackHandler* mqttCallbackHandler;
WlanESP* p_wlan;
WiFiClient p_espClient;
OTA_ESP* p_ota;
MQTT_ESP* p_mqtt;
Network* p_network;
MqttCallbackHandler* p_mqttCbHandler;

void setup() {
Serial.begin(9600);

p_color = new Colors(MODUS_RGB);
p_keyboardDevice = new Device("deskLightingKeyboard", PIN_D4, 12, 0, 1, 8, p_color);
p_bedWallDevice = new Device("deskLightingBedWall", PIN_D3, 60, 9, 10, 17, p_color);
p_bedSideDevice = new Device("deskLightingBedSide", PIN_D2, 60, 18, 19, 26, p_color);

animate(); // show lights before connecting with network

p_wlan = new WlanESP(WLAN_SSID, WLAN_PASSWORD);
p_ota = new OTA_ESP();
p_mqtt = new MQTT_ESP(MQTT_SERVER_IP_ADDRESS, MQTT_SERVER_PORT, p_espClient);
p_network = new Network(p_wlan, p_ota, p_mqtt);

p_color = new Colors(MODUS_RGB);
p_keyboardDevice = new Device("deskLightingKeyboard", PIN_D4, 12, 0, 1, 7, p_color);
p_bedWallDevice = new Device("deskLightingBedWall", PIN_D3, 60, 8, 9, 15, p_color);
p_bedSideDevice = new Device("deskLightingBedSide", PIN_D2, 60, 16, 17, 23, p_color);

mqttCallbackHandler = new MqttCallbackHandler(
p_mqtt,
p_color,
p_keyboardDevice,
p_bedWallDevice,
p_bedSideDevice
);

p_network->init(
p_keyboardDevice,
p_bedWallDevice,
p_bedSideDevice,
onMqttPayload
);
p_mqttCbHandler = new MqttCallbackHandler(p_mqtt, p_color, p_keyboardDevice, p_bedWallDevice, p_bedSideDevice);
}

void loop() {
animate();
p_network->loop(p_keyboardDevice, p_bedWallDevice, p_bedSideDevice, onMqttPayload);
}

// Animate all devices
void animate() {
p_keyboardDevice->animate();
p_bedWallDevice->animate();
p_bedSideDevice->animate();

p_network->loop();
}

// Callback wrapper for the mqtt
void onMqttPayload(char* pc_topic, u_int8_t* pi_payload, unsigned int i_length) {
mqttCallbackHandler->onMqttPayload(pc_topic, pi_payload, i_length);
p_mqttCbHandler->onMqttPayload(pc_topic, pi_payload, i_length);
}
14 changes: 13 additions & 1 deletion Roomlight/src/device/animation/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ void Animation::reloadConf() {
p_animationTypeStorage->reload();
p_orientationStorage->reload();
p_statusStorage->reload();
p_brightnessStorage->reload();
p_storage->setCrc();
}

Expand All @@ -17,6 +18,7 @@ void Animation::readConf() {
c_type = p_storage->read(p_animationTypeStorage);
c_orientation = p_storage->read(p_orientationStorage);
b_status = p_storage->read(p_statusStorage);
i_brightness = p_storage->read(p_brightnessStorage);

restart();
}
Expand All @@ -27,6 +29,7 @@ void Animation::writeConf() {
p_storage->write(p_animationTypeStorage, c_type);
p_storage->write(p_orientationStorage, c_orientation);
p_storage->write(p_statusStorage, b_status);
p_storage->write(p_brightnessStorage, i_brightness);
p_storage->commit();
}

Expand All @@ -42,6 +45,7 @@ char* Animation::getConfAsJSON() {
str_msg+="\"blue\": " + String(pi_color[2]);
str_msg+= "},";
str_msg+= "\"orientation\": \"" + String(c_orientation) + "\",";
str_msg+= "\"brightness\": \"" + String(i_brightness) + "\",";

switch(c_type) {
case 'f':
Expand Down Expand Up @@ -87,6 +91,10 @@ void Animation::setStatus(boolean b_status) {
restart();
}

void Animation::setBrightness(int i_brightness) {
Animation::i_brightness = i_brightness;
}

boolean Animation::getStatus() {
return b_status;
}
Expand All @@ -95,7 +103,11 @@ void Animation::animate() {
//prüfen, ob Zustand Strip aktiv oder standby is
if(getStatus()) {
//Zustand ist aktiv


if(i_brightness != p_strip->getBrightness()) {
p_strip->dimmen(i_brightness, pi_color, i_time);
p_strip->setBrightness(i_brightness);
}
if(b_isChange) {
idle();
b_isChange = false;
Expand Down
16 changes: 11 additions & 5 deletions Roomlight/src/device/animation/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class Animation {
private:
int* pi_color;
int i_time;
int i_brightness;
char c_type;
char c_orientation;
boolean b_isChange;
Expand All @@ -22,6 +23,7 @@ class Animation {
StorageElement* p_animationTypeStorage;
StorageElement* p_orientationStorage;
StorageElement* p_statusStorage;
StorageElement* p_brightnessStorage;

Storage* p_storage;
Ledstrip* p_strip;
Expand All @@ -35,13 +37,16 @@ class Animation {

p_storage = new Storage(i_crcStorageIndex, i_startStorageIndex, i_endStorageIndex);

p_colorStorage = new StorageElementMulti(i_startStorageIndex + 0, i_startStorageIndex + 2, new int[3]{255, 255, 255});
p_animationTimeStorage = new StorageElement(i_startStorageIndex + 3, 0);
p_animationTypeStorage = new StorageElement(i_startStorageIndex + 4, 'f');
p_orientationStorage = new StorageElement(i_startStorageIndex + 5, 'r');
p_statusStorage = new StorageElement(i_startStorageIndex + 6, true);
p_colorStorage = new StorageElementMulti(i_startStorageIndex + 0, i_startStorageIndex + 2, new int[3]{255, 255, 255});
p_animationTimeStorage = new StorageElement(i_startStorageIndex + 3, 0);
p_animationTypeStorage = new StorageElement(i_startStorageIndex + 4, 'f');
p_orientationStorage = new StorageElement(i_startStorageIndex + 5, 'r');
p_statusStorage = new StorageElement(i_startStorageIndex + 6, true);
p_brightnessStorage = new StorageElement(i_startStorageIndex + 7, 250);

readConf();

p_strip->setBrightness(i_brightness);
}

void reloadConf();
Expand All @@ -54,6 +59,7 @@ class Animation {
void setType(char);
void setColor(int*);
void setStatus(boolean);
void setBrightness(int);

boolean getStatus();

Expand Down
Loading

0 comments on commit f5b4964

Please sign in to comment.