Skip to content

Commit

Permalink
Added Deep sleep and battery warning
Browse files Browse the repository at this point in the history
  • Loading branch information
tonym128 committed Jan 16, 2020
1 parent d2355ed commit 062a53f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
18 changes: 18 additions & 0 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ static std::array<int, 8> 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;
Expand Down Expand Up @@ -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)
{
Expand Down
28 changes: 14 additions & 14 deletions platform/esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 062a53f

Please sign in to comment.