Fixed MQTT stuff.

This commit is contained in:
Fabian Schlenz 2021-01-08 17:10:46 +01:00
parent 0d88dc3e0f
commit d966d2ef8e
5 changed files with 21 additions and 7 deletions

View File

@ -18,4 +18,4 @@ monitor_port = /dev/cu.wchusbserial*
monitor_speed = 74880 monitor_speed = 74880
monitor_filters = default, time, send_on_enter, esp8266_exception_decoder monitor_filters = default, time, send_on_enter, esp8266_exception_decoder
lib_deps = fastled/FastLED @ 3.4.0 lib_deps = fastled/FastLED @ 3.4.0
PubSubClient PubSubClient @ 2.8

View File

@ -44,13 +44,13 @@ bool Corner::reached_level(uint16_t level) {
} }
void Corner::blend_to(CRGB target, uint16_t eid, uint8_t effect_speed) { void Corner::blend_to(CRGB target, uint16_t eid, uint8_t effect_speed) {
LOGln("blendTo called. Corner: %p, target: %d,%d,%d, eid: %d, 'old' effect_id: %d, speed: %d", this, target.r, target.g, target.b, eid, effect_id, effect_speed); //LOGln("blendTo called. Corner: %p, target: %d,%d,%d, eid: %d, 'old' effect_id: %d, speed: %d", this, target.r, target.g, target.b, eid, effect_id, effect_speed);
if (eid==0) { if (eid==0) {
this->effect_id = random16(); this->effect_id = random16();
LOGln("Set effect_id to %d", this->effect_id); //LOGln("Set effect_id to %d", this->effect_id);
} else { } else {
if (this->effect_id == eid) { if (this->effect_id == eid) {
LOGln("'Old' effect. Doing nothing."); //LOGln("'Old' effect. Doing nothing.");
return; return;
} }
this->effect_id = eid; this->effect_id = eid;

View File

@ -77,7 +77,7 @@ void setup_fastled() {
FastLED.addLeds<WS2812B, 5, GRB>(leds, LEDS_PER_CORNER * CORNERS_PER_PART * NODE_COUNT).setCorrection(TypicalLEDStrip); FastLED.addLeds<WS2812B, 5, GRB>(leds, LEDS_PER_CORNER * CORNERS_PER_PART * NODE_COUNT).setCorrection(TypicalLEDStrip);
LOGln("LEDs: %3d", LED_COUNT); LOGln("LEDs: %3d", LED_COUNT);
FastLED.setBrightness(255); FastLED.setBrightness(255);
FastLED.setDither(DISABLE_DITHER); //FastLED.setDither(DISABLE_DITHER);
FastLED.setMaxPowerInVoltsAndMilliamps(5, MAX_MILLIAMPS); FastLED.setMaxPowerInVoltsAndMilliamps(5, MAX_MILLIAMPS);
set_all_leds(CRGB::Black); set_all_leds(CRGB::Black);
} }
@ -195,14 +195,19 @@ void loop() {
} }
} else if (active_mode == AM_OFF) { } else if (active_mode == AM_OFF) {
LOGln("Blanking.");
for(Node* node : nodes) { for(Node* node : nodes) {
node->set_color(CRGB::Black); node->set_color(CRGB::Black);
node->draw();
} }
} else { // This includes AM_ERROR } else { // This includes AM_ERROR
for(Node* node : nodes) { for(Node* node : nodes) {
node->set_color(CRGB::Black); node->set_color(CRGB::Black);
} }
nodes[0]->set_color(CRGB::Red); nodes[0]->set_color(CRGB::Red);
for(Node* node : nodes) {
node->draw();
}
} }
last_loop = millis(); last_loop = millis();

View File

@ -24,16 +24,24 @@ void callback(char* topic, byte* pl, unsigned int length) {
uint16_t duration = 0; uint16_t duration = 0;
AnimationMode new_mode = AM_NONE; AnimationMode new_mode = AM_NONE;
String current_part; String current_part;
LOGln("Received command %s", payload.c_str());
while (payload.length() > 0) { while (payload.length() > 0) {
int offset = payload.indexOf("&"); int offset = payload.indexOf("&");
if (offset != -1) { if (offset != -1) {
current_part = payload.substring(0, offset); current_part = payload.substring(0, offset);
payload = payload.substring(offset + 1); payload = payload.substring(offset + 1);
} else {
current_part = payload;
payload = "";
} }
offset = current_part.indexOf("="); offset = current_part.indexOf("=");
if (offset==-1) continue; if (offset==-1) {
LOGln("Parameter without '=' detected: %s", current_part.c_str());
continue;
}
String key = current_part.substring(0, offset); String key = current_part.substring(0, offset);
String value = current_part.substring(offset+1); String value = current_part.substring(offset+1);
LOGln(" Processing key %s with value %s", key.c_str(), value.c_str());
if (key.equals("mode")) { if (key.equals("mode")) {
if (value.equals("nodes")) { new_mode = AM_NODES; } if (value.equals("nodes")) { new_mode = AM_NODES; }
@ -59,6 +67,7 @@ void callback(char* topic, byte* pl, unsigned int length) {
LOGln("Unknown key '%s'. (For reference: Value is '%s'.)", key.c_str(), value.c_str()); LOGln("Unknown key '%s'. (For reference: Value is '%s'.)", key.c_str(), value.c_str());
} }
} }
LOGln("Finished processing the command.");
if (new_mode != AM_NONE) { if (new_mode != AM_NONE) {
if (duration > 0) { if (duration > 0) {

View File

@ -57,7 +57,7 @@ Node* Node::create_neighbour(uint8_t edge) {
} }
void Node::blend_to(CRGB color, uint16_t effect_id, uint8_t effect_speed) { void Node::blend_to(CRGB color, uint16_t effect_id, uint8_t effect_speed) {
LOGln("Node::blend_to called. this:%p", this); //LOGln("Node::blend_to called. this:%p", this);
if (effect_speed == 0) effect_speed = random8(2)+1; if (effect_speed == 0) effect_speed = random8(2)+1;
if (effect_id == 0) effect_id = random16(); if (effect_id == 0) effect_id = random16();
for(Corner* corner : this->_corners) { for(Corner* corner : this->_corners) {