From c156002332a63763c1ae624eb6ad95eccb552ebb Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 30 Jun 2018 09:34:24 +0200 Subject: [PATCH 1/5] illucat --- platformio.ini | 2 +- src/examples/button/Button.h | 8 +++++--- src/examples/illucat/Illucat.h | 2 ++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/platformio.ini b/platformio.ini index 972848a..016561f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] -env_default = button +env_default = illucat [common] framework = arduino diff --git a/src/examples/button/Button.h b/src/examples/button/Button.h index f26d90a..45a0daa 100644 --- a/src/examples/button/Button.h +++ b/src/examples/button/Button.h @@ -13,13 +13,14 @@ class Button : public Sprocket { Task btnTask; MeshNet* net; int pin; + int warnlevel = 0; Button(SprocketConfig cfg) : Sprocket(cfg) {} Sprocket* activate(Scheduler* scheduler, Network* network) { pin = D2; pinMode(pin, INPUT_PULLUP); net = static_cast(network); net->mesh.onReceive(bind(&Button::receivedCallback,this, _1, _2)); - btnTask.set(TASK_MILLISECOND * 500, TASK_FOREVER, + btnTask.set(TASK_MILLISECOND * 250, TASK_FOREVER, bind(&Button::readPin, this, net)); scheduler->addTask(btnTask); btnTask.enable(); @@ -27,8 +28,9 @@ class Button : public Sprocket { void readPin(MeshNet* network){ if(digitalRead(pin)){ - Serial.println("btn pressed"); - network->broadcast("EE1B2E"); + Serial.println("warnlevel: " + String(warnlevel)); + warnlevel++; + network->broadcast(String(warnlevel)); } } diff --git a/src/examples/illucat/Illucat.h b/src/examples/illucat/Illucat.h index 0991f6c..dbc80fa 100644 --- a/src/examples/illucat/Illucat.h +++ b/src/examples/illucat/Illucat.h @@ -20,6 +20,8 @@ class Illucat : public Sprocket { NeoPattern* pixels; Illucat(SprocketConfig cfg, NeoPixelConfig pixelCfg) : Sprocket(cfg) { pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800, [](int pixels){}); + pixels->begin(); + pixels->setBrightness(64); } Sprocket* activate(Scheduler* scheduler, Network* network) { net = static_cast(network); From a5cffc9bce2b9123ca76f45f32eb85331b7d492f Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 30 Jun 2018 10:50:48 +0200 Subject: [PATCH 2/5] add color modes --- src/examples/illucat/Illucat.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/examples/illucat/Illucat.h b/src/examples/illucat/Illucat.h index dbc80fa..08a89b9 100644 --- a/src/examples/illucat/Illucat.h +++ b/src/examples/illucat/Illucat.h @@ -9,9 +9,12 @@ using namespace std; using namespace std::placeholders; +enum PIXEL_MODES {RED = 0xFF0000, GREEN = 0x00FF00, YELLOW = 0xffff00, BLUE = 0x0000FF, ORANGE = 0xffa500}; + struct NeoPixelConfig { int pin; int length; + int mode; }; class Illucat : public Sprocket { @@ -31,7 +34,11 @@ class Illucat : public Sprocket { void messageReceived( uint32_t from, String &msg ) { Serial.printf("illucat: received from %u msg=%s\n", from, msg.c_str()); - setHexColor(msg.c_str()); + setColor(msg.c_str()); + } + void setColor(const char *color){ + pixels->ColorSet(BLUE); + pixels->show(); } void setHexColor(const char *hex){ int r, g, b; From e496d99a8d50b0717d5423fb6cf1237dc92d147a Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 30 Jun 2018 11:34:12 +0200 Subject: [PATCH 3/5] colors dingens --- src/examples/button/Button.h | 2 ++ src/examples/illucat/Illucat.h | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/examples/button/Button.h b/src/examples/button/Button.h index 45a0daa..7fbe93f 100644 --- a/src/examples/button/Button.h +++ b/src/examples/button/Button.h @@ -14,6 +14,7 @@ class Button : public Sprocket { MeshNet* net; int pin; int warnlevel = 0; + int cycleEnd = 4; Button(SprocketConfig cfg) : Sprocket(cfg) {} Sprocket* activate(Scheduler* scheduler, Network* network) { pin = D2; @@ -30,6 +31,7 @@ class Button : public Sprocket { if(digitalRead(pin)){ Serial.println("warnlevel: " + String(warnlevel)); warnlevel++; + if(warnlevel == cycleEnd) warnlevel = 0; network->broadcast(String(warnlevel)); } } diff --git a/src/examples/illucat/Illucat.h b/src/examples/illucat/Illucat.h index 08a89b9..83d86f7 100644 --- a/src/examples/illucat/Illucat.h +++ b/src/examples/illucat/Illucat.h @@ -9,7 +9,10 @@ using namespace std; using namespace std::placeholders; +#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0]) + enum PIXEL_MODES {RED = 0xFF0000, GREEN = 0x00FF00, YELLOW = 0xffff00, BLUE = 0x0000FF, ORANGE = 0xffa500}; +int CAT_MODES[] = {RED, GREEN, YELLOW, BLUE, ORANGE}; struct NeoPixelConfig { int pin; @@ -21,6 +24,7 @@ class Illucat : public Sprocket { public: MeshNet* net; NeoPattern* pixels; + int currentMode; Illucat(SprocketConfig cfg, NeoPixelConfig pixelCfg) : Sprocket(cfg) { pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800, [](int pixels){}); pixels->begin(); @@ -34,11 +38,15 @@ class Illucat : public Sprocket { void messageReceived( uint32_t from, String &msg ) { Serial.printf("illucat: received from %u msg=%s\n", from, msg.c_str()); - setColor(msg.c_str()); + changeMode(msg.c_str()); } - void setColor(const char *color){ - pixels->ColorSet(BLUE); - pixels->show(); + void changeMode(const char *mode){ + currentMode = atoi(mode); + Serial.println(currentMode); + //if(ARRAY_LENGTH(CAT_MODES) >= (int) mode){ + pixels->ColorSet(CAT_MODES[currentMode]); + pixels->show(); + //} } void setHexColor(const char *hex){ int r, g, b; From 5b86bc9481b9affc827d0e118456321672b67876 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 30 Jun 2018 12:11:34 +0200 Subject: [PATCH 4/5] fix num of modes --- src/examples/button/Button.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/button/Button.h b/src/examples/button/Button.h index 7fbe93f..38452ea 100644 --- a/src/examples/button/Button.h +++ b/src/examples/button/Button.h @@ -14,7 +14,7 @@ class Button : public Sprocket { MeshNet* net; int pin; int warnlevel = 0; - int cycleEnd = 4; + int cycleEnd = 5; Button(SprocketConfig cfg) : Sprocket(cfg) {} Sprocket* activate(Scheduler* scheduler, Network* network) { pin = D2; From 9cf768dc8e10c35d34c87d8f03d4436c34a84013 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 30 Jun 2018 14:59:23 +0200 Subject: [PATCH 5/5] parse json --- src/examples/illucat/Illucat.h | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/examples/illucat/Illucat.h b/src/examples/illucat/Illucat.h index 83d86f7..56c1678 100644 --- a/src/examples/illucat/Illucat.h +++ b/src/examples/illucat/Illucat.h @@ -11,8 +11,8 @@ using namespace std::placeholders; #define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0]) -enum PIXEL_MODES {RED = 0xFF0000, GREEN = 0x00FF00, YELLOW = 0xffff00, BLUE = 0x0000FF, ORANGE = 0xffa500}; -int CAT_MODES[] = {RED, GREEN, YELLOW, BLUE, ORANGE}; +enum PIXEL_MODES {BLACK = 0x000000, RED = 0xFF0000, GREEN = 0x00FF00, YELLOW = 0xffff00, BLUE = 0x0000FF, ORANGE = 0xffa500}; +int CAT_MODES[] = {BLACK, RED, GREEN, YELLOW, BLUE, ORANGE}; struct NeoPixelConfig { int pin; @@ -25,6 +25,7 @@ class Illucat : public Sprocket { MeshNet* net; NeoPattern* pixels; int currentMode; + Illucat(SprocketConfig cfg, NeoPixelConfig pixelCfg) : Sprocket(cfg) { pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800, [](int pixels){}); pixels->begin(); @@ -38,15 +39,24 @@ class Illucat : public Sprocket { void messageReceived( uint32_t from, String &msg ) { Serial.printf("illucat: received from %u msg=%s\n", from, msg.c_str()); - changeMode(msg.c_str()); + StaticJsonBuffer<200> jsonBuffer; + JsonObject& root = jsonBuffer.parseObject(msg); + if (!root.success()) { + Serial.println("parseObject() failed"); + return; + } + changeMode(root["severity"]); + /* if(root["action"] == "pressed") { + } + if(root["action"] == "dial") { + changeMode("0"); + } */ } void changeMode(const char *mode){ currentMode = atoi(mode); Serial.println(currentMode); - //if(ARRAY_LENGTH(CAT_MODES) >= (int) mode){ - pixels->ColorSet(CAT_MODES[currentMode]); - pixels->show(); - //} + pixels->ColorSet(CAT_MODES[currentMode]); + pixels->show(); } void setHexColor(const char *hex){ int r, g, b;