fix screen logic
This commit is contained in:
parent
c7f62fd967
commit
42ced6346b
1 changed files with 26 additions and 18 deletions
44
main.ino
44
main.ino
|
@ -215,22 +215,34 @@ class DisplayConfig {
|
|||
tft.setRotation(1);
|
||||
tft.fillScreen(BACKGROUND_COLOUR);
|
||||
};
|
||||
Screen* applyScreen(int index){
|
||||
this->screenIndex = index;
|
||||
tft.fillScreen(BACKGROUND_COLOUR);
|
||||
return this->screens[index];
|
||||
};
|
||||
Screen* cycleScreen() {
|
||||
this->screenIndex = (this->screenIndex + 1) % this->screenCount;
|
||||
return this->applyScreen(this->screenIndex);
|
||||
|
||||
void setScreen(int i) {
|
||||
this->screenIndex = i;
|
||||
}
|
||||
|
||||
Screen* getCurrentScreen() {return this->screens[this->screenIndex];}
|
||||
Screen* getCurrentScreenIndex() {return this->screenIndex;}
|
||||
void applyScreen(int i){
|
||||
this->setScreen(i);
|
||||
this->drawScreen(i);
|
||||
};
|
||||
|
||||
void cycleScreen() {this->screenIndex = (this->screenIndex + 1) % this->screenCount;}
|
||||
|
||||
// Screen* getCurrentScreen() {return this->screens[this->screenIndex];}
|
||||
int getCurrentScreenIndex() {return this->screenIndex;}
|
||||
|
||||
void drawScreen(int i) {
|
||||
tft.fillScreen(BACKGROUND_COLOUR);
|
||||
this->screens[i]->draw();
|
||||
}
|
||||
|
||||
void drawCurrentScreen() {
|
||||
this->drawScreen(this->screenIndex);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
const byte DEBOUNCE_DELAY = 50;
|
||||
unsigned long previousMillis = -1000000000;
|
||||
unsigned long lastDebounceTime = 0;
|
||||
|
@ -254,8 +266,6 @@ Screen* screenBigHum;
|
|||
|
||||
DisplayConfig* config;
|
||||
|
||||
Screen* currentScreen;
|
||||
|
||||
void setup() {
|
||||
|
||||
// Datapoint storage. Arguments: Unit, amount of datapoints to be saved.
|
||||
|
@ -293,8 +303,6 @@ void setup() {
|
|||
Serial.begin(115200);
|
||||
Serial.println(F("Serial started."));
|
||||
|
||||
currentScreen = config->getCurrentScreen();
|
||||
|
||||
pinMode(buttonPin, INPUT);
|
||||
|
||||
Wire.begin();
|
||||
|
@ -310,7 +318,7 @@ void setup() {
|
|||
void loop() {
|
||||
unsigned long currentMillis = millis();
|
||||
if (sht3xErrorLastCycle) {
|
||||
config->applyScreen(config->getCurrentScreenIndex());
|
||||
config->drawCurrentScreen();
|
||||
sht3xErrorLastCycle = false;
|
||||
}
|
||||
if (currentMillis - previousMillis >= WAIT_TIME * 1000) {
|
||||
|
@ -323,7 +331,7 @@ void loop() {
|
|||
humData->addData(hum);
|
||||
|
||||
|
||||
currentScreen->draw();
|
||||
config->drawCurrentScreen();
|
||||
|
||||
Serial.print(F("Temperature: "));
|
||||
Serial.print(temp);
|
||||
|
@ -345,7 +353,8 @@ void loop() {
|
|||
}
|
||||
if (digitalRead(buttonPin)){
|
||||
if (!buttonPressedLastCycle && millis() - lastDebounceTime > DEBOUNCE_DELAY){
|
||||
config->cycleScreen()->draw();
|
||||
config->cycleScreen();
|
||||
config->drawCurrentScreen();
|
||||
buttonPressedLastCycle = true;
|
||||
lastDebounceTime = millis();
|
||||
}
|
||||
|
@ -353,4 +362,3 @@ void loop() {
|
|||
buttonPressedLastCycle = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue