mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 05:24:30 +01:00
button sprocket yey
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
; http://docs.platformio.org/page/projectconf.html
|
; http://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
env_default = illucat
|
env_default = button
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
@@ -77,3 +77,12 @@ monitor_baud = ${common.monitor_baud}
|
|||||||
framework = ${common.framework}
|
framework = ${common.framework}
|
||||||
lib_deps = ${common.lib_deps}
|
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;
|
Task btnTask;
|
||||||
MeshNet* net;
|
MeshNet* net;
|
||||||
int pin;
|
int pin;
|
||||||
MeshApp(SprocketConfig cfg) : Sprocket(cfg) {}
|
Button(SprocketConfig cfg) : Sprocket(cfg) {}
|
||||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||||
pinMode(D2, INPUT_PULLUP);
|
pin = D2;
|
||||||
|
pinMode(pin, INPUT_PULLUP);
|
||||||
net = static_cast<MeshNet*>(network);
|
net = static_cast<MeshNet*>(network);
|
||||||
net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2));
|
net->mesh.onReceive(bind(&Button::receivedCallback,this, _1, _2));
|
||||||
someTask.set(TASK_MILLISECOND * 50, TASK_FOREVER,
|
btnTask.set(TASK_MILLISECOND * 500, TASK_FOREVER,
|
||||||
bind(&MeshApp::readPin, this, net));
|
bind(&Button::readPin, this, net));
|
||||||
scheduler->addTask(btnTask);
|
scheduler->addTask(btnTask);
|
||||||
btnTask.enable();
|
btnTask.enable();
|
||||||
} using Sprocket::activate;
|
} using Sprocket::activate;
|
||||||
|
|
||||||
void readPin(MeshNet* network){
|
void readPin(MeshNet* network){
|
||||||
if(digitalRead(pin)){
|
if(digitalRead(pin)){
|
||||||
network->broadcast("{ \"pressed \": 1 }");
|
Serial.println("btn pressed");
|
||||||
|
network->broadcast("EE1B2E");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void receivedCallback( uint32_t from, String &msg ) {
|
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
|
// respond in receive callback can cause an endless loop when all nodes run the same firmware
|
||||||
//String foo = String("cheerz back to ") + String(from);
|
//String foo = String("cheerz back to ") + String(from);
|
||||||
//net->broadcast(foo);
|
//net->broadcast(foo);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "MeshNet.h"
|
#include "MeshNet.h"
|
||||||
#include "MeshApp.h"
|
#include "Button.h"
|
||||||
|
|
||||||
MeshNet net({
|
MeshNet net({
|
||||||
STATION_MODE, WIFI_CHANNEL,
|
STATION_MODE, WIFI_CHANNEL,
|
||||||
@@ -8,7 +8,7 @@ MeshNet net({
|
|||||||
STATION_SSID, STATION_PASSWORD, HOSTNAME,
|
STATION_SSID, STATION_PASSWORD, HOSTNAME,
|
||||||
MESH_DEBUG_TYPES
|
MESH_DEBUG_TYPES
|
||||||
});
|
});
|
||||||
MeshApp sprocket({ STARTUP_DELAY, SERIAL_BAUD_RATE });
|
Button sprocket({ STARTUP_DELAY, SERIAL_BAUD_RATE });
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
sprocket.join(net);
|
sprocket.join(net);
|
||||||
|
|||||||
Reference in New Issue
Block a user