Skip to content

Commit

Permalink
Menu bugfixes
Browse files Browse the repository at this point in the history
fix Menu Bugs like:
- correct exiting (after 20 sec)
- missed button presses
- exit rainbow mode via button press
  • Loading branch information
davidkreidler committed Sep 24, 2023
1 parent 65caa7e commit 700b2b0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 12 deletions.
35 changes: 24 additions & 11 deletions OpenCO2_Sensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,6 @@ void calibrate() {

void rainbowMode() {
displayRainbow();
scd4x.stopPeriodicMeasurement();
scd4x.powerDown();
digitalWrite(LED_POWER, LOW); //LED ON

for(int j = 0; j < 256; j++) {
Expand All @@ -400,6 +398,7 @@ void rainbowMode() {
strip.setPixelColor(0, green, red, blue);
strip.show();
if (j == 255) j=0;
if (digitalRead(BUTTON) == 0) return;
delay(20);
}
}
Expand Down Expand Up @@ -467,9 +466,9 @@ void toggleWiFi() {
}

delay(500);
for (int i=0; i<200; i++) {
if (digitalRead(BUTTON) == 0) return; // wait for button press
delay(100);
unsigned long StartTime = millis();
for (;;) {
if ((millis() - StartTime) > 20000 || digitalRead(BUTTON) == 0) return; // wait for button press OR up to 20 sec
}
}

Expand All @@ -484,7 +483,7 @@ enum MenuOptions {
};

const char* menuItems[NUM_OPTIONS] = {
"LED toggle",
"LED on/off",
"Rainbow",
"Calibrate",
"History",
Expand All @@ -499,24 +498,33 @@ void handleButtonPress() {
displayMenu(selectedOption);

uint16_t mspressed;
for (int i=0; i<2000; i++) { // display Menu up to 20 sec
unsigned long menuStartTime = millis();

for (;;) {
if ((millis() - menuStartTime) > 20000) { // display Menu up to 20 sec
refreshes = 1;
return;
}

mspressed = 0;
if (digitalRead(BUTTON) == 0) {
while(digitalRead(BUTTON) == 0) { // calculate how long BUTTON is pressed
delay(100);
mspressed += 100;
if (mspressed > 1000) break;
}
if (mspressed > 1000) {
if (mspressed > 1000) { // long press
switch (selectedOption) {
case LED:
LEDalwaysOn = !LEDalwaysOn;
setLED(co2);
delay(1000);
while(digitalRead(BUTTON) == 0) {} // wait until button is released
refreshes = 1;
return;
case RAINBOW:
rainbowMode();
setLED(co2);
refreshes = 1;
return;
case CALIBRATE:
calibrate();
Expand All @@ -531,17 +539,17 @@ void handleButtonPress() {
refreshes = 1;
return;
case EXIT:
while(digitalRead(BUTTON) == 0) {} // wait until button is released
refreshes = 1;
return;
}
} else { // goto next Menu point
if (selectedOption+1 == NUM_OPTIONS) selectedOption = 0;
else selectedOption++;
displayMenu(selectedOption);
i = 0; // display Menu again for 20 sec
menuStartTime = millis(); // display Menu again for 20 sec
}
}
delay(10);
}
}

Expand Down Expand Up @@ -629,6 +637,11 @@ void loop() {
bool isDataReady = false;
uint16_t ready_error = scd4x.getDataReadyFlag(isDataReady);
if (ready_error || !isDataReady) {
// needed to overwrite displayed Menu
displayWriteMeasuerments(co2, temperature, humidity);
if(BatteryMode) displayBattery(calcBatteryPercentage(readBatteryVoltage()));
updateDisplay();

if (BatteryMode) goto_deep_sleep(29000);
else goto_light_sleep(4000);
return; // otherwise continues running!
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Enable Wi-Fi via the Menu button. When power is connected, an access point `Open

Download `OpenCO2_Sensor.ino.bin` from the latest [release](https://github.com/davidkreidler/OpenCO2_Sensor/releases).
Enable Wi-Fi via the Menu button, in an area where no previously known network is active. Connect power. Then connect to `OpenCO2 Sensor` and navigate to http://192.168.4.1 . Under `Update` select the `OpenCO2_Sensor.ino.bin` file and click `Update`. The Sensor will restart.
![alt text](https://github.com/davidkreidler/OpenCO2_Sensor/raw/main/pictures/ota.jpg)
![alt text](https://github.com/davidkreidler/OpenCO2_Sensor/raw/main/pictures/OTA.jpg)

# Update via USB

Expand Down
2 changes: 2 additions & 0 deletions epd_abstraction.ino
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ void draw_qr_code(const uint8_t * qrcode) {
else Paint_DrawNum(200-4*11, 200-16, qrcodeNumber+1, &Font16, BLACK, WHITE);
Paint_DrawString_EN(200-3*11, 200-16, "/", &Font16, WHITE, BLACK);
Paint_DrawNum(200-2*11, 200-16, hour+1, &Font16, BLACK, WHITE);
Paint_DrawString_EN(1, 1, "Wait 20sec to exit", &Font16, WHITE, BLACK);
updateDisplay();
}

Expand Down Expand Up @@ -402,6 +403,7 @@ void displayWiFiStrengh() {
}

void displayWriteError(char errorMessage[256]){
Paint_Clear(WHITE);
Paint_DrawString_EN(5, 40, errorMessage, &Font20, WHITE, BLACK);
}

Expand Down
Binary file modified pictures/drawing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 700b2b0

Please sign in to comment.