button sprocket yey

This commit is contained in:
2018-06-29 22:48:36 +02:00
parent 492d7f70a9
commit 803a84c20f
3 changed files with 22 additions and 11 deletions

View File

@@ -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
Adafruit NeoPixel
[env:button]
src_filter = +<*> -<examples/> -<firmware/> +<examples/button/>
platform = ${common.platform}
board = ${common.board}
upload_speed = ${common.upload_speed}
monitor_baud = ${common.monitor_baud}
framework = ${common.framework}
lib_deps = ${common.lib_deps}

View File

@@ -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<MeshNet*>(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);

View File

@@ -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);