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