Handle button presses
This commit is contained in:
parent
a563cc45b5
commit
b753d9f8ea
12
README.md
12
README.md
@ -2,13 +2,19 @@
|
||||
|
||||
## TODO
|
||||
|
||||
### Server
|
||||
|
||||
- [x] Use timeout for fetching departures
|
||||
- [x] Add basic auth
|
||||
- [x] Create Nix package
|
||||
- [x] Create container
|
||||
- [x] Write ESP8266 client
|
||||
- [ ] Make port configurable
|
||||
- [x] Transfer using JSON
|
||||
- [x] Correctly implement basic auth
|
||||
- [ ] Use unidecode to replace non-ascii stuff in the backend
|
||||
- [ ] Make port configurable
|
||||
- [ ] Use unidecode to replace non-ascii stuff
|
||||
- [ ] Add query parameter for selecting EFAClient
|
||||
|
||||
### Client
|
||||
|
||||
- [x] Write ESP8266 client
|
||||
- [x] Add code for handling button presses
|
||||
|
@ -61,8 +61,12 @@ Adafruit_ST7735 display(TFT_CS, TFT_DC, TFT_RESET);
|
||||
|
||||
class State {
|
||||
public:
|
||||
virtual void enter() = 0;
|
||||
virtual void tick() = 0;
|
||||
// When the state is entered
|
||||
virtual void enter();
|
||||
// Called in the business loop
|
||||
virtual void tick();
|
||||
// Called when the button is pushed
|
||||
virtual void button();
|
||||
virtual ~State() = default;
|
||||
};
|
||||
|
||||
@ -75,7 +79,6 @@ public:
|
||||
class StateFetching : public State {
|
||||
public:
|
||||
void enter() override;
|
||||
void tick() override;
|
||||
};
|
||||
|
||||
class StateShowingDepartures : public State {
|
||||
@ -87,8 +90,15 @@ public:
|
||||
StateShowingDepartures(String&);
|
||||
void enter() override;
|
||||
void tick() override;
|
||||
void button() override;
|
||||
};
|
||||
|
||||
// Empty default implementations
|
||||
|
||||
void State::enter() {}
|
||||
void State::tick() {}
|
||||
void State::button() {}
|
||||
|
||||
// App state implementation
|
||||
|
||||
uint64_t currentTick = 0;
|
||||
@ -143,9 +153,6 @@ void StateFetching::enter() {
|
||||
setState<StateShowingDepartures>(departuresRaw);
|
||||
};
|
||||
|
||||
void StateFetching::tick() {
|
||||
}
|
||||
|
||||
StateShowingDepartures::StateShowingDepartures(String &departuresRaw) {
|
||||
deserializeJson(departures, departuresRaw);
|
||||
}
|
||||
@ -154,9 +161,11 @@ void StateShowingDepartures::enter() {
|
||||
Serial.println("Entering StateShowingDepartures");
|
||||
entered = millis();
|
||||
|
||||
// clear status and main areas
|
||||
display.fillRect(STATUS_X, STATUS_Y, STATUS_WIDTH, STATUS_HEIGHT, COLOR_BG);
|
||||
display.fillRect(MAIN_X, MAIN_Y, MAIN_WIDTH, MAIN_HEIGHT, COLOR_BG);
|
||||
|
||||
// draw timetable
|
||||
int line = 0;
|
||||
for (JsonVariant departure : departures["departures"].as<JsonArray>()) {
|
||||
display.setCursor(MAIN_X, MAIN_Y + (CY + 3) * line);
|
||||
@ -183,6 +192,10 @@ void StateShowingDepartures::tick() {
|
||||
}
|
||||
}
|
||||
|
||||
void StateShowingDepartures::button() {
|
||||
setState<StateFetching>();
|
||||
}
|
||||
|
||||
int buttonPushed = false;
|
||||
|
||||
void ICACHE_RAM_ATTR onButtonFalling() {
|
||||
@ -218,6 +231,9 @@ void loop() {
|
||||
stateChanged = false;
|
||||
// Note: enter() may call setState(). In that case we want to end up right back here.
|
||||
state->enter();
|
||||
} else if (buttonPushed) {
|
||||
buttonPushed = false;
|
||||
state->button();
|
||||
} else {
|
||||
state->tick();
|
||||
currentTick++;
|
||||
|
Loading…
x
Reference in New Issue
Block a user