From 816963240d86ec993998d619e83e2dee3f327f37 Mon Sep 17 00:00:00 2001 From: Patrick Balsiger Date: Sat, 17 Nov 2018 11:20:24 +0100 Subject: [PATCH] combined example --- platformio.ini | 13 +++++++++- src/examples/combined/config.h | 31 ++++++++++++++++++++++ src/examples/combined/main.cpp | 44 ++++++++++++++++++++++++++++++++ src/examples/rotary/main.cpp | 2 +- src/inputs/rotary/RotaryPlugin.h | 4 +-- 5 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 src/examples/combined/config.h create mode 100644 src/examples/combined/main.cpp diff --git a/platformio.ini b/platformio.ini index 3d95f09..f6c16d7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -47,4 +47,15 @@ upload_speed = ${common.upload_speed} monitor_baud = ${common.monitor_baud} src_filter = +<*> - + - + lib_deps = ${common.lib_deps} - Ai Esp32 Rotary Encoder \ No newline at end of file + Ai Esp32 Rotary Encoder + +[env:combined_esp32] +platform = espressif32 +board = esp32dev +framework = ${common.framework} +build_flags = -std=c++14 +upload_speed = ${common.upload_speed} +monitor_baud = ${common.monitor_baud} +src_filter = +<*> + + - + +lib_deps = ${common.lib_deps} + Ai Esp32 Rotary Encoder \ No newline at end of file diff --git a/src/examples/combined/config.h b/src/examples/combined/config.h new file mode 100644 index 0000000..588bb89 --- /dev/null +++ b/src/examples/combined/config.h @@ -0,0 +1,31 @@ +#ifndef __DEVICE_CONFIG__ +#define __DEVICE_CONFIG__ + +// Scheduler +#define _TASK_SLEEP_ON_IDLE_RUN +#define _TASK_STD_FUNCTION +#define _TASK_PRIORITY + +// Chip +#define SPROCKET_TYPE "SPROCKET" +#define SERIAL_BAUD_RATE 115200 +#define STARTUP_DELAY 1000 + +/* +connecting Rotary encoder +CLK (A pin) - to any microcontroler intput pin with interrupt +DT (B pin) - to any microcontroler intput pin with interrupt +SW (button pin) - to any microcontroler intput pin +VCC - to microcontroler VCC (then set ROTARY_ENCODER_VCC_PIN -1) +GND - to microcontroler GND +*/ +#define ROTARY_ENCODER_A_PIN 35 +#define ROTARY_ENCODER_B_PIN 34 +#define ROTARY_ENCODER_BUTTON_PIN 21 +#define ROTARY_ENCODER_VCC_PIN -1 /*put -1 of Rotary encoder Vcc is connected directly to 3,3V; else you can use declared output pin for powering rotary encoder */ + +// Pot +#define POT_THRESHOLD 16 +#define POT_POLL_INTERVAL 50 + +#endif \ No newline at end of file diff --git a/src/examples/combined/main.cpp b/src/examples/combined/main.cpp new file mode 100644 index 0000000..58b2178 --- /dev/null +++ b/src/examples/combined/main.cpp @@ -0,0 +1,44 @@ +#include "config.h" +#include "Sprocket.h" +#include "inputs/rotary/RotaryPlugin.h" +#include "inputs/pot/PotPlugin.h" + +Sprocket *sprocket; +RotaryPlugin *r1; +PotPlugin* p1; + +void addRotary(Sprocket *s, Plugin *r, const char *topic) +{ + String btnTopic = String(topic) + String("/button"); + s->subscribe(topic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, topic, _1)); + s->subscribe(btnTopic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, btnTopic, _1)); + s->addPlugin(r); +} + +void addPot(Sprocket* s, int pin, const char* topic) +{ + s->addPlugin( + new PotPlugin({pin, POT_THRESHOLD, POT_POLL_INTERVAL, topic})); + s->subscribe(topic, bind([](String label, String val){ + PRINT_MSG(Serial, label.c_str(), val.c_str()); + }, topic, _1)); +} + +void setup() +{ + sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE}); + r1 = new RotaryPlugin({35, 34, 21, -1, 50, 0, 255, true, "rotary1"}); + r1->rotaryEncoder->setup([] { r1->rotaryEncoder->readEncoder_ISR(); }); + addRotary(sprocket, r1, "rotary1"); + addPot(sprocket, 36, "pot1"); + addPot(sprocket, 37, "pot2"); + addPot(sprocket, 38, "pot3"); + addPot(sprocket, 39, "pot4"); + sprocket->activate(); +} + +void loop() +{ + sprocket->loop(); + yield(); +} \ No newline at end of file diff --git a/src/examples/rotary/main.cpp b/src/examples/rotary/main.cpp index 1e24da6..80bc6a4 100644 --- a/src/examples/rotary/main.cpp +++ b/src/examples/rotary/main.cpp @@ -8,9 +8,9 @@ RotaryPlugin *r1; void addRotary(Sprocket *s, Plugin *r, const char *topic) { String btnTopic = String(topic) + String("/button"); - s->addPlugin(r); s->subscribe(topic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, topic, _1)); s->subscribe(btnTopic, bind([](String label, String val) { PRINT_MSG(Serial, label.c_str(), val.c_str()); }, btnTopic, _1)); + s->addPlugin(r); } void setup() diff --git a/src/inputs/rotary/RotaryPlugin.h b/src/inputs/rotary/RotaryPlugin.h index 463e66f..54add89 100644 --- a/src/inputs/rotary/RotaryPlugin.h +++ b/src/inputs/rotary/RotaryPlugin.h @@ -1,5 +1,5 @@ -#ifndef __POT_PLUGIN_H__ -#define __POT_PLUGIN_H__ +#ifndef __ROTARY_PLUGIN_H__ +#define __ROTARY_PLUGIN_H__ #define _TASK_SLEEP_ON_IDLE_RUN #define _TASK_STD_FUNCTION