From 9e2d2b39f0aa7de5c714c1b16ef17921a4dd15e8 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Fri, 6 Jan 2023 12:50:46 -0700 Subject: [PATCH] Fix URL and a few other display tweaks --- README.md | 28 ++++++++++++++++++++ network-server.h | 2 +- network.cpp | 2 +- wallart.ino | 67 +++++++++++++++++++++++++++++++++--------------- xlat.py | 12 +++++++++ 5 files changed, 88 insertions(+), 23 deletions(-) create mode 100644 xlat.py diff --git a/README.md b/README.md index 00c6eb4..51b10a1 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,34 @@ form different ideas about what it's displaying. That's cool. +Network Server +-------------- + +If you provide a wallart server in +`network-server.h`, +the program will periodically fetch an image/animation from it, +and display that image/animation. + +Because the fetch takes some time, +one of the animation patterns actually shows progress of the fetch. +It's the one with the four lights of the same color. +After it's either succeeded or failed, +it stays on that color for a while, +so you can tell how everything is going. +Here's what the colors indicate: + +Color it stays on | Status +--- | --- +Blue | Unable to connect to access point +Aqua | Some sort of problem initiating the HTTPS request (DNS?) +Green | HTTPS server request failed (404 or similar) +Yellow | Image download failed +Orange | Everything worked! + +A happy setup will cycle through each color once, +and then display orange for a while. + + Philosophy ---------- diff --git a/network-server.h b/network-server.h index a1c3ecc..22f75e1 100644 --- a/network-server.h +++ b/network-server.h @@ -5,6 +5,6 @@ * * https://git.woozle.org/neale/wallart-server */ -//#define ART_HOSTNAME "wallart.your.site" +#define ART_HOSTNAME "www.woozle.org" #define ART_PORT 443 #define ART_PATH "/wallart/wallart.bin" diff --git a/network.cpp b/network.cpp index f66baf5..e53a270 100644 --- a/network.cpp +++ b/network.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include #include "network.h" diff --git a/wallart.ino b/wallart.ino index cd789d2..6a492a8 100644 --- a/wallart.ino +++ b/wallart.ino @@ -3,15 +3,12 @@ #include #include "picker.h" #include "network.h" +#include "network-server.h" #define NEOPIXEL_PIN 32 #define GRIDLEN 64 #define WFM_PASSWORD "artsy fartsy" -#define ART_HOSTNAME "sweetums.woozle.org" -#define ART_PORT 443 -#define ART_PATH "/public/wallart.bin" - #define MILLISECOND 1 #define SECOND (1000 * MILLISECOND) @@ -21,7 +18,9 @@ CRGB grid[GRIDLEN]; void setup() { FastLED.addLeds(grid, GRIDLEN); - FastLED.setBrightness(32); + FastLED.setBrightness(64); + // Maybe it's the plexiglass but for my build I really need to dial back the red + FastLED.setCorrection(0xc0ffff); network_setup(WFM_PASSWORD); } @@ -30,7 +29,8 @@ void fade(int cycles = 2) { int hue = random(256); for (int i = 0; i < reps; i++) { for (int pos = 0; pos < 8; pos++) { - grid[(i+pos) % GRIDLEN] = CHSV(hue, 255, pos * 32); + uint8_t p = cm5xlat(8, (i+pos) % GRIDLEN); + grid[p] = CHSV(hue, 255, pos * 32); } FastLED.show(); pause(80); @@ -123,14 +123,28 @@ void conwayish(int cycles=5000) { } } -void cm5(int cycles=200) { +uint8_t cm5xlat(uint8_t width, uint8_t pos) { + if (width == 0) { + return pos; + } + + uint8_t x = pos % width; + uint8_t y = pos / width; + uint8_t odd = y % 2; + + return (y*width) + ((width-x-1)*odd) + (x*(1-odd)); +} + +void cm5(uint8_t width=0, int cycles=200) { for (int frame = 0; frame < cycles; frame++) { int val = 127 * random(2); - for (int pos = 0; pos < GRIDLEN; pos++) { + for (uint8_t pos = 0; pos < GRIDLEN; pos++) { + uint8_t xpos = cm5xlat(width, pos); if (pos < GRIDLEN-1) { - grid[pos] = grid[pos + 1]; + uint8_t x2pos = cm5xlat(width, pos+1); + grid[xpos] = grid[x2pos]; } else { - grid[pos] = CHSV(0, 255, val); + grid[xpos] = CHSV(0, 255, val); } } FastLED.show(); @@ -169,26 +183,28 @@ uint8_t netgetStatus(uint8_t hue) { void netget(int count=60) { uint8_t hue = netgetStatus(HUE_BLUE); +#if defined(ART_HOSTNAME) && defined(ART_PORT) && defined(ART_PATH) if (connected()) { WiFiClientSecure scli; - hue = netgetStatus(hue - 32); + hue = netgetStatus(HUE_AQUA); scli.setInsecure(); HttpClient https(scli, ART_HOSTNAME, ART_PORT); do { if (https.get(ART_PATH) != 0) break; - hue = netgetStatus(hue - 32); + hue = netgetStatus(HUE_GREEN); if (https.skipResponseHeaders() != HTTP_SUCCESS) break; - hue = netgetStatus(hue - 32); + hue = netgetStatus(HUE_YELLOW); int artlen = https.read((uint8_t *)NetArt, sizeof(NetArt)); - hue = netgetStatus(hue - 32); + hue = netgetStatus(HUE_ORANGE); NetArtFrames = (artlen / 3) / GRIDLEN; } while(false); https.stop(); } +#endif for (int i = 0; i < count; i++) { netgetStatus(hue); @@ -208,8 +224,17 @@ void spinner(int count=32) { void loop() { Picker p; + uint8_t getprob = 4; - if (p.Pick(1)) { + if ((NetArtFrames == 0) || !connected()) { + getprob = 16; + } + + if (p.Pick(getprob)) { + netget(); + } else if (p.Pick(4)) { + netart(); + } else if (p.Pick(1)) { fade(); singleCursor(20); } else if (p.Pick(1)) { @@ -220,11 +245,11 @@ void loop() { conwayish(); } else if (p.Pick(8)) { glitchPulse(); - } else if (p.Pick(8)) { - cm5(); - } else if (p.Pick(8)) { - netart(); - } else if (p.Pick(4) || !connected()) { - netget(); + } else if (p.Pick(2)) { + cm5(0); + } else if (p.Pick(2)) { + cm5(8); + } else if (p.Pick(2)) { + cm5(16); } } diff --git a/xlat.py b/xlat.py new file mode 100644 index 0000000..1eb1e3c --- /dev/null +++ b/xlat.py @@ -0,0 +1,12 @@ +def xlat(width, pos): + if width == 0: + return pos + + x = pos % width + y = pos // width + odd = y % 2 + + return (y*width) + ((width-x-1)*odd) + (x*(1-odd)) + +for i in range(32): + print(i, xlat(8, i))