simplify config
This commit is contained in:
parent
79e7bb904d
commit
241ac1ad92
1 changed files with 42 additions and 61 deletions
79
main.ino
79
main.ino
|
@ -269,64 +269,45 @@ bool buttonPressedLastCycle = false;
|
||||||
bool sht3xErrorLastCycle = false;
|
bool sht3xErrorLastCycle = false;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CONFIG START
|
// CONFIG START
|
||||||
DataStorage* tempData;
|
|
||||||
DataStorage* humData;
|
|
||||||
GraphElement* graphTemp;
|
|
||||||
GraphElement* graphHum;
|
|
||||||
MaxAvgMinElement* bigMaxAvgMinTemp;
|
|
||||||
MaxAvgMinElement* bigMaxAvgMinHum;
|
|
||||||
MaxAvgMinElement* maxAvgMinTemp;
|
|
||||||
MaxAvgMinElement* maxAvgMinHum;
|
|
||||||
showCurrentValue* showCurrentTemp;
|
|
||||||
showCurrentValue* showCurrentHum;
|
|
||||||
Screen* screenTemp;
|
|
||||||
Screen* screenHum;
|
|
||||||
Screen* screenBigTemp;
|
|
||||||
Screen* screenBigHum;
|
|
||||||
Screen* screenCurrent;
|
|
||||||
|
|
||||||
DisplayConfig* config;
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
|
|
||||||
// Datapoint storage. Arguments: Unit, amount of datapoints to be saved.
|
// Datapoint storage. Arguments: Unit, amount of datapoints to be saved.
|
||||||
tempData = new DataStorage("C", AMOUNT_DATAPOINTS);
|
DataStorage tempData("C", AMOUNT_DATAPOINTS);
|
||||||
humData = new DataStorage("%", AMOUNT_DATAPOINTS);
|
DataStorage humData("%", AMOUNT_DATAPOINTS);
|
||||||
|
|
||||||
// Screen elements. Base arguments: X Pos, Y Pos, Width, Lenght, Datasource, Border true/false.
|
// Screen elements. Base arguments: X Pos, Y Pos, Width, Lenght, Datasource, Border true/false.
|
||||||
bigMaxAvgMinTemp = new MaxAvgMinElement(5, 5, 65, 70, *tempData, false, 2);
|
GraphElement graphTemp(5, 5, 80, 70, tempData, true, AMOUNT_DATAPOINTS, 10);
|
||||||
bigMaxAvgMinHum = new MaxAvgMinElement(5, 5, 65, 70, *humData, false, 2);
|
GraphElement graphHum(5, 5, 80, 70, humData, true, AMOUNT_DATAPOINTS, 10);
|
||||||
graphTemp = new GraphElement(5, 5, 80, 70, *tempData, true, AMOUNT_DATAPOINTS, 10);
|
MaxAvgMinElement bigMaxAvgMinTemp(5, 5, 65, 70, tempData, false, 2);
|
||||||
maxAvgMinTemp = new MaxAvgMinElement(90, 5, 65, 70, *tempData, false, 1);
|
MaxAvgMinElement bigMaxAvgMinHum(5, 5, 65, 70, humData, false, 2);
|
||||||
graphHum = new GraphElement(5, 5, 80, 70, *humData, true, AMOUNT_DATAPOINTS, 10);
|
MaxAvgMinElement maxAvgMinTemp(90, 5, 65, 70, tempData, false, 1);
|
||||||
maxAvgMinHum = new MaxAvgMinElement(90, 5, 65, 70, *humData, false, 1);
|
MaxAvgMinElement maxAvgMinHum(90, 5, 65, 70, humData, false, 1);
|
||||||
showCurrentTemp = new showCurrentValue(0, 0, 40, 80, *tempData, false);
|
showCurrentValue showCurrentTemp(0, 0, 40, 80, tempData, false);
|
||||||
showCurrentHum = new showCurrentValue(0, 40, 40, 80, *humData, false);
|
showCurrentValue showCurrentHum(0, 40, 40, 80, humData, false);
|
||||||
|
|
||||||
// Element 'collections' / arrays. Arguments: Array containing pointers to elements, nullptr must be at the end.
|
// Element 'collections' / arrays. Arguments: Array containing pointers to elements, nullptr must be at the end.
|
||||||
static Element* elemArrTemp[] = { graphTemp, maxAvgMinTemp, nullptr };
|
Element* elemArrTemp[] { &graphTemp, &maxAvgMinTemp, nullptr };
|
||||||
static Element* elemArrHum[] = { graphHum, maxAvgMinHum, nullptr };
|
Element* elemArrHum[] { &graphHum, &maxAvgMinHum, nullptr };
|
||||||
static Element* elemBigArrTemp[] = { bigMaxAvgMinTemp, nullptr };
|
Element* elemBigArrTemp[] { &bigMaxAvgMinTemp, nullptr };
|
||||||
static Element* elemBigArrHum[] = { bigMaxAvgMinHum, nullptr };
|
Element* elemBigArrHum[] { &bigMaxAvgMinHum, nullptr };
|
||||||
static Element* currentArr[] = { showCurrentTemp, showCurrentHum, nullptr };
|
Element* currentArr[] { &showCurrentTemp, &showCurrentHum, nullptr };
|
||||||
|
|
||||||
// Screens. Arguments: Element arrays.
|
// Screens. Arguments: Element arrays.
|
||||||
screenTemp = new Screen(elemArrTemp);
|
Screen screenTemp(elemArrTemp);
|
||||||
screenHum = new Screen(elemArrHum);
|
Screen screenHum(elemArrHum);
|
||||||
screenBigTemp = new Screen(elemBigArrTemp);
|
Screen screenBigTemp(elemBigArrTemp);
|
||||||
screenBigHum = new Screen(elemBigArrHum);
|
Screen screenBigHum(elemBigArrHum);
|
||||||
screenCurrent = new Screen(currentArr);
|
Screen screenCurrent(currentArr);
|
||||||
|
|
||||||
|
|
||||||
// Screen 'collections' / arrays: Arguments: Array containing pointers to screens, nullptr must be at the end.
|
// Screen 'collections' / arrays: Arguments: Array containing pointers to screens, nullptr must be at the end.
|
||||||
static Screen* screenArr[] = { screenCurrent, screenTemp, screenHum, screenBigTemp, screenBigHum, nullptr};
|
Screen* screenArr[] = { &screenCurrent, &screenTemp, &screenHum, &screenBigTemp, &screenBigHum, nullptr};
|
||||||
|
|
||||||
// Config. Arguments: A screen array.
|
DisplayConfig config(screenArr);
|
||||||
config = new DisplayConfig(screenArr);
|
|
||||||
// CONFIG END
|
// CONFIG END
|
||||||
|
|
||||||
|
|
||||||
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.println(F("Serial started."));
|
Serial.println(F("Serial started."));
|
||||||
|
|
||||||
|
@ -345,7 +326,7 @@ void setup() {
|
||||||
void loop() {
|
void loop() {
|
||||||
unsigned long currentMillis = millis();
|
unsigned long currentMillis = millis();
|
||||||
if (sht3xErrorLastCycle) {
|
if (sht3xErrorLastCycle) {
|
||||||
config->drawCurrentScreen();
|
config.drawCurrentScreen();
|
||||||
sht3xErrorLastCycle = false;
|
sht3xErrorLastCycle = false;
|
||||||
}
|
}
|
||||||
if (currentMillis - previousMillis >= WAIT_TIME * 1000) {
|
if (currentMillis - previousMillis >= WAIT_TIME * 1000) {
|
||||||
|
@ -354,11 +335,11 @@ void loop() {
|
||||||
float temp = sht3x.temperature();
|
float temp = sht3x.temperature();
|
||||||
float hum = sht3x.humidity();
|
float hum = sht3x.humidity();
|
||||||
|
|
||||||
tempData->addData(temp);
|
tempData.addData(temp);
|
||||||
humData->addData(hum);
|
humData.addData(hum);
|
||||||
|
|
||||||
|
|
||||||
config->drawCurrentScreen();
|
config.drawCurrentScreen();
|
||||||
|
|
||||||
Serial.print(F("Temperature: "));
|
Serial.print(F("Temperature: "));
|
||||||
Serial.print(temp);
|
Serial.print(temp);
|
||||||
|
@ -380,8 +361,8 @@ void loop() {
|
||||||
}
|
}
|
||||||
if (digitalRead(buttonPin)){
|
if (digitalRead(buttonPin)){
|
||||||
if (!buttonPressedLastCycle && millis() - lastDebounceTime > DEBOUNCE_DELAY){
|
if (!buttonPressedLastCycle && millis() - lastDebounceTime > DEBOUNCE_DELAY){
|
||||||
config->cycleScreen();
|
config.cycleScreen();
|
||||||
config->drawCurrentScreen();
|
config.drawCurrentScreen();
|
||||||
buttonPressedLastCycle = true;
|
buttonPressedLastCycle = true;
|
||||||
lastDebounceTime = millis();
|
lastDebounceTime = millis();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue