refactor: Integrate intelligent market-driven deep sleep
This commit is contained in:
1 parent
652a622954
commit
52162da3e8
1 file changed
+10
-2
+10
-2
@@ -326,6 +326,11 @@ void setup() {
|
|||||||
struct tm now = {};
|
struct tm now = {};
|
||||||
for (int i = 0; i < 10 && !getLocalTime(&now); i++) delay(500);
|
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
|
// Fetch market data
|
||||||
StockData sd[NUM_STOCKS];
|
StockData sd[NUM_STOCKS];
|
||||||
float dayGain = 0.0f, openValue = 0.0f;
|
float dayGain = 0.0f, openValue = 0.0f;
|
||||||
@@ -351,10 +356,11 @@ void setup() {
|
|||||||
|
|
||||||
// -- Row 1: timestamp (left) | "zZz [battery] xx%" (right) --
|
// -- Row 1: timestamp (left) | "zZz [battery] xx%" (right) --
|
||||||
char timeStr[32];
|
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.setCursor(20, 22);
|
||||||
M5.Display.print("U: ");
|
M5.Display.print("U: ");
|
||||||
M5.Display.print(timeStr);
|
M5.Display.print(timeStr);
|
||||||
|
M5.Display.printf(" (%s)", marketPhase(etTm));
|
||||||
|
|
||||||
M5.Display.setCursor(740, 15);
|
M5.Display.setCursor(740, 15);
|
||||||
M5.Display.print("zZz");
|
M5.Display.print("zZz");
|
||||||
@@ -418,7 +424,9 @@ void setup() {
|
|||||||
M5.Display.endWrite();
|
M5.Display.endWrite();
|
||||||
|
|
||||||
delay(1000);
|
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() {}
|
void loop() {}
|
||||||
Reference in new issue
Block a user