moar topics

This commit is contained in:
2018-09-17 15:34:24 +02:00
parent 939f167dad
commit ad8ba61986
7 changed files with 91 additions and 12 deletions

View File

@@ -9,6 +9,10 @@
"array": "cpp", "array": "cpp",
"initializer_list": "cpp", "initializer_list": "cpp",
"*.tcc": "cpp", "*.tcc": "cpp",
"sstream": "cpp" "sstream": "cpp",
"deque": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"vector": "cpp"
} }
} }

View File

@@ -11,6 +11,10 @@
- [20%] easy to flash single binary file - [20%] easy to flash single binary file
- [0%] audio output - [0%] audio output
## Bugs
- when new connections arrive, it somehow switches to defaultAnimation
- animations don't seem to work properly anymore
## Enduser Setup ## Enduser Setup
1. Scan for access points 1. Scan for access points
1. connect to illucat-mesh 1. connect to illucat-mesh

View File

@@ -30,11 +30,12 @@ class NeoPattern : public Adafruit_NeoPixel
pattern ActivePattern; // which pattern is running pattern ActivePattern; // which pattern is running
direction Direction; // direction to run the pattern direction Direction; // direction to run the pattern
unsigned long Interval; // milliseconds between updates unsigned long Interval = 150; // milliseconds between updates
unsigned long lastUpdate; // last update of position unsigned long lastUpdate = 0; // last update of position
uint32_t Color1, Color2; // What colors are in use uint32_t Color1 = 0;
uint16_t TotalSteps; // total number of steps in the pattern uint32_t Color2 = 0; // What colors are in use
uint16_t TotalSteps = 255; // total number of steps in the pattern
uint16_t Index; // current step within the pattern uint16_t Index; // current step within the pattern
uint16_t completed = 0; uint16_t completed = 0;
@@ -45,19 +46,20 @@ class NeoPattern : public Adafruit_NeoPixel
:Adafruit_NeoPixel(pixels, pin, type) :Adafruit_NeoPixel(pixels, pin, type)
{ {
OnComplete = callback; OnComplete = callback;
TotalSteps = numPixels();
} }
NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type) NeoPattern(uint16_t pixels, uint8_t pin, uint8_t type)
:Adafruit_NeoPixel(pixels, pin, type) :Adafruit_NeoPixel(pixels, pin, type)
{ {
TotalSteps = numPixels();
} }
void onCompleteDefault(int pixels) { void onCompleteDefault(int pixels) {
if(ActivePattern != RAINBOW_CYCLE){ if(ActivePattern != RAINBOW_CYCLE){
//Serial.println("reversing"); //Serial.println("reversing");
Reverse();
} }
Reverse();
//Serial.println("pattern completed"); //Serial.println("pattern completed");
} }

View File

@@ -32,6 +32,38 @@ struct NeoPixelConfig : public JsonStruct {
} }
}; };
struct NeoPatternMsg : public JsonStruct {
String pattern;
String payload;
String topic;
uint color;
uint color2;
uint totalSteps;
void mapJsonObject(JsonObject& root) {
root["topic"] = topic;
root["pattern"] = pattern;
root["payload"] = payload;
root["color"] = color;
root["color2"] = color2;
root["totalSteps"] = totalSteps;
}
// Map a json object to this struct.
void fromJsonObject(JsonObject& json){
if(!verifyJsonObject(json)){
PRINT_MSG(Serial, "fromJsonObject", "cannot parse JSON");
valid = 0;
return;
}
topic = getAttrFromJson(json, "topic");
color = getIntAttrFromJson(json, "color");
color2 = getIntAttrFromJson(json, "color2");
pattern = getAttrFromJson(json, "pattern");
payload = getAttrFromJson(json, "payload");
totalSteps = getIntAttrFromJson(json, "totalSteps", 255);
valid = 1;
};
};
struct NeoPatternDto : public JsonStruct { struct NeoPatternDto : public JsonStruct {
uint mode; uint mode;
uint value; uint value;
@@ -51,12 +83,14 @@ struct NeoPatternDto : public JsonStruct {
void fromJsonObject(JsonObject& json){ void fromJsonObject(JsonObject& json){
if(!verifyJsonObject(json)){ if(!verifyJsonObject(json)){
PRINT_MSG(Serial, "fromJsonObject", "cannot parse JSON"); PRINT_MSG(Serial, "fromJsonObject", "cannot parse JSON");
valid = 0;
return; return;
} }
mode = atoi(json[JSON_MODE_NODE]); mode = atoi(json[JSON_MODE_NODE]);
mode = mode < ARRAY_LENGTH(PIXEL_FNCS) ? mode : 0; mode = mode < ARRAY_LENGTH(PIXEL_FNCS) ? mode : 0;
value = json[JSON_VALUE]; value = json[JSON_VALUE];
valueStr = json[JSON_VALUE]; valueStr = json[JSON_VALUE];
valid = 1;
}; };
}; };

View File

@@ -39,4 +39,4 @@ lib_deps = ${common.lib_deps}
ESPAsyncTCP ESPAsyncTCP
Adafruit NeoPixel Adafruit NeoPixel
DNSServer DNSServer
https://gitlab.com/wirelos/sprocket-core.git#develop https://gitlab.com/wirelos/sprocket-core.git#mediator

View File

@@ -53,6 +53,7 @@ class IlluCat : public MeshSprocket {
pixelConfig.defaultColor = 100; pixelConfig.defaultColor = 100;
} }
// TDOO remove
virtual void scanningAnimation() { virtual void scanningAnimation() {
pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval); pixels->Scanner(pixels->Wheel(COLOR_NOT_CONNECTED), pixelConfig.updateInterval);
//pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD); //pixels->Fade(0, pixels->Color(255,255,255), 4, pixelConfig.updateInterval, FORWARD);
@@ -97,7 +98,8 @@ class IlluCat : public MeshSprocket {
server->addHandler(ws); server->addHandler(ws);
// FIXME OnDisable is triggered after last scan, aprx. 10 sec // FIXME OnDisable is triggered after last scan, aprx. 10 sec
net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this)); // FIXME chck if this is also triggered when new connection arrives
//net->mesh.stationScan.task.setOnDisable(bind(&IlluCat::defaultAnimation,this));
return MeshSprocket::activate(scheduler, network); return MeshSprocket::activate(scheduler, network);
} using MeshSprocket::activate; } using MeshSprocket::activate;
@@ -113,9 +115,15 @@ class IlluCat : public MeshSprocket {
virtual void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) { virtual void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len) {
if(type == WS_EVT_DATA){ if(type == WS_EVT_DATA){
String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0); String frame = WsUtils::parseFrameAsString(type, arg, data, len, 0);
onMessage(0, frame); //onMessage(0, frame);
net->mesh.sendBroadcast(frame); NeoPatternMsg msg;
client->text(String(millis())); msg.fromJsonString(frame);
if(msg.valid){
// TODO convert message to send to mesh
//net->mesh.sendBroadcast(frame);
publish(msg.topic, msg.payload);
client->text(String(millis()));
}
} }
} }

View File

@@ -26,11 +26,38 @@ class PixelPlugin : public Plugin {
pixels->setBrightness(pixelConfig.brightness); pixels->setBrightness(pixelConfig.brightness);
} }
void activate(Scheduler* userScheduler, Network* network){ void activate(Scheduler* userScheduler, Network* network){
subscribe("pixels/color", bind(&PixelPlugin::setColor, this, _1));
subscribe("pixels/color2", bind(&PixelPlugin::setColor2, this, _1));
subscribe("pixels/pattern", bind(&PixelPlugin::setPattern, this, _1));
subscribe("pixels/totalSteps", bind(&PixelPlugin::setTotalSteps, this, _1));
subscribe("pixels/brightness", bind(&PixelPlugin::setBrightness, this, _1));
animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this)); animation.set(TASK_MILLISECOND * pixelConfig.updateInterval, TASK_FOREVER, bind(&PixelPlugin::animate, this));
userScheduler->addTask(animation); userScheduler->addTask(animation);
animation.enable(); animation.enable();
Serial.println("NeoPixels activated"); Serial.println("NeoPixels activated");
} }
void setTotalSteps(String msg){
pixels->TotalSteps = atoi(msg.c_str());
}
void setBrightness(String msg){
int inVal = atoi(msg.c_str());
pixels->setBrightness(inVal);
pixels->show();
}
void setColor(String msg){
pixels->Color1 = atoi(msg.c_str());
if(pixels->ActivePattern == NONE){
pixels->ColorSet(pixels->Color1);
}
}
void setColor2(String msg){
pixels->Color2 = atoi(msg.c_str());
}
void setPattern(String msg){
pixels->Index = 0;
pixels->ActivePattern = (pattern)atoi(msg.c_str());
}
void animate(){ void animate(){
pixels->Update(); pixels->Update();
} }