mirror of
https://gitlab.com/wirelos/sprocket-plugin-gpio.git
synced 2025-12-14 13:26:48 +01:00
rename pot to analog as it is quite a generic way to read the input
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
;[platformio]
|
||||
;env_default = Pot, Pot_esp32
|
||||
;env_default = analog
|
||||
|
||||
[common]
|
||||
framework = arduino
|
||||
@@ -15,25 +15,25 @@ lib_deps =
|
||||
https://gitlab.com/wirelos/sprocket-lib.git#develop
|
||||
|
||||
|
||||
[env:pot]
|
||||
[env:analog]
|
||||
platform = ${common.platform}
|
||||
board = ${common.board}
|
||||
framework = ${common.framework}
|
||||
upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> -<examples/> +<examples/pot/> -<inputs/> +<inputs/pot>
|
||||
src_filter = +<*> -<examples/> +<examples/analog/> -<inputs/> +<inputs/analog>
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore =
|
||||
Ai Esp32 Rotary Encoder
|
||||
|
||||
[env:pot_esp32]
|
||||
[env:analog_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 = +<*> -<examples/> +<examples/pot/> -<inputs/> +<inputs/pot>
|
||||
src_filter = +<*> -<examples/> +<examples/analog/> -<inputs/> +<inputs/analog>
|
||||
lib_deps = ${common.lib_deps}
|
||||
lib_ignore =
|
||||
Ai Esp32 Rotary Encoder
|
||||
@@ -56,6 +56,6 @@ framework = ${common.framework}
|
||||
build_flags = -std=c++14
|
||||
upload_speed = ${common.upload_speed}
|
||||
monitor_baud = ${common.monitor_baud}
|
||||
src_filter = +<*> +<inputs/pot> +<inputs/rotary> -<examples/> +<examples/combined/>
|
||||
src_filter = +<*> +<inputs/analog> +<inputs/rotary> -<examples/> +<examples/combined/>
|
||||
lib_deps = ${common.lib_deps}
|
||||
Ai Esp32 Rotary Encoder
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "config.h"
|
||||
#include "Sprocket.h"
|
||||
#include "inputs/pot/PotPlugin.h"
|
||||
#include "inputs/analog/AnalogInputPlugin.h"
|
||||
|
||||
Sprocket *sprocket;
|
||||
|
||||
void registerPot(Sprocket* s, int pin, const char* topic)
|
||||
{
|
||||
s->addPlugin(
|
||||
new PotPlugin({pin, POT_THRESHOLD, POT_POLL_INTERVAL, topic}));
|
||||
new AnalogInputPlugin({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));
|
||||
@@ -1,11 +1,11 @@
|
||||
#include "config.h"
|
||||
#include "Sprocket.h"
|
||||
#include "inputs/rotary/RotaryPlugin.h"
|
||||
#include "inputs/pot/PotPlugin.h"
|
||||
#include "inputs/analog/AnalogInputPlugin.h"
|
||||
|
||||
Sprocket *sprocket;
|
||||
RotaryPlugin *r1;
|
||||
PotPlugin* p1;
|
||||
AnalogInputPlugin* p1;
|
||||
|
||||
void addRotary(Sprocket *s, Plugin *r, const char *topic)
|
||||
{
|
||||
@@ -15,13 +15,12 @@ void addRotary(Sprocket *s, Plugin *r, const char *topic)
|
||||
s->addPlugin(r);
|
||||
}
|
||||
|
||||
void addPot(Sprocket* s, int pin, const char* topic)
|
||||
void addAnalogInput(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));
|
||||
s->addPlugin(new AnalogInputPlugin({pin, POT_THRESHOLD, POT_POLL_INTERVAL, topic}));
|
||||
}
|
||||
|
||||
void setup()
|
||||
@@ -30,10 +29,10 @@ void setup()
|
||||
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");
|
||||
addAnalogInput(sprocket, 36, "pot1");
|
||||
addAnalogInput(sprocket, 37, "pot2");
|
||||
addAnalogInput(sprocket, 38, "pot3");
|
||||
addAnalogInput(sprocket, 39, "pot4");
|
||||
sprocket->activate();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
#include "PotPlugin.h"
|
||||
#include "AnalogInputPlugin.h"
|
||||
|
||||
PotPlugin::PotPlugin(GpioConfig cfg){
|
||||
AnalogInputPlugin::AnalogInputPlugin(GpioConfig cfg){
|
||||
config = cfg;
|
||||
}
|
||||
void PotPlugin::activate(Scheduler *userScheduler)
|
||||
void AnalogInputPlugin::activate(Scheduler *userScheduler)
|
||||
{
|
||||
inputTask.set(TASK_MILLISECOND * config.updateInterval, TASK_FOREVER, std::bind(&PotPlugin::checkInput, this));
|
||||
inputTask.set(TASK_MILLISECOND * config.updateInterval, TASK_FOREVER, std::bind(&AnalogInputPlugin::checkInput, this));
|
||||
userScheduler->addTask(inputTask);
|
||||
inputTask.enable();
|
||||
PRINT_MSG(Serial, "PLUGIN", "PotPlugin activated");
|
||||
PRINT_MSG(Serial, "PLUGIN", "AnalogInputPlugin activated");
|
||||
}
|
||||
|
||||
void PotPlugin::checkInput()
|
||||
void AnalogInputPlugin::checkInput()
|
||||
{
|
||||
// FIXME add range and threashold to config
|
||||
int newVal = analogRead(config.pin);
|
||||
if ((newVal >= currentVal + config.threshold || newVal <= currentVal - config.threshold))
|
||||
{
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef __POT_PLUGIN_H__
|
||||
#define __POT_PLUGIN_H__
|
||||
#ifndef __ANALOG_INPUT__PLUGIN_H__
|
||||
#define __ANALOG_INPUT__PLUGIN_H__
|
||||
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
@@ -16,12 +16,12 @@
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
class PotPlugin : public Plugin {
|
||||
class AnalogInputPlugin : public Plugin {
|
||||
public:
|
||||
Task inputTask;
|
||||
int currentVal = 0;
|
||||
GpioConfig config;
|
||||
PotPlugin(GpioConfig cfg);
|
||||
AnalogInputPlugin(GpioConfig cfg);
|
||||
void activate(Scheduler* userScheduler);
|
||||
void checkInput();
|
||||
};
|
||||
Reference in New Issue
Block a user