cleanup code, add some more text; fix updater

This commit is contained in:
Riley L. 2024-09-29 18:08:45 +02:00
parent 8f4ca71f72
commit e3d9adbb44
3 changed files with 38 additions and 27 deletions

View file

@ -40,10 +40,10 @@ ESP8266WebServer server(80);
WebSocketsServer webSocket(81);
WiFiUDP UDP;
char UDP_packet[90 * 4];
char UDP_packet[90 * 4] = {0};
WiFiUDP UDP2;
char UDP2_packet[60];
char UDP2_packet[60] = {0};
String ota_pw;
@ -143,7 +143,7 @@ void handleSetPixels() {
uint8_t buf[360];
uint8_t toggle = 0;
for(int i = 0 ; i < 720 ; i++) {
buf[i/2] = lookup_hex(hexbuf[i]) << (toggle * 8);
buf[i/2] = lookup_hex(hexbuf[i]) << (toggle * 4);
toggle ^= 1;
}
@ -229,6 +229,10 @@ void handleUpdate() {
void handleUpload() {
HTTPUpload& upload = server.upload();
size_t bytediv = 127 / max(upload.contentLength, size_t(1)); // bytes / step; upload / 127
fillColor(0xFF, 0xA5, 0);
writeText("upgrading firmware...");
if (upload.status == UPLOAD_FILE_START) {
Serial.printf("Update: %s\n", upload.filename.c_str());
if (!Update.begin(upload.contentLength)) {
@ -241,6 +245,9 @@ void handleUpload() {
} else if (upload.status == UPLOAD_FILE_END) {
if (Update.end(true)) {
Serial.printf("Update Success: %u\nRebooting...\n", upload.totalSize);
fillColor(0, 255, 0);
writeText("upgraded firmware!");
} else {
Update.printError(Serial);
}
@ -277,14 +284,7 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length
String message = String((char*) payload);
Serial.print("WS:");
Serial.println(message);
if (message.startsWith("{RGB}=")) {
uint32_t rgb;
rgb = strtol(message.substring(7,13).c_str(), 0, 16);
fillColor(rgb>>16, rgb >> 8, rgb >> 0);
return;
}
Serial.println(message);
writeText(message.c_str());
} else if(type == WStype_BIN) {
for(size_t i = 0 ; i < length ; i+=4 ) {
@ -304,7 +304,7 @@ void handleFallbackRoot() {
prefs.end();
char wifiCredentialsPage[1024];
sprintf(wifiCredentialsPage, wifiCredentialsTemplate, ssid.c_str(), wifi_pw.c_str(), ota_pw.c_str());
snprintf(wifiCredentialsPage, 1024, wifiCredentialsTemplate, ssid.c_str(), wifi_pw.c_str(), ota_pw.c_str());
server.send(200, "text/html", wifiCredentialsPage);
}
@ -489,11 +489,10 @@ void handleUDP() {
if (packetSize) {
Serial.print("Received packet2! ize: ");
Serial.println(packetSize);
int len = UDP2.read(UDP2_packet, 60);
int len = UDP2.read(UDP2_packet, 60-1);
UDP2_packet[len] = '\0';
Serial.println("Lol nein");
writeText(UDP2_packet);
}
}

View file

@ -94,6 +94,17 @@ char *lines[] = {
// "this escalated quickly... again",
"rm -rf / --no-preserve-root",
"::1 sweet ::1",
"Cutie Cuddle Club n.e.V.",
"wo ist mein Demogeld?",
"Antifa GmbH Aktion{r*in",
":3",
"Echtzeit-Java",
"Cyber-Technologien",
"IQ: Raumtemperatur",
"Niveau: Subterrain",
"rm -r f/"
"is it real if u can't lick it?",
"Piracy Policy",
};
const size_t num_lines = sizeof(lines)/sizeof(*lines);

View file

@ -35,16 +35,15 @@ void sleep(uint mils) {
void setup() {
Serial.begin(115200);
Serial.println("FastLED");
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
FastLED.setBrightness(255);
// databits 5 + (x & 07) -> x = 2
// docu would be nice
// 7 bits
// even parity
// 2 stopbits?
Serial.println("FastLED");
FastLED.addLeds<WS2812B, DATA_PIN, RGB>(ledsRGB, getRGBWsize(NUM_LEDS));
FastLED.setBrightness(255);
fis.begin(1200, SWSERIAL_7E2);
fillColorW(255, 255, 255, 127);
@ -90,7 +89,7 @@ void loop() {
return;
}
hue = uint8_t(counter);
hue = uint8_t(counter/2);
// rainbow right to left
if(rainbow) {
@ -200,10 +199,9 @@ void writeText(const char text[]) {
void fill_stripes(CRGB a, CRGB b, CRGB c, CRGB d, CRGB e) {
#define stripewidth (NUM_LEDS / 5 / 2)
#define STRIPE(I, VARIABLE) do { \
fillColorFT(stripewidth * I, stripewidth * (I+1), VARIABLE);\
fillColorFT(NUM_LEDS - (stripewidth * (I+1)), NUM_LEDS - (stripewidth * I), VARIABLE);\
} while(0);
#define STRIPE(I, VARIABLE) \
fillColorFT(stripewidth * I, stripewidth * (I+1), VARIABLE); \
fillColorFT(NUM_LEDS - (stripewidth * (I+1)), NUM_LEDS - (stripewidth * I), VARIABLE);
STRIPE(0, a)
STRIPE(1, b)
@ -254,7 +252,7 @@ void progress_color(uint8 r, uint8 g, uint8 b) {
void add_progress() {
progress(progress_status+1, progress_total,
progress_r, progress_g, progress_b);
progress_r, progress_g, progress_b);
}
void set_progress(uint8 x, uint8 of) {
@ -263,7 +261,7 @@ void set_progress(uint8 x, uint8 of) {
void show_progress() {
progress(progress_status, progress_total,
progress_r, progress_g, progress_b);
progress_r, progress_g, progress_b);
}
void progress(uint8 progress, uint8 total, uint8 r, uint8 g, uint8 b) {
@ -277,6 +275,9 @@ void progress(uint8 progress, uint8 total, uint8 r, uint8 g, uint8 b) {
progress_r = r; progress_g = g; progress_b = b;
CRGB c = CRGB(r, g, b);
total = max(total, uint8(1));
uint8_t lastled = progress * NUM_LEDS/2 / total;
for(int i = 0 ; i < NUM_LEDS ; i++ )