From 3c35b5b204a1f7c0c0ed4e887306e4f641ca01aa Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 8 Dec 2023 20:37:55 -0700 Subject: [PATCH] Fully move to new NTP thingy --- README.md | 13 ++----------- network.cpp | 11 +++++++++-- network.h | 1 + timezones.h | 17 ----------------- wallart.ino | 36 ++++++++++++++++++++---------------- 5 files changed, 32 insertions(+), 46 deletions(-) delete mode 100644 timezones.h diff --git a/README.md b/README.md index 3b8f780..511a420 100644 --- a/README.md +++ b/README.md @@ -97,17 +97,8 @@ it displays something like a clock. * There are four pixels around the bottom that move every 5 seconds -Update ------- - -You can upload a new version of the firmware. -Reset the device, -and select the "Update" button instead of configuring WiFi. -Then you can upload the new .bin firmware file. - -You may have to reconfigure networking after this. - -### Uploading from CLI +Updating Firmware +----------------- python3 esptool.py --chip esp32 --port "/dev/ttyUSB0" --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x1000 wallart.ino.bootloader.bin 0x8000 wallart.ino.partitions.bin 0xe000 boot_app0.bin 0x10000 wallart.ino.bin diff --git a/network.cpp b/network.cpp index 2615af2..0347de4 100644 --- a/network.cpp +++ b/network.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include "network.h" @@ -13,11 +14,17 @@ void network_reset() { wfm.resetSettings(); } -void on_time_available(struct timeval *t) -{ + +bool time_was_accurate_once = false; +bool clock_is_set() { + return time_was_accurate_once; +} + +void on_time_available(struct timeval *t) { struct tm timeInfo; getLocalTime(&timeInfo, 1000); Serial.println(&timeInfo, "%A, %B %d %Y %H:%M:%S %Z %z "); + time_was_accurate_once = true; } void network_setup(char *password) { diff --git a/network.h b/network.h index b919c58..4143a85 100644 --- a/network.h +++ b/network.h @@ -8,3 +8,4 @@ void network_setup(char *password); bool connected(); void pause(uint32_t dwMs); void netget(int count); +bool clock_is_set(); diff --git a/timezones.h b/timezones.h deleted file mode 100644 index e7a64b2..0000000 --- a/timezones.h +++ /dev/null @@ -1,17 +0,0 @@ -#include - -TimeChangeRule usEDT = {"EDT", Second, Sun, Mar, 2, -240}; -TimeChangeRule usEST = {"EST", First, Sun, Nov, 2, -300}; -Timezone TZ_US_Eastern(usEDT, usEST); - -TimeChangeRule usCDT = {"CDT", Second, Sun, Mar, 2, -300}; -TimeChangeRule usCST = {"CST", First, Sun, Nov, 2, -360}; -Timezone TZ_US_Central(usCDT, usCST); - -TimeChangeRule usMDT = {"MDT", Second, Sun, Mar, 2, -360}; -TimeChangeRule usMST = {"MST", First, Sun, Nov, 2, -420}; -Timezone TZ_US_Mountain(usMDT, usMST); - -TimeChangeRule usPDT = {"EDT", Second, Sun, Mar, 2, -420}; -TimeChangeRule usPST = {"EST", First, Sun, Nov, 2, -480}; -Timezone TZ_US_Pacific(usPDT, usPST); diff --git a/wallart.ino b/wallart.ino index 444e56c..448f627 100644 --- a/wallart.ino +++ b/wallart.ino @@ -10,7 +10,6 @@ #define NEOPIXEL_PIN 32 #define GRIDLEN 64 #define WFM_PASSWORD "artsy fartsy" -#define TIMEZONE TZ_US_Eastern /* * The hours when the day begins and ends. @@ -274,18 +273,22 @@ void spinner(int count=32) { } } -void displayTime(unsigned long duration = 20 * SECOND) { - if (timeStatus() != timeSet) return; +void displayTime(unsigned long duration = 20*SECOND) { + if (!clock_is_set()) return; unsigned long end = millis() + duration; + FastLED.clear(); while (millis() < end) { - int hh = hour(); - int mmss = now() % 3600; + struct tm info; + getLocalTime(&info); + + int hh = info.tm_hour; + int mmss = (info.tm_min * 60) + info.tm_sec; uint8_t hue = HUE_YELLOW; // Top: Hours - if (isPM()) { + if (hh >= 12) { hue = HUE_ORANGE; hh -= 12; } @@ -298,10 +301,10 @@ void displayTime(unsigned long duration = 20 * SECOND) { // Outer: 5s uint8_t s = (mmss/5) % 5; - grid[64 - 7 - 1] = CHSV(HUE_PURPLE, 128, (s==1)?96:0); - grid[64 - 15 - 1] = CHSV(HUE_PURPLE, 128, (s==2)?96:0); - grid[64 - 8 - 1] = CHSV(HUE_PURPLE, 128, (s==3)?96:0); - grid[64 - 0 - 1] = CHSV(HUE_PURPLE, 128, (s==4)?96:0); + grid[64 - 7 - 1] = CHSV(HUE_GREEN, 128, (s==1)?96:0); + grid[64 - 15 - 1] = CHSV(HUE_GREEN, 128, (s==2)?96:0); + grid[64 - 8 - 1] = CHSV(HUE_GREEN, 128, (s==3)?96:0); + grid[64 - 0 - 1] = CHSV(HUE_GREEN, 128, (s==4)?96:0); for (int i = 0; i < 12; i++) { // Omit first and last position on a row @@ -339,11 +342,11 @@ void loop() { uint8_t getprob = 4; bool conn = connected(); bool day = true; - timeStatus_t ts = timeStatus(); - if (ts == timeSet) { - int hh = hour(); - day = ((hh >= DAY_BEGIN) && (hh < DAY_END)); + if (clock_is_set()) { + struct tm info; + getLocalTime(&info); + day = ((info.tm_hour >= DAY_BEGIN) && (info.tm_hour < DAY_END)); } FastLED.setBrightness(day?DAY_BRIGHTNESS:NIGHT_BRIGHTNESS); @@ -352,8 +355,9 @@ void loop() { getprob = 16; } - if ((ts == timeSet) && (!day || p.Pick(4))) { - // At night, only ever show the clock + if (!day && clock_is_set()) { + displayTime(); + } else if (p.Pick(4) && clock_is_set()) { displayTime(2 * MINUTE); } else if (p.Pick(getprob)) { netget();