Added TableSoccer as esphome... It's finally no longer an ill-configure Homie
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
#include "esphome.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace tablesoccer_helper {
|
||||
|
||||
class BtnHelperClass : public Component, public mqtt::CustomMQTTDevice {
|
||||
protected:
|
||||
|
||||
InternalGPIOPin *resetBtn;
|
||||
InternalGPIOPin *undoBtn;
|
||||
gpio::GPIOBinaryOutput *keep_alive;
|
||||
unsigned long lastThingDone = 0;
|
||||
unsigned long enableFrom = 0;
|
||||
|
||||
public:
|
||||
|
||||
void set_reset_pin(InternalGPIOPin *resetBtn){
|
||||
this->resetBtn = resetBtn;
|
||||
}
|
||||
void set_undo_pin(InternalGPIOPin *undoBtn){
|
||||
this->undoBtn = undoBtn;
|
||||
}
|
||||
void set_keep_alive_output(gpio::GPIOBinaryOutput *keep_alive){
|
||||
this->keep_alive = keep_alive;
|
||||
}
|
||||
|
||||
void setup() override {
|
||||
lastThingDone = millis();
|
||||
enableFrom = millis();
|
||||
|
||||
ESP_LOGD("Tablesoccer", "Ready");
|
||||
}
|
||||
|
||||
void reset_last_thing_done(){
|
||||
lastThingDone = millis();
|
||||
}
|
||||
|
||||
void send_score(std::string side){
|
||||
publish("tabletenniscounter/control/score/count", side, 2, false);
|
||||
lastThingDone = millis();
|
||||
enableFrom = lastThingDone + 200;
|
||||
}
|
||||
|
||||
void loop() override{
|
||||
|
||||
if(millis() < enableFrom) return;
|
||||
|
||||
if(resetBtn->digital_read() == LOW && undoBtn->digital_read() == LOW){
|
||||
ESP_LOGD("Tablesoccer", "User requested shutdown, Shutting Down.");
|
||||
keep_alive->set_state(false);
|
||||
}
|
||||
if(resetBtn->digital_read() == LOW){
|
||||
|
||||
publish("tabletenniscounter/control/score/reset", "", 2, false);
|
||||
|
||||
lastThingDone = millis();
|
||||
enableFrom = lastThingDone + 500;
|
||||
}
|
||||
else if(undoBtn->digital_read() == LOW){
|
||||
publish("tabletenniscounter/control/score/undo", "", 2, false);
|
||||
lastThingDone = millis();
|
||||
enableFrom = lastThingDone + 500;
|
||||
}
|
||||
else if((millis() - lastThingDone) >= 300000){
|
||||
ESP_LOGD("Tablesoccer", "Table soccer table has't been used in over 15 minutes, Shutting Down.");
|
||||
keep_alive->set_state(false);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user