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

View File

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

View File

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