mirror of
https://gitlab.com/wirelos/sprocket-plugin-gpio.git
synced 2025-12-14 05:16:50 +01:00
add button event
This commit is contained in:
@@ -5,20 +5,20 @@
|
||||
Sprocket *sprocket;
|
||||
RotaryPlugin *r1;
|
||||
|
||||
void registerPlugin(Sprocket *s, Plugin *r, const char *topic)
|
||||
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));
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
sprocket = new Sprocket({STARTUP_DELAY, SERIAL_BAUD_RATE});
|
||||
//r1 = new RotaryPlugin({35, 34, 21, -1, 50, 0, 255, true, "rotary1_enc", "rotary1_btn"});
|
||||
r1 = new RotaryPlugin({35, 34, 21, -1, 50, 0, 255, true, "rotary1"});
|
||||
r1->rotaryEncoder->setup([] { r1->rotaryEncoder->readEncoder_ISR(); });
|
||||
|
||||
registerPlugin(sprocket, r1, "rotary1");
|
||||
addRotary(sprocket, r1, "rotary1");
|
||||
sprocket->activate();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,9 +24,9 @@ void RotaryPlugin::checkInput()
|
||||
int encReading = rotaryEncoder->readEncoder();
|
||||
publish(config.topic, String(encReading));
|
||||
}
|
||||
//ButtonState newBtnState = rotaryEncoder->currentButtonState();
|
||||
//if(newBtnState != btnState){
|
||||
// btnState = newBtnState;
|
||||
// publish(config.topicButton, String(btnState));
|
||||
//}
|
||||
ButtonState newBtnState = rotaryEncoder->currentButtonState();
|
||||
if(newBtnState != btnState){
|
||||
btnState = newBtnState;
|
||||
publish(String(config.topic) + String("/button"), String(btnState));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class RotaryPlugin : public Plugin {
|
||||
public:
|
||||
Task inputTask;
|
||||
int currentVal = 0;
|
||||
//ButtonState btnState = BUT_RELEASED;
|
||||
ButtonState btnState = BUT_RELEASED;
|
||||
AiEsp32RotaryEncoder* rotaryEncoder;
|
||||
RotaryConfig config;
|
||||
RotaryPlugin(RotaryConfig cfg);
|
||||
|
||||
Reference in New Issue
Block a user