mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 13:08:21 +01:00
parse json
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user