From 803a84c20f980047db472f3ea9d4ea074befd9fa Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Fri, 29 Jun 2018 22:48:36 +0200 Subject: [PATCH] button sprocket yey --- platformio.ini | 13 +++++++++++-- src/examples/button/Button.h | 16 +++++++++------- src/examples/button/main.cpp | 4 ++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/platformio.ini b/platformio.ini index bb8fa86..972848a 100644 --- a/platformio.ini +++ b/platformio.ini @@ -9,7 +9,7 @@ ; http://docs.platformio.org/page/projectconf.html [platformio] -env_default = illucat +env_default = button [common] framework = arduino @@ -76,4 +76,13 @@ upload_speed = ${common.upload_speed} monitor_baud = ${common.monitor_baud} framework = ${common.framework} lib_deps = ${common.lib_deps} - Adafruit NeoPixel \ No newline at end of file + Adafruit NeoPixel + +[env:button] +src_filter = +<*> - - + +platform = ${common.platform} +board = ${common.board} +upload_speed = ${common.upload_speed} +monitor_baud = ${common.monitor_baud} +framework = ${common.framework} +lib_deps = ${common.lib_deps} \ No newline at end of file diff --git a/src/examples/button/Button.h b/src/examples/button/Button.h index a8fa611..f26d90a 100644 --- a/src/examples/button/Button.h +++ b/src/examples/button/Button.h @@ -13,25 +13,27 @@ class Button : public Sprocket { Task btnTask; MeshNet* net; int pin; - MeshApp(SprocketConfig cfg) : Sprocket(cfg) {} + Button(SprocketConfig cfg) : Sprocket(cfg) {} Sprocket* activate(Scheduler* scheduler, Network* network) { - pinMode(D2, INPUT_PULLUP); + pin = D2; + pinMode(pin, INPUT_PULLUP); net = static_cast(network); - net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2)); - someTask.set(TASK_MILLISECOND * 50, TASK_FOREVER, - bind(&MeshApp::readPin, this, net)); + net->mesh.onReceive(bind(&Button::receivedCallback,this, _1, _2)); + btnTask.set(TASK_MILLISECOND * 500, TASK_FOREVER, + bind(&Button::readPin, this, net)); scheduler->addTask(btnTask); btnTask.enable(); } using Sprocket::activate; void readPin(MeshNet* network){ if(digitalRead(pin)){ - network->broadcast("{ \"pressed \": 1 }"); + Serial.println("btn pressed"); + network->broadcast("EE1B2E"); } } void receivedCallback( uint32_t from, String &msg ) { - Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str()); + Serial.printf("button: Received from %u msg=%s\n", from, msg.c_str()); // respond in receive callback can cause an endless loop when all nodes run the same firmware //String foo = String("cheerz back to ") + String(from); //net->broadcast(foo); diff --git a/src/examples/button/main.cpp b/src/examples/button/main.cpp index 655fbbd..061f47f 100644 --- a/src/examples/button/main.cpp +++ b/src/examples/button/main.cpp @@ -1,6 +1,6 @@ #include "config.h" #include "MeshNet.h" -#include "MeshApp.h" +#include "Button.h" MeshNet net({ STATION_MODE, WIFI_CHANNEL, @@ -8,7 +8,7 @@ MeshNet net({ STATION_SSID, STATION_PASSWORD, HOSTNAME, MESH_DEBUG_TYPES }); -MeshApp sprocket({ STARTUP_DELAY, SERIAL_BAUD_RATE }); +Button sprocket({ STARTUP_DELAY, SERIAL_BAUD_RATE }); void setup() { sprocket.join(net);