Animated web art! Remove spinner.

This commit is contained in:
Neale Pickett 2022-07-19 21:14:34 -06:00
parent 83dd19c68c
commit 661d754488
2 changed files with 35 additions and 43 deletions

View File

@ -1,10 +1,6 @@
#pragma once #pragma once
#include <HTTPClient.h>
#include <WiFiClientSecure.h>
void network_setup(char *password); void network_setup(char *password);
bool connected(); bool connected();
void pause(uint32_t dwMs); void pause(uint32_t dwMs);
void netget(int count); void netget(int count);

View File

@ -1,15 +1,22 @@
#include <FastLED.h> #include <FastLED.h>
#include <ArduinoHttpClient.h>
#include <WiFiClientSecure.h>
#include "picker.h" #include "picker.h"
#include "network.h" #include "network.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_URL "https://sweetums.woozle.org/public/wallart.bin"
#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)
#define HTTPS_TIMEOUT (2 * SECOND)
CRGB grid[GRIDLEN]; CRGB grid[GRIDLEN];
void setup() { void setup() {
@ -132,18 +139,22 @@ void cm5(int cycles=200) {
} }
// Art from the network // Art from the network
bool NetArtExists = false; int NetArtFrames = 0;
CRGB NetArt[GRIDLEN]; CRGB NetArt[8][GRIDLEN];
void netart() { void netart(int count=40) {
if (NetArtExists) { if (NetArtFrames < 1) {
memcpy(grid, NetArt, GRIDLEN*3); return;
}
for (int i = 0; i < count; i++) {
memcpy(grid, NetArt[i%NetArtFrames], GRIDLEN*3);
FastLED.show(); FastLED.show();
pause(10 * SECOND); pause(500);
} }
} }
int netgetStatus(int hue) { uint8_t netgetStatus(uint8_t hue) {
static int positions[4] = {0}; static int positions[4] = {0};
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
grid[positions[j]] = CHSV(0, 0, 0); grid[positions[j]] = CHSV(0, 0, 0);
@ -155,8 +166,8 @@ int netgetStatus(int hue) {
return hue; return hue;
} }
void netget(int count=30) { void netget(int count=60) {
int hue = netgetStatus(HUE_BLUE); uint8_t hue = netgetStatus(HUE_BLUE);
if (connected()) { if (connected()) {
WiFiClientSecure scli; WiFiClientSecure scli;
@ -164,34 +175,19 @@ void netget(int count=30) {
hue = netgetStatus(hue - 32); hue = netgetStatus(hue - 32);
scli.setInsecure(); scli.setInsecure();
{ HttpClient https(scli, ART_HOSTNAME, ART_PORT);
HTTPClient https; do {
if (https.get(ART_PATH) != 0) break;
hue = netgetStatus(hue - 32);
if (https.begin(scli, ART_URL)) { if (https.skipResponseHeaders() != HTTP_SUCCESS) break;
hue = netgetStatus(hue - 32); hue = netgetStatus(hue - 32);
int code = https.GET();
if (code == HTTP_CODE_OK) {
hue = netgetStatus(hue - 32);
String resp = https.getString();
for (int i = 0; i < resp.length(); i += 3) {
if (resp.length() < i+3) {
break;
}
CRGB pixel = CRGB(resp[i], resp[i+1], resp[i+2]);
NetArt[i/3] = rgb2hsv_approximate(pixel);
}
NetArtExists = true;
hue = hue - 32;
}
https.end();
FastLED.show(); int artlen = https.read((uint8_t *)NetArt, sizeof(NetArt));
for (int i = 0; i < 4*4; i++) { hue = netgetStatus(hue - 32);
pause(250); NetArtFrames = (artlen / 3) / GRIDLEN;
} } while(false);
} https.stop();
scli.stop();
}
} }
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
@ -226,8 +222,8 @@ void loop() {
glitchPulse(); glitchPulse();
} else if (p.Pick(8)) { } else if (p.Pick(8)) {
cm5(); cm5();
} else if (p.Pick(10)) { } else if (p.Pick(8)) {
spinner(); netart();
} else if (p.Pick(4) || !connected()) { } else if (p.Pick(4) || !connected()) {
netget(); netget();
} }