Compare commits

..

2 Commits

Author SHA1 Message Date
Neale Pickett 9e2d2b39f0 Fix URL and a few other display tweaks 2023-01-06 12:50:46 -07:00
Neale Pickett f9b51216ba Add generic network server info 2023-01-06 10:35:31 -07:00
5 changed files with 97 additions and 22 deletions

View File

@ -16,6 +16,34 @@ form different ideas about what it's displaying.
That's cool. 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 Philosophy
---------- ----------

10
network-server.h Normal file
View File

@ -0,0 +1,10 @@
#pragma once
/*
* Define these to fetch from a wallart-server
*
* https://git.woozle.org/neale/wallart-server
*/
#define ART_HOSTNAME "www.woozle.org"
#define ART_PORT 443
#define ART_PATH "/wallart/wallart.bin"

View File

@ -1,7 +1,7 @@
#include <FastLED.h> #include <FastLED.h>
#include <WiFiManager.h> #include <WiFiManager.h>
#include <esp_wifi.h> #include <esp_wifi.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
#include "network.h" #include "network.h"

View File

@ -3,15 +3,12 @@
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
#include "picker.h" #include "picker.h"
#include "network.h" #include "network.h"
#include "network-server.h"
#define NEOPIXEL_PIN 32 #define NEOPIXEL_PIN 32
#define GRIDLEN 64 #define GRIDLEN 64
#define WFM_PASSWORD "artsy fartsy" #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 MILLISECOND 1
#define SECOND (1000 * MILLISECOND) #define SECOND (1000 * MILLISECOND)
@ -21,7 +18,9 @@ CRGB grid[GRIDLEN];
void setup() { void setup() {
FastLED.addLeds<WS2812, NEOPIXEL_PIN, GRB>(grid, GRIDLEN); FastLED.addLeds<WS2812, NEOPIXEL_PIN, GRB>(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); network_setup(WFM_PASSWORD);
} }
@ -30,7 +29,8 @@ void fade(int cycles = 2) {
int hue = random(256); int hue = random(256);
for (int i = 0; i < reps; i++) { for (int i = 0; i < reps; i++) {
for (int pos = 0; pos < 8; pos++) { 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(); FastLED.show();
pause(80); 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++) { for (int frame = 0; frame < cycles; frame++) {
int val = 127 * random(2); 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) { if (pos < GRIDLEN-1) {
grid[pos] = grid[pos + 1]; uint8_t x2pos = cm5xlat(width, pos+1);
grid[xpos] = grid[x2pos];
} else { } else {
grid[pos] = CHSV(0, 255, val); grid[xpos] = CHSV(0, 255, val);
} }
} }
FastLED.show(); FastLED.show();
@ -169,26 +183,28 @@ uint8_t netgetStatus(uint8_t hue) {
void netget(int count=60) { void netget(int count=60) {
uint8_t hue = netgetStatus(HUE_BLUE); uint8_t hue = netgetStatus(HUE_BLUE);
#if defined(ART_HOSTNAME) && defined(ART_PORT) && defined(ART_PATH)
if (connected()) { if (connected()) {
WiFiClientSecure scli; WiFiClientSecure scli;
hue = netgetStatus(hue - 32); hue = netgetStatus(HUE_AQUA);
scli.setInsecure(); scli.setInsecure();
HttpClient https(scli, ART_HOSTNAME, ART_PORT); HttpClient https(scli, ART_HOSTNAME, ART_PORT);
do { do {
if (https.get(ART_PATH) != 0) break; if (https.get(ART_PATH) != 0) break;
hue = netgetStatus(hue - 32); hue = netgetStatus(HUE_GREEN);
if (https.skipResponseHeaders() != HTTP_SUCCESS) break; if (https.skipResponseHeaders() != HTTP_SUCCESS) break;
hue = netgetStatus(hue - 32); hue = netgetStatus(HUE_YELLOW);
int artlen = https.read((uint8_t *)NetArt, sizeof(NetArt)); int artlen = https.read((uint8_t *)NetArt, sizeof(NetArt));
hue = netgetStatus(hue - 32); hue = netgetStatus(HUE_ORANGE);
NetArtFrames = (artlen / 3) / GRIDLEN; NetArtFrames = (artlen / 3) / GRIDLEN;
} while(false); } while(false);
https.stop(); https.stop();
} }
#endif
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
netgetStatus(hue); netgetStatus(hue);
@ -208,8 +224,17 @@ void spinner(int count=32) {
void loop() { void loop() {
Picker p; 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(); fade();
singleCursor(20); singleCursor(20);
} else if (p.Pick(1)) { } else if (p.Pick(1)) {
@ -220,11 +245,11 @@ void loop() {
conwayish(); conwayish();
} else if (p.Pick(8)) { } else if (p.Pick(8)) {
glitchPulse(); glitchPulse();
} else if (p.Pick(8)) { } else if (p.Pick(2)) {
cm5(); cm5(0);
} else if (p.Pick(8)) { } else if (p.Pick(2)) {
netart(); cm5(8);
} else if (p.Pick(4) || !connected()) { } else if (p.Pick(2)) {
netget(); cm5(16);
} }
} }

12
xlat.py Normal file
View File

@ -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))