mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-15 21:18: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])
|
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
|
||||||
|
|
||||||
enum PIXEL_MODES {RED = 0xFF0000, GREEN = 0x00FF00, YELLOW = 0xffff00, BLUE = 0x0000FF, ORANGE = 0xffa500};
|
enum PIXEL_MODES {BLACK = 0x000000, RED = 0xFF0000, GREEN = 0x00FF00, YELLOW = 0xffff00, BLUE = 0x0000FF, ORANGE = 0xffa500};
|
||||||
int CAT_MODES[] = {RED, GREEN, YELLOW, BLUE, ORANGE};
|
int CAT_MODES[] = {BLACK, RED, GREEN, YELLOW, BLUE, ORANGE};
|
||||||
|
|
||||||
struct NeoPixelConfig {
|
struct NeoPixelConfig {
|
||||||
int pin;
|
int pin;
|
||||||
@@ -25,6 +25,7 @@ class Illucat : public Sprocket {
|
|||||||
MeshNet* net;
|
MeshNet* net;
|
||||||
NeoPattern* pixels;
|
NeoPattern* pixels;
|
||||||
int currentMode;
|
int currentMode;
|
||||||
|
|
||||||
Illucat(SprocketConfig cfg, NeoPixelConfig pixelCfg) : Sprocket(cfg) {
|
Illucat(SprocketConfig cfg, NeoPixelConfig pixelCfg) : Sprocket(cfg) {
|
||||||
pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800, [](int pixels){});
|
pixels = new NeoPattern(pixelCfg.length, pixelCfg.pin, NEO_GRB + NEO_KHZ800, [](int pixels){});
|
||||||
pixels->begin();
|
pixels->begin();
|
||||||
@@ -38,15 +39,24 @@ class Illucat : public Sprocket {
|
|||||||
|
|
||||||
void messageReceived( uint32_t from, String &msg ) {
|
void messageReceived( uint32_t from, String &msg ) {
|
||||||
Serial.printf("illucat: received from %u msg=%s\n", from, msg.c_str());
|
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){
|
void changeMode(const char *mode){
|
||||||
currentMode = atoi(mode);
|
currentMode = atoi(mode);
|
||||||
Serial.println(currentMode);
|
Serial.println(currentMode);
|
||||||
//if(ARRAY_LENGTH(CAT_MODES) >= (int) mode){
|
pixels->ColorSet(CAT_MODES[currentMode]);
|
||||||
pixels->ColorSet(CAT_MODES[currentMode]);
|
pixels->show();
|
||||||
pixels->show();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
void setHexColor(const char *hex){
|
void setHexColor(const char *hex){
|
||||||
int r, g, b;
|
int r, g, b;
|
||||||
|
|||||||
Reference in New Issue
Block a user