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