diff --git a/game.cpp b/game.cpp index c1a8609..50a58d1 100644 --- a/game.cpp +++ b/game.cpp @@ -12,6 +12,8 @@ static std::array buttonRaw; #include "platform/esp32.h" #endif +static unsigned long batteryWarningEnd = 0; + bool displayImageInfinite(int16_t x, int16_t y, uint16_t w, uint16_t h, uint16_t *bitmap) { int screenpixel; @@ -241,6 +243,22 @@ void gameLoop() } voltageF = getVoltage(); + if (voltageF > 3.0 && voltageF < 4.0) { + if (batteryWarningEnd == 0) batteryWarningEnd = 5000 + getTimeInMillis(); + else if (batteryWarningEnd < getTimeInMillis()) { + #ifdef ESP32 + esp_deep_sleep_start(); + #else + drawString(gameBuff,(char*)"DEEPSLEEP!",0,gameBuff->HEIGHT-16,0xE0,0); + #endif + + } + + drawString(gameBuff,(char*)"LOW BATTERY!",0,0,0xE0,0); + drawString(gameBuff,(char*)"PLEASE CHARGE!",0,0,0xE0,0); + + } + calcFPS(); if (gameBuff->consoleBuffer != nullptr) { diff --git a/platform/esp32.h b/platform/esp32.h index a6e2755..27e6047 100644 --- a/platform/esp32.h +++ b/platform/esp32.h @@ -221,20 +221,20 @@ void gameInit() tft.setSwapBytes(true); // Swap the byte order for pushImage() - corrects endianness tft.fillScreen(TFT_BLACK); - Serial.println("Input Init"); - TOUCH_SENSE = getRawInput(); - for (int i = 0; i < 8; i++) - { - TOUCH_SENSE[i] /= 2; - if (TOUCH_SENSE[i] > TOUCH_SENSE_MAX) - TOUCH_SENSE[i] = TOUCH_SENSE_MAX; - if (TOUCH_SENSE[i] < TOUCH_SENSE_MIN) - TOUCH_SENSE[i] = TOUCH_SENSE_MIN; - Serial.print("Touch Sense : "); - Serial.print(i); - Serial.print(" - "); - Serial.println(TOUCH_SENSE[i]); - } + // Serial.println("Input Init"); + // TOUCH_SENSE = getRawInput(); + // for (int i = 0; i < 8; i++) + // { + // TOUCH_SENSE[i] /= 2; + // if (TOUCH_SENSE[i] > TOUCH_SENSE_MAX) + // TOUCH_SENSE[i] = TOUCH_SENSE_MAX; + // if (TOUCH_SENSE[i] < TOUCH_SENSE_MIN) + // TOUCH_SENSE[i] = TOUCH_SENSE_MIN; + // Serial.print("Touch Sense : "); + // Serial.print(i); + // Serial.print(" - "); + // Serial.println(TOUCH_SENSE[i]); + // } Serial.println("SPIFFS Init"); if (!SPIFFS.begin(true))