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..38452ea 100644 --- a/src/examples/button/Button.h +++ b/src/examples/button/Button.h @@ -13,13 +13,15 @@ class Button : public Sprocket { Task btnTask; MeshNet* net; int pin; + int warnlevel = 0; + int cycleEnd = 5; 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 +29,10 @@ class Button : public Sprocket { void readPin(MeshNet* network){ if(digitalRead(pin)){ - Serial.println("btn pressed"); - network->broadcast("EE1B2E"); + 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 0991f6c..56c1678 100644 --- a/src/examples/illucat/Illucat.h +++ b/src/examples/illucat/Illucat.h @@ -9,17 +9,27 @@ using namespace std; using namespace std::placeholders; +#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0]) + +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; int length; + int mode; }; 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(); + pixels->setBrightness(64); } Sprocket* activate(Scheduler* scheduler, Network* network) { net = static_cast(network); @@ -29,7 +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()); - setHexColor(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); + pixels->ColorSet(CAT_MODES[currentMode]); + pixels->show(); } void setHexColor(const char *hex){ int r, g, b;