diff --git a/m5paper-stockticker.ino b/m5paper-stockticker.ino index 5b62653..db258dc 100644 --- a/m5paper-stockticker.ino +++ b/m5paper-stockticker.ino @@ -326,6 +326,11 @@ void setup() { struct tm now = {}; for (int i = 0; i < 10 && !getLocalTime(&now); i++) delay(500); + // Current US Eastern time -> tells us which event (open/mid/close) this is + // and, later, when the next event is. + struct tm etTm; + getEasternTime(etTm); + // Fetch market data StockData sd[NUM_STOCKS]; float dayGain = 0.0f, openValue = 0.0f; @@ -351,10 +356,11 @@ void setup() { // -- Row 1: timestamp (left) | "zZz [battery] xx%" (right) -- char timeStr[32]; - strftime(timeStr, sizeof(timeStr), "%d/%m %I:%M %p", &now); + strftime(timeStr, sizeof(timeStr), "%m/%d %I:%M %p", &now); M5.Display.setCursor(20, 22); M5.Display.print("U: "); M5.Display.print(timeStr); + M5.Display.printf(" (%s)", marketPhase(etTm)); M5.Display.setCursor(740, 15); M5.Display.print("zZz"); @@ -418,7 +424,9 @@ void setup() { M5.Display.endWrite(); delay(1000); - M5.Power.deepSleep(43200000000ULL); // 12 hours + // We wake at open, midday, and close, so update now and sleep until + // whichever event comes next (Mon-Fri). + prepareForSleepAndEnter(usUntilNextEvent(etTm)); } void loop() {} \ No newline at end of file