add button event

This commit is contained in:
2018-11-17 04:33:38 +01:00
parent 1241124ae5
commit f977ca570e
3 changed files with 10 additions and 10 deletions

View File

@@ -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();
}

View File

@@ -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));
}
}

View File

@@ -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);