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