Fixed MQTT stuff.
This commit is contained in:
parent
0d88dc3e0f
commit
d966d2ef8e
@ -18,4 +18,4 @@ monitor_port = /dev/cu.wchusbserial*
|
||||
monitor_speed = 74880
|
||||
monitor_filters = default, time, send_on_enter, esp8266_exception_decoder
|
||||
lib_deps = fastled/FastLED @ 3.4.0
|
||||
PubSubClient
|
||||
PubSubClient @ 2.8
|
@ -44,13 +44,13 @@ bool Corner::reached_level(uint16_t level) {
|
||||
}
|
||||
|
||||
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) {
|
||||
this->effect_id = random16();
|
||||
LOGln("Set effect_id to %d", this->effect_id);
|
||||
//LOGln("Set effect_id to %d", this->effect_id);
|
||||
} else {
|
||||
if (this->effect_id == eid) {
|
||||
LOGln("'Old' effect. Doing nothing.");
|
||||
//LOGln("'Old' effect. Doing nothing.");
|
||||
return;
|
||||
}
|
||||
this->effect_id = eid;
|
||||
|
@ -77,7 +77,7 @@ void setup_fastled() {
|
||||
FastLED.addLeds<WS2812B, 5, GRB>(leds, LEDS_PER_CORNER * CORNERS_PER_PART * NODE_COUNT).setCorrection(TypicalLEDStrip);
|
||||
LOGln("LEDs: %3d", LED_COUNT);
|
||||
FastLED.setBrightness(255);
|
||||
FastLED.setDither(DISABLE_DITHER);
|
||||
//FastLED.setDither(DISABLE_DITHER);
|
||||
FastLED.setMaxPowerInVoltsAndMilliamps(5, MAX_MILLIAMPS);
|
||||
set_all_leds(CRGB::Black);
|
||||
}
|
||||
@ -195,14 +195,19 @@ void loop() {
|
||||
}
|
||||
|
||||
} else if (active_mode == AM_OFF) {
|
||||
LOGln("Blanking.");
|
||||
for(Node* node : nodes) {
|
||||
node->set_color(CRGB::Black);
|
||||
node->draw();
|
||||
}
|
||||
} else { // This includes AM_ERROR
|
||||
for(Node* node : nodes) {
|
||||
node->set_color(CRGB::Black);
|
||||
}
|
||||
nodes[0]->set_color(CRGB::Red);
|
||||
for(Node* node : nodes) {
|
||||
node->draw();
|
||||
}
|
||||
}
|
||||
|
||||
last_loop = millis();
|
||||
|
11
src/mqtt.cpp
11
src/mqtt.cpp
@ -24,16 +24,24 @@ void callback(char* topic, byte* pl, unsigned int length) {
|
||||
uint16_t duration = 0;
|
||||
AnimationMode new_mode = AM_NONE;
|
||||
String current_part;
|
||||
LOGln("Received command %s", payload.c_str());
|
||||
while (payload.length() > 0) {
|
||||
int offset = payload.indexOf("&");
|
||||
if (offset != -1) {
|
||||
current_part = payload.substring(0, offset);
|
||||
payload = payload.substring(offset + 1);
|
||||
} else {
|
||||
current_part = payload;
|
||||
payload = "";
|
||||
}
|
||||
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 value = current_part.substring(offset+1);
|
||||
LOGln(" Processing key %s with value %s", key.c_str(), value.c_str());
|
||||
|
||||
if (key.equals("mode")) {
|
||||
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("Finished processing the command.");
|
||||
|
||||
if (new_mode != AM_NONE) {
|
||||
if (duration > 0) {
|
||||
|
@ -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) {
|
||||
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_id == 0) effect_id = random16();
|
||||
for(Corner* corner : this->_corners) {
|
||||
|
Loading…
Reference in New Issue
Block a user