Compare commits
1 Commits
v0.4
...
colorFlowE
Author | SHA1 | Date | |
---|---|---|---|
bfc359e554
|
@ -10,6 +10,7 @@ configItems = [
|
|||||||
{"label":"MQTT Password", "key":"mqttPass", "type":"C", "length":32, "default":"geheim123"},
|
{"label":"MQTT Password", "key":"mqttPass", "type":"C", "length":32, "default":"geheim123"},
|
||||||
{"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32, "default":"RgbLed1"},
|
{"label":"MQTT ClientId", "key":"mqttClientId", "type":"C", "length":32, "default":"RgbLed1"},
|
||||||
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":8883},
|
{"label":"MQTT Port", "key":"mqttPort", "type":"I", "default":8883},
|
||||||
|
{"label":"MQTT Topic Flow Command", "key":"mqttTopicFlowCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/FlowCommand"},
|
||||||
{"label":"MQTT Topic Color Command", "key":"mqttTopicColorCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/ColorCommand"},
|
{"label":"MQTT Topic Color Command", "key":"mqttTopicColorCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/ColorCommand"},
|
||||||
{"label":"MQTT Topic Command", "key":"mqttTopicCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/Command"},
|
{"label":"MQTT Topic Command", "key":"mqttTopicCommand", "type":"C", "length":64, "default":"IoT/RgbLed1/Command"},
|
||||||
{"label":"MQTT DebugTopic", "key":"mqttDebugTopic", "type":"C", "length":64, "default":"IoT/RgbLed1/Debug"},
|
{"label":"MQTT DebugTopic", "key":"mqttDebugTopic", "type":"C", "length":64, "default":"IoT/RgbLed1/Debug"},
|
||||||
|
@ -47,6 +47,58 @@ Adafruit_NeoPixel pixels(NUM_OF_LEDs, PIXEL_PIN, NEO_RGB + NEO_KHZ400);
|
|||||||
|
|
||||||
bool show = false;
|
bool show = false;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
E_FC_IDLE,
|
||||||
|
E_FC_ABORT,
|
||||||
|
E_FC_FADE_ON,
|
||||||
|
E_FC_FADE_OFF,
|
||||||
|
} e_colorFlowCmds;
|
||||||
|
|
||||||
|
e_colorFlowCmds colorFlowCmd = E_FC_IDLE;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
E_FE_IDLE,
|
||||||
|
E_FE_INCREASE_BRIGHTNESS,
|
||||||
|
E_FE_DECREASE_BRIGHTNESS,
|
||||||
|
} e_colorFlowStates;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static void colorFlowEngine() {
|
||||||
|
e_colorFlowStates colorFlowState = E_FE_IDLE;
|
||||||
|
|
||||||
|
if (colorFlowCmd == E_FC_ABORT) {
|
||||||
|
colorFlowState = E_FE_IDLE;
|
||||||
|
colorFlowCmd = E_FC_IDLE;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (colorFlowState) {
|
||||||
|
case E_FE_IDLE:
|
||||||
|
switch (colorFlowCmd) {
|
||||||
|
case E_FC_FADE_ON:
|
||||||
|
colorFlowState = E_FE_INCREASE_BRIGHTNESS;
|
||||||
|
break;
|
||||||
|
case E_FC_FADE_OFF:
|
||||||
|
colorFlowState = E_FE_DECREASE_BRIGHTNESS;
|
||||||
|
break;
|
||||||
|
case E_FC_IDLE:
|
||||||
|
case E_FC_ABORT:
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
colorFlowCmd = E_FC_IDLE;
|
||||||
|
break;
|
||||||
|
case E_FE_INCREASE_BRIGHTNESS:
|
||||||
|
// fade up
|
||||||
|
show = true;
|
||||||
|
break;
|
||||||
|
case E_FE_DECREASE_BRIGHTNESS:
|
||||||
|
// fade down
|
||||||
|
show = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static CRGB evaluationColorWord(char* cmd) {
|
static CRGB evaluationColorWord(char* cmd) {
|
||||||
@ -97,6 +149,7 @@ static CRGB evaluationColorWord(char* cmd) {
|
|||||||
void subscribeApplication() {
|
void subscribeApplication() {
|
||||||
mqttClient.subscribe(configBlock.mqttTopicColorCommand);
|
mqttClient.subscribe(configBlock.mqttTopicColorCommand);
|
||||||
mqttClient.subscribe(configBlock.mqttTopicCommand);
|
mqttClient.subscribe(configBlock.mqttTopicCommand);
|
||||||
|
mqttClient.subscribe(configBlock.mqttTopicFlowCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -133,7 +186,17 @@ static void setColor(int8_t ledNumber, uint8_t red, uint8_t green, uint8_t blue)
|
|||||||
|
|
||||||
|
|
||||||
void callbackApplication(char *topic, uint8_t tokenCnt, char **tokens) {
|
void callbackApplication(char *topic, uint8_t tokenCnt, char **tokens) {
|
||||||
if (! strcmp(topic, configBlock.mqttTopicCommand)) {
|
if (! strcmp(topic, configBlock.mqttTopicFlowCommand)) {
|
||||||
|
switch (tokenCnt) {
|
||||||
|
case 1:
|
||||||
|
if (! strcmp(tokens[0], "up")) {
|
||||||
|
colorFlowCmd = E_FC_FADE_ON;
|
||||||
|
} else if (! strcmp(tokens[0], "down")) {
|
||||||
|
colorFlowCmd = E_FC_FADE_OFF;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (! strcmp(topic, configBlock.mqttTopicCommand)) {
|
||||||
int32_t n, b;
|
int32_t n, b;
|
||||||
CRGB pseudoColors;
|
CRGB pseudoColors;
|
||||||
switch (tokenCnt) {
|
switch (tokenCnt) {
|
||||||
@ -149,6 +212,7 @@ void callbackApplication(char *topic, uint8_t tokenCnt, char **tokens) {
|
|||||||
setColor(n, b, b, b);
|
setColor(n, b, b, b);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
colorFlowCmd = E_FC_ABORT;
|
||||||
} else if (! strcmp(topic, configBlock.mqttTopicColorCommand)) {
|
} else if (! strcmp(topic, configBlock.mqttTopicColorCommand)) {
|
||||||
int32_t n, red, green, blue;
|
int32_t n, red, green, blue;
|
||||||
CRGB colors;
|
CRGB colors;
|
||||||
@ -180,6 +244,7 @@ void callbackApplication(char *topic, uint8_t tokenCnt, char **tokens) {
|
|||||||
setColor(n, red, green, blue);
|
setColor(n, red, green, blue);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
colorFlowCmd = E_FC_ABORT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,7 +269,7 @@ void setupApplication() {
|
|||||||
void loopApplication() {
|
void loopApplication() {
|
||||||
mqttLoop();
|
mqttLoop();
|
||||||
|
|
||||||
|
colorFlowEngine();
|
||||||
|
|
||||||
if (show) {
|
if (show) {
|
||||||
show = false;
|
show = false;
|
||||||
|
@ -36,6 +36,7 @@ void configServeIndex() {
|
|||||||
strcpy(configBlock.mqttPass, "geheim123");
|
strcpy(configBlock.mqttPass, "geheim123");
|
||||||
strcpy(configBlock.mqttClientId, "RgbLed1");
|
strcpy(configBlock.mqttClientId, "RgbLed1");
|
||||||
configBlock.mqttPort = 8883;
|
configBlock.mqttPort = 8883;
|
||||||
|
strcpy(configBlock.mqttTopicFlowCommand, "IoT/RgbLed1/FlowCommand");
|
||||||
strcpy(configBlock.mqttTopicColorCommand, "IoT/RgbLed1/ColorCommand");
|
strcpy(configBlock.mqttTopicColorCommand, "IoT/RgbLed1/ColorCommand");
|
||||||
strcpy(configBlock.mqttTopicCommand, "IoT/RgbLed1/Command");
|
strcpy(configBlock.mqttTopicCommand, "IoT/RgbLed1/Command");
|
||||||
strcpy(configBlock.mqttDebugTopic, "IoT/RgbLed1/Debug");
|
strcpy(configBlock.mqttDebugTopic, "IoT/RgbLed1/Debug");
|
||||||
@ -194,6 +195,21 @@ void configServeIndex() {
|
|||||||
buffer += configBlock.mqttPort;
|
buffer += configBlock.mqttPort;
|
||||||
buffer += "\"";
|
buffer += "\"";
|
||||||
|
|
||||||
|
buffer +=
|
||||||
|
" />"
|
||||||
|
" </td>"
|
||||||
|
" </tr>"
|
||||||
|
" <tr>"
|
||||||
|
" <td>"
|
||||||
|
" <label for\"mqttTopicFlowCommand\">MQTT Topic Flow Command</label>"
|
||||||
|
" </td><td>"
|
||||||
|
" <input type=\"text\" name=\"mqttTopicFlowCommand\" id=\"mqttTopicFlowCommand\" ";
|
||||||
|
|
||||||
|
buffer += " size=\"64\" ";
|
||||||
|
buffer += " value=\"";
|
||||||
|
buffer += configBlock.mqttTopicFlowCommand;
|
||||||
|
buffer += "\"";
|
||||||
|
|
||||||
buffer +=
|
buffer +=
|
||||||
" />"
|
" />"
|
||||||
" </td>"
|
" </td>"
|
||||||
@ -300,6 +316,8 @@ void configServeGetConfiguration() {
|
|||||||
strcpy(configBlock.mqttClientId, arg.c_str());
|
strcpy(configBlock.mqttClientId, arg.c_str());
|
||||||
arg = webServer.arg("mqttPort");
|
arg = webServer.arg("mqttPort");
|
||||||
configBlock.mqttPort = atoi(arg.c_str());
|
configBlock.mqttPort = atoi(arg.c_str());
|
||||||
|
arg = webServer.arg("mqttTopicFlowCommand");
|
||||||
|
strcpy(configBlock.mqttTopicFlowCommand, arg.c_str());
|
||||||
arg = webServer.arg("mqttTopicColorCommand");
|
arg = webServer.arg("mqttTopicColorCommand");
|
||||||
strcpy(configBlock.mqttTopicColorCommand, arg.c_str());
|
strcpy(configBlock.mqttTopicColorCommand, arg.c_str());
|
||||||
arg = webServer.arg("mqttTopicCommand");
|
arg = webServer.arg("mqttTopicCommand");
|
||||||
@ -368,6 +386,10 @@ void showConfiguration() {
|
|||||||
Serial.print(configBlock.mqttPort);
|
Serial.print(configBlock.mqttPort);
|
||||||
Serial.println(">");
|
Serial.println(">");
|
||||||
|
|
||||||
|
Serial.print("mqttTopicFlowCommand = <");
|
||||||
|
Serial.print(configBlock.mqttTopicFlowCommand);
|
||||||
|
Serial.println(">");
|
||||||
|
|
||||||
Serial.print("mqttTopicColorCommand = <");
|
Serial.print("mqttTopicColorCommand = <");
|
||||||
Serial.print(configBlock.mqttTopicColorCommand);
|
Serial.print(configBlock.mqttTopicColorCommand);
|
||||||
Serial.println(">");
|
Serial.println(">");
|
||||||
|
@ -9,6 +9,7 @@ typedef struct {
|
|||||||
char mqttPass[32];
|
char mqttPass[32];
|
||||||
char mqttClientId[32];
|
char mqttClientId[32];
|
||||||
uint32_t mqttPort;
|
uint32_t mqttPort;
|
||||||
|
char mqttTopicFlowCommand[64];
|
||||||
char mqttTopicColorCommand[64];
|
char mqttTopicColorCommand[64];
|
||||||
char mqttTopicCommand[64];
|
char mqttTopicCommand[64];
|
||||||
char mqttDebugTopic[64];
|
char mqttDebugTopic[64];
|
||||||
|
Reference in New Issue
Block a user