cleaner code
This commit is contained in:
		
							
								
								
									
										11
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										11
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							@@ -8,7 +8,16 @@
 | 
			
		||||
        "vector": "cpp",
 | 
			
		||||
        "string_view": "cpp",
 | 
			
		||||
        "initializer_list": "cpp",
 | 
			
		||||
        "ranges": "cpp"
 | 
			
		||||
        "ranges": "cpp",
 | 
			
		||||
        "compare": "cpp",
 | 
			
		||||
        "functional": "cpp",
 | 
			
		||||
        "tuple": "cpp",
 | 
			
		||||
        "type_traits": "cpp",
 | 
			
		||||
        "utility": "cpp",
 | 
			
		||||
        "*.tcc": "cpp",
 | 
			
		||||
        "limits": "cpp",
 | 
			
		||||
        "ostream": "cpp",
 | 
			
		||||
        "streambuf": "cpp"
 | 
			
		||||
    },
 | 
			
		||||
    "C_Cpp.errorSquiggles": "disabled"
 | 
			
		||||
}
 | 
			
		||||
@@ -12,12 +12,16 @@
 | 
			
		||||
platform = https://github.com/maxgerhardt/platform-raspberrypi.git
 | 
			
		||||
board = pico
 | 
			
		||||
framework = arduino
 | 
			
		||||
platform_packages = 
 | 
			
		||||
	framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#master
 | 
			
		||||
board_build.core = earlephilhower
 | 
			
		||||
upload_port = /run/media/amelia/RPI-RP2/
 | 
			
		||||
debug_tool = cmsis-dap
 | 
			
		||||
;upload_protocol = cmsis-dap
 | 
			
		||||
monitor_speed = 115200
 | 
			
		||||
board_build.filesystem_size = 1m
 | 
			
		||||
board_build.f_cpu = 133000000L
 | 
			
		||||
build_flags = -O3
 | 
			
		||||
; board_flags = -DWIFICC=CYW43_COUNTRY_USA
 | 
			
		||||
lib_deps =  
 | 
			
		||||
	https://github.com/FastLED/FastLED
 | 
			
		||||
	https://github.com/FastLED/FastLED#master
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								src/config.h
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								src/config.h
									
									
									
									
									
								
							@@ -11,10 +11,11 @@
 | 
			
		||||
#define MAX_LEDS 170*8
 | 
			
		||||
 | 
			
		||||
// LED driver chip model - depends on strip
 | 
			
		||||
#define LED_TYPE WS2811
 | 
			
		||||
#define LED_TYPE WS2812
 | 
			
		||||
 | 
			
		||||
// RGB pin ordering - RGB, BGR, GBR, etc
 | 
			
		||||
#define RGB_ORDER GBR
 | 
			
		||||
//#define RGB_ORDER GBR
 | 
			
		||||
#define RGB_ORDER GRB
 | 
			
		||||
 | 
			
		||||
// Max number of LED strips connected
 | 
			
		||||
// 8 for ARGB Controller PCB
 | 
			
		||||
@@ -47,15 +48,20 @@
 | 
			
		||||
 | 
			
		||||
#define ETH_SPI_SPD 10000000
 | 
			
		||||
 | 
			
		||||
// Temporary: network and universe settings
 | 
			
		||||
// network and universe settings
 | 
			
		||||
 | 
			
		||||
// Will be replaced with WebUI + EEPROM config
 | 
			
		||||
// WebUI + EEPROM config
 | 
			
		||||
// to allow for changing settings without recompiling
 | 
			
		||||
#define HOSTNAME "Lighting.1"
 | 
			
		||||
#define ETH_MODE "staticip" // comment out for DHCP
 | 
			
		||||
#define IP_ADDR IPAddress(192,168,50,2)
 | 
			
		||||
 | 
			
		||||
extern IPAddress IP_ADDR;
 | 
			
		||||
 | 
			
		||||
extern unsigned short START_UNIVERSE;
 | 
			
		||||
extern char HOSTNAME[64];
 | 
			
		||||
 | 
			
		||||
extern String ETH_MODE;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define update_path "/update"
 | 
			
		||||
#define update_username "admin"
 | 
			
		||||
#define update_password "Password@123"
 | 
			
		||||
 | 
			
		||||
#define START_UNIVERSE 1
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										36
									
								
								src/e131.cpp
									
									
									
									
									
								
							
							
						
						
									
										36
									
								
								src/e131.cpp
									
									
									
									
									
								
							@@ -200,20 +200,15 @@ int E131::beginMulticast(const char *ssid, const char *passphrase,
 | 
			
		||||
int E131::begin() {
 | 
			
		||||
    int retval = 0;
 | 
			
		||||
 | 
			
		||||
    if (Serial) {
 | 
			
		||||
        if(ETH_MODE == "staticip") {
 | 
			
		||||
            Serial.println("");
 | 
			
		||||
            Serial.println("Setting static IP");
 | 
			
		||||
            Serial.println("");
 | 
			
		||||
            eth.config(IP_ADDR, INADDR_NONE);
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            Serial.println("");
 | 
			
		||||
            Serial.println(F("Requesting Address via DHCP"));
 | 
			
		||||
            Serial.println("");
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
    if(ETH_MODE == "staticip") {
 | 
			
		||||
        Serial.println("Setting static IP");
 | 
			
		||||
        eth.config(IP_ADDR, INADDR_NONE);
 | 
			
		||||
    }
 | 
			
		||||
    else {
 | 
			
		||||
        Serial.println(F("Requesting Address via DHCP"));
 | 
			
		||||
    }
 | 
			
		||||
        
 | 
			
		||||
    
 | 
			
		||||
    
 | 
			
		||||
    SPI.setRX(16);
 | 
			
		||||
    SPI.setCS(17);
 | 
			
		||||
@@ -221,24 +216,29 @@ int E131::begin() {
 | 
			
		||||
    SPI.setTX(19);
 | 
			
		||||
    eth.setSPISpeed(ETH_SPI_SPD);
 | 
			
		||||
    lwipPollingPeriod(3);
 | 
			
		||||
    
 | 
			
		||||
    //char * hostname_char;
 | 
			
		||||
    //HOSTNAME.toCharArray(hostname_char, 32);
 | 
			
		||||
    eth.setHostname(HOSTNAME);
 | 
			
		||||
    
 | 
			
		||||
    if (!eth.begin()) {
 | 
			
		||||
        Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
 | 
			
		||||
        return false;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    while (!eth.connected()) {
 | 
			
		||||
    int count = 0;
 | 
			
		||||
    while (!eth.connected() && count < 32) {
 | 
			
		||||
        rp2040.wdt_reset();
 | 
			
		||||
        count++;
 | 
			
		||||
        Serial.print(".");
 | 
			
		||||
        delay(500);
 | 
			
		||||
        delay(250);
 | 
			
		||||
    }
 | 
			
		||||
    retval = eth.connected();
 | 
			
		||||
    if (Serial) {
 | 
			
		||||
        if (retval) {
 | 
			
		||||
            Serial.print(F("\n- IP Address: "));
 | 
			
		||||
            Serial.print(F("\r\n- IP Address: "));
 | 
			
		||||
            Serial.println(eth.localIP());
 | 
			
		||||
        } else {
 | 
			
		||||
            Serial.println(F("** DHCP FAILED"));
 | 
			
		||||
            Serial.println(F("\r\n** DHCP FAILED"));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -26,6 +26,7 @@
 | 
			
		||||
#include "Arduino.h"
 | 
			
		||||
#include "config.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/* Network interface detection.  WiFi for ESP8266 and Ethernet for AVR */
 | 
			
		||||
#ifdef INT_WIFI
 | 
			
		||||
    #include <WiFi.h>
 | 
			
		||||
@@ -41,7 +42,7 @@
 | 
			
		||||
//#   define INT_ETHERNET
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#define NO_DOUBLE_BUFFER 1
 | 
			
		||||
//#define NO_DOUBLE_BUFFER 1
 | 
			
		||||
/* Defaults */
 | 
			
		||||
#define E131_DEFAULT_PORT 5568
 | 
			
		||||
#define WIFI_CONNECT_TIMEOUT 15000  /* 15 seconds */
 | 
			
		||||
@@ -222,6 +223,7 @@ class E131 {
 | 
			
		||||
                stats.last_clientPort = udp.remotePort();
 | 
			
		||||
            } else if (error == ERROR_IGNORE) {
 | 
			
		||||
                // Do nothing
 | 
			
		||||
                return 0;
 | 
			
		||||
            } else {
 | 
			
		||||
                if (Serial)
 | 
			
		||||
                    dumpError(error);
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										604
									
								
								src/main.cpp
									
									
									
									
									
								
							
							
						
						
									
										604
									
								
								src/main.cpp
									
									
									
									
									
								
							@@ -8,9 +8,11 @@
 | 
			
		||||
#include "e131.h"
 | 
			
		||||
#include <FastLED.h>
 | 
			
		||||
#include "config.h"
 | 
			
		||||
#include <EEPROM.h>
 | 
			
		||||
 | 
			
		||||
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
 | 
			
		||||
// Begin code
 | 
			
		||||
bool core1_separate_stack =  true;
 | 
			
		||||
 | 
			
		||||
#ifdef DEBUG
 | 
			
		||||
  #define PRINTFUNC print
 | 
			
		||||
@@ -30,15 +32,16 @@ int pins[8];
 | 
			
		||||
WebServer httpServer(80);
 | 
			
		||||
HTTPUpdateServer httpUpdater;
 | 
			
		||||
bool status = 0;
 | 
			
		||||
int blankcount = 0;
 | 
			
		||||
bool ready = 0;
 | 
			
		||||
bool status2 = 0;
 | 
			
		||||
byte ready = 0;
 | 
			
		||||
bool newconfig = false;
 | 
			
		||||
struct tm timeinfo;
 | 
			
		||||
WiFiServer server(8000);
 | 
			
		||||
String clientbuffer = "";
 | 
			
		||||
String initinfo = "";
 | 
			
		||||
bool debug = 0;
 | 
			
		||||
bool debug = 1;
 | 
			
		||||
bool printer = 1;
 | 
			
		||||
// Colors (RGB)
 | 
			
		||||
int bootsel_count = 0;
 | 
			
		||||
 | 
			
		||||
const uint8_t RED[PIXEL_SIZE]= {0x20, 0x00, 0x00};
 | 
			
		||||
const uint8_t ORANGE[PIXEL_SIZE]= {0x20, 0x10, 0x00};
 | 
			
		||||
@@ -52,14 +55,11 @@ const uint8_t WHITE[PIXEL_SIZE]= {0x20, 0x20, 0x20};
 | 
			
		||||
#define MAX_PIXELS_PER_UNIVERSE 512 / PIXEL_SIZE  /* Number of pixels */
 | 
			
		||||
#define CHANNEL_START 1 /* Channel to start listening at */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
E131 e131;
 | 
			
		||||
 | 
			
		||||
template <class T> T print(T in) {
 | 
			
		||||
  Serial.print(String(in));
 | 
			
		||||
  if(printer) clientbuffer += String(in);
 | 
			
		||||
  status = 1;
 | 
			
		||||
  return (T)true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -69,98 +69,372 @@ template <class T> T println(T in) {
 | 
			
		||||
    clientbuffer += String(in);
 | 
			
		||||
    clientbuffer += "\n";
 | 
			
		||||
  }
 | 
			
		||||
  status = 1;
 | 
			
		||||
  return (T)true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void write_universe(int universe, uint8_t data[]) {
 | 
			
		||||
  // universe starts at 0
 | 
			
		||||
void wipe_eeprom() {
 | 
			
		||||
 | 
			
		||||
  //PRINTFUNC("Universe: ");
 | 
			
		||||
  //PRINTLNFUNC(universe);
 | 
			
		||||
  for(int i = 0; i < 64+16; i++) {
 | 
			
		||||
    EEPROM.write(i, (byte)0);
 | 
			
		||||
  }
 | 
			
		||||
  EEPROM.commit();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IPAddress IP_ADDR;
 | 
			
		||||
 | 
			
		||||
unsigned short START_UNIVERSE;
 | 
			
		||||
char HOSTNAME[64];
 | 
			
		||||
 | 
			
		||||
String ETH_MODE;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
String postForms;
 | 
			
		||||
 | 
			
		||||
void handleRoot() {
 | 
			
		||||
  httpServer.send(200, "text/html", postForms);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void handlePlain() {
 | 
			
		||||
  if (httpServer.method() != HTTP_POST) {
 | 
			
		||||
    httpServer.send(405, "text/plain", "Method Not Allowed");
 | 
			
		||||
  } else {
 | 
			
		||||
    httpServer.send(200, "text/plain", "POST body was:\r\n" + httpServer.arg("plain"));
 | 
			
		||||
    println("POST body was:\r\n" + httpServer.arg("plain"));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void handleForm() {
 | 
			
		||||
  if (httpServer.method() != HTTP_POST) {
 | 
			
		||||
    httpServer.send(405, "text/plain", "Method Not Allowed");
 | 
			
		||||
  } else {
 | 
			
		||||
    String message = "POST form was:\r\n";
 | 
			
		||||
    bool ipset = false;
 | 
			
		||||
    bool reboot = false;
 | 
			
		||||
    for (uint8_t i = 0; i < httpServer.args(); i++) {
 | 
			
		||||
      Serial.println(httpServer.argName(i));
 | 
			
		||||
      if (httpServer.argName(i) == "ipa") {
 | 
			
		||||
        ipset = true;
 | 
			
		||||
      }
 | 
			
		||||
      if (httpServer.argName(i) == "hostname") {
 | 
			
		||||
        println("Updating hostname");
 | 
			
		||||
        for (int j = 0; j < sizeof(HOSTNAME); j++) {
 | 
			
		||||
          if (j < sizeof(httpServer.arg(i)))
 | 
			
		||||
            HOSTNAME[j] = httpServer.arg(i)[j];
 | 
			
		||||
          else
 | 
			
		||||
            HOSTNAME[j] = '\0';
 | 
			
		||||
        }
 | 
			
		||||
        //HOSTNAME = httpServer.arg(i);
 | 
			
		||||
        EEPROM.put(8, HOSTNAME);
 | 
			
		||||
        newconfig = true;
 | 
			
		||||
        //EEPROM.commit();
 | 
			
		||||
      }
 | 
			
		||||
      if (httpServer.argName(i) == "universe") {
 | 
			
		||||
        println("Updating start universe");
 | 
			
		||||
        START_UNIVERSE = (unsigned short)(httpServer.arg(i).toInt());
 | 
			
		||||
        EEPROM.put(4, START_UNIVERSE);
 | 
			
		||||
        newconfig = true;
 | 
			
		||||
        //EEPROM.commit();
 | 
			
		||||
      }
 | 
			
		||||
      if (httpServer.argName(i) == "reboot") {
 | 
			
		||||
        println("Rebooting...");
 | 
			
		||||
        reboot = true;
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\r\n";
 | 
			
		||||
    }
 | 
			
		||||
    if (ipset) {
 | 
			
		||||
      println("Updating IP address...");
 | 
			
		||||
      byte a, b, c, d;
 | 
			
		||||
      for (uint8_t i = 0; i < httpServer.args(); i++) {
 | 
			
		||||
        if (httpServer.argName(i) == "ipa")
 | 
			
		||||
          a = byte(httpServer.arg(i).toInt());
 | 
			
		||||
        if (httpServer.argName(i) == "ipb")
 | 
			
		||||
          b = byte(httpServer.arg(i).toInt());
 | 
			
		||||
        if (httpServer.argName(i) == "ipc")
 | 
			
		||||
          c = byte(httpServer.arg(i).toInt());
 | 
			
		||||
        if (httpServer.argName(i) == "ipd")
 | 
			
		||||
          d = byte(httpServer.arg(i).toInt());
 | 
			
		||||
      }
 | 
			
		||||
 | 
			
		||||
      IP_ADDR = IPAddress(a,b,c,d);
 | 
			
		||||
      EEPROM.write(0, a);
 | 
			
		||||
      EEPROM.write(1, b);
 | 
			
		||||
      EEPROM.write(2, c);
 | 
			
		||||
      EEPROM.write(3, d);
 | 
			
		||||
      newconfig = true;
 | 
			
		||||
    }
 | 
			
		||||
    httpServer.sendHeader("Location", "/",true);  
 | 
			
		||||
    httpServer.send(302, "text/plain", "");
 | 
			
		||||
    //httpServer.send(200, "text/plain", message);
 | 
			
		||||
    println(message);
 | 
			
		||||
    if(reboot) {
 | 
			
		||||
      EEPROM.commit();
 | 
			
		||||
      for (int i = 0; i < MAX_LEDS; i++) {
 | 
			
		||||
        ledstrip[i] = CRGB(0, 0, 0);
 | 
			
		||||
      }
 | 
			
		||||
      FastLED.show();
 | 
			
		||||
      ready = 3; // trigger core 1 to stop
 | 
			
		||||
      delay(250);
 | 
			
		||||
      rp2040.reboot();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void handleNotFound() {
 | 
			
		||||
  String message = "File Not Found\n\n";
 | 
			
		||||
  message += "URI: ";
 | 
			
		||||
  message += httpServer.uri();
 | 
			
		||||
  message += "\nMethod: ";
 | 
			
		||||
  message += (httpServer.method() == HTTP_GET) ? "GET" : "POST";
 | 
			
		||||
  message += "\nArguments: ";
 | 
			
		||||
  message += httpServer.args();
 | 
			
		||||
  message += "\n";
 | 
			
		||||
  for (uint8_t i = 0; i < httpServer.args(); i++) {
 | 
			
		||||
    message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n";
 | 
			
		||||
  }
 | 
			
		||||
  httpServer.send(404, "text/plain", message);
 | 
			
		||||
  println(message);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void write_universe(long universe, uint8_t data[], long size) {
 | 
			
		||||
  // universe starts at 0
 | 
			
		||||
  /*PRINTFUNC("Universe: ");
 | 
			
		||||
  PRINTLNFUNC(universe);
 | 
			
		||||
  PRINTFUNC("Calculate size: ");
 | 
			
		||||
  PRINTLNFUNC(sizeof(calculate));*/
 | 
			
		||||
  int offset = calculate[universe];
 | 
			
		||||
  //PRINTFUNC("Offset: ");
 | 
			
		||||
  //PRINTLNFUNC(offset);
 | 
			
		||||
  /*PRINTFUNC("Offset: ");
 | 
			
		||||
  PRINTLNFUNC(offset);
 | 
			
		||||
  PRINTFUNC("Universes size: ");
 | 
			
		||||
  PRINTLNFUNC(sizeof(universes));*/
 | 
			
		||||
  int write_size = universes[universe];
 | 
			
		||||
  //PRINTFUNC("Length: ");
 | 
			
		||||
  //PRINTLNFUNC(write_size);
 | 
			
		||||
  status = 0;
 | 
			
		||||
  PRINTFUNC("Length: ");
 | 
			
		||||
  PRINTLNFUNC(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
 | 
			
		||||
  PRINTFUNC("Data: ");
 | 
			
		||||
  PRINTLNFUNC(size);
 | 
			
		||||
  if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2 > size) {
 | 
			
		||||
    println("Write size too big!!");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  if(offset + write_size > sizeof(ledstrip)) {
 | 
			
		||||
    println("Write size too big!!");
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  //status = 0;
 | 
			
		||||
  for (int i = 0; i < write_size; i++) {
 | 
			
		||||
    int j = i * PIXEL_SIZE + (CHANNEL_START - 1);
 | 
			
		||||
    //if(debug) {
 | 
			
		||||
    //  PRINTFUNC(data[j]);
 | 
			
		||||
    //  PRINTFUNC(" ");
 | 
			
		||||
    //  PRINTFUNC(data[j+1]);
 | 
			
		||||
    //  PRINTFUNC(" ");
 | 
			
		||||
    //  PRINTFUNC(data[j+2]);
 | 
			
		||||
    //  PRINTFUNC("  ");
 | 
			
		||||
    //}
 | 
			
		||||
    /*if(debug) {
 | 
			
		||||
      PRINTFUNC(data[j]);
 | 
			
		||||
      PRINTFUNC(" ");
 | 
			
		||||
      PRINTFUNC(data[j+1]);
 | 
			
		||||
      PRINTFUNC(" ");
 | 
			
		||||
      PRINTFUNC(data[j+2]);
 | 
			
		||||
      PRINTFUNC("  ");
 | 
			
		||||
    }*/
 | 
			
		||||
    ledstrip[offset + i] = CRGB(data[j], data[j+1], data[j+2]);
 | 
			
		||||
    //ledstrip[strip].setPixelColor(i + offset, data[j], data[j+1], data[j+2]);
 | 
			
		||||
  }
 | 
			
		||||
  status = 1;
 | 
			
		||||
  //FastLED.show();
 | 
			
		||||
  //status = 1;
 | 
			
		||||
  
 | 
			
		||||
  //PRINTLNFUNC("Done writing.");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char* PARAM_INPUT_1 = "ipaddr";
 | 
			
		||||
const char* PARAM_INPUT_2 = "hostname";
 | 
			
		||||
const char* PARAM_INPUT_3 = "universe";
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// HTML web page to handle 3 input fields (input1, input2, input3)
 | 
			
		||||
const char index_html[] PROGMEM = R"rawliteral(
 | 
			
		||||
<!DOCTYPE HTML><html><head>
 | 
			
		||||
  <title>ESP Input Form</title>
 | 
			
		||||
  <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
  </head><body>
 | 
			
		||||
  All settings below will save to EEPROM flash and won't get overridden by a firmware upgrade.
 | 
			
		||||
  Settings will take effect after reboot.
 | 
			
		||||
  <form action="/get">
 | 
			
		||||
    ipaddr: <input type="text" name="IP Address">
 | 
			
		||||
    <input type="submit" value="Submit">
 | 
			
		||||
  </form><br>
 | 
			
		||||
  <form action="/get">
 | 
			
		||||
    hostname: <input type="text" name="Hostname">
 | 
			
		||||
    <input type="submit" value="Submit">
 | 
			
		||||
  </form><br>
 | 
			
		||||
  <form action="/get">
 | 
			
		||||
    universe: <input type="text" name="Start Universe">
 | 
			
		||||
    <input type="submit" value="Submit">
 | 
			
		||||
  </form>
 | 
			
		||||
</body></html>)rawliteral";
 | 
			
		||||
 | 
			
		||||
//void notFound(AsyncWebServerRequest *request) {
 | 
			
		||||
//  request->send(404, "text/plain", "Not found");
 | 
			
		||||
//}
 | 
			
		||||
 | 
			
		||||
void setup() {
 | 
			
		||||
  Serial.begin(115200);
 | 
			
		||||
  //rp2040.wdt_begin(8000);
 | 
			
		||||
  pinMode(24, INPUT); // VBUS detect - check for USB connection
 | 
			
		||||
  if (digitalRead(24)) {
 | 
			
		||||
    delay(3000); // Wait for serial
 | 
			
		||||
  }
 | 
			
		||||
  println("\r\nStarting RGB Controller...");
 | 
			
		||||
  pinMode(20, OUTPUT);
 | 
			
		||||
  println("Resetting W5500 Ethernet Driver...");
 | 
			
		||||
  digitalWrite(20, LOW); // reset W5500 ethernet
 | 
			
		||||
  delay(1);
 | 
			
		||||
  delay(1); // for 1 ms
 | 
			
		||||
  digitalWrite(20, HIGH);
 | 
			
		||||
  SPI.setRX(16);
 | 
			
		||||
  SPI.setCS(17);
 | 
			
		||||
  SPI.setSCK(18);
 | 
			
		||||
  SPI.setTX(19);
 | 
			
		||||
  pinMode(ENABLEPIN, OUTPUT);
 | 
			
		||||
  println("Enabling outputs...");
 | 
			
		||||
  digitalWrite(ENABLEPIN, LOW); // Enable buffer output!
 | 
			
		||||
  //pinMode(0, OUTPUT);
 | 
			
		||||
  //digitalWrite(0, HIGH);
 | 
			
		||||
  Serial.begin(115200);
 | 
			
		||||
  delay(3000);
 | 
			
		||||
  println("========= PicoLighter v1.0 Initializing =========");
 | 
			
		||||
  
 | 
			
		||||
  //delay(3000);
 | 
			
		||||
  println("Checking for EEPROM configuration...");
 | 
			
		||||
  EEPROM.begin(256);
 | 
			
		||||
  //wipe_eeprom();
 | 
			
		||||
  EEPROM.get(4, START_UNIVERSE);
 | 
			
		||||
  if (START_UNIVERSE == 0 || START_UNIVERSE == 65535) {
 | 
			
		||||
    println("No valid config detected. Setting defaults...");
 | 
			
		||||
    START_UNIVERSE = 1;
 | 
			
		||||
    EEPROM.put(4, START_UNIVERSE);
 | 
			
		||||
    EEPROM.commit();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  if(EEPROM.read(8) == byte(0)) { // check if EEPROM is empty
 | 
			
		||||
    char newhostname[] = "RGBController";
 | 
			
		||||
    for (int j = 0; j < sizeof(HOSTNAME); j++) {
 | 
			
		||||
      if (j < sizeof(newhostname))
 | 
			
		||||
        HOSTNAME[j] = newhostname[j];
 | 
			
		||||
      else
 | 
			
		||||
        HOSTNAME[j] = '\0';
 | 
			
		||||
    }
 | 
			
		||||
    EEPROM.put(8, HOSTNAME);
 | 
			
		||||
    EEPROM.commit();
 | 
			
		||||
  }
 | 
			
		||||
  EEPROM.get(8, HOSTNAME);
 | 
			
		||||
  if (HOSTNAME == "") {
 | 
			
		||||
    char newhostname[] = "RGBController";
 | 
			
		||||
    for (int j = 0; j < sizeof(HOSTNAME); j++) {
 | 
			
		||||
      if (j < sizeof(newhostname))
 | 
			
		||||
        HOSTNAME[j] = newhostname[j];
 | 
			
		||||
      else
 | 
			
		||||
        HOSTNAME[j] = '\0';
 | 
			
		||||
    }
 | 
			
		||||
    EEPROM.put(8, HOSTNAME);
 | 
			
		||||
    EEPROM.commit();
 | 
			
		||||
  }
 | 
			
		||||
  IP_ADDR = IPAddress(EEPROM.read(0),EEPROM.read(1),EEPROM.read(2),EEPROM.read(3));
 | 
			
		||||
  if (!IP_ADDR.isSet())
 | 
			
		||||
    ETH_MODE = "dhcp";
 | 
			
		||||
  else
 | 
			
		||||
    ETH_MODE = "staticip";
 | 
			
		||||
  rp2040.wdt_reset();
 | 
			
		||||
 | 
			
		||||
  println("Configuration loaded.");
 | 
			
		||||
  if (!e131.begin()) {
 | 
			
		||||
    println("Connection failed. Retrying.");
 | 
			
		||||
    rp2040.reboot();
 | 
			
		||||
  }
 | 
			
		||||
  while (ready == 0) {
 | 
			
		||||
    delay(100);
 | 
			
		||||
  }
 | 
			
		||||
  #ifdef INT_WIFI
 | 
			
		||||
    WiFi.noLowPowerMode();
 | 
			
		||||
  #endif
 | 
			
		||||
  
 | 
			
		||||
  // If we get here, then network is good to go
 | 
			
		||||
  println("Starting mDNS client...");
 | 
			
		||||
  MDNS.begin(HOSTNAME);
 | 
			
		||||
  println("Starting web configurator & firmware update service...");
 | 
			
		||||
 | 
			
		||||
  httpUpdater.setup(&httpServer, update_path, update_username, update_password);
 | 
			
		||||
 | 
			
		||||
  httpServer.on("/", handleRoot);
 | 
			
		||||
 | 
			
		||||
  httpServer.on("/postplain/", handlePlain);
 | 
			
		||||
  postForms = "<html>\
 | 
			
		||||
  <head>\
 | 
			
		||||
    <title>RGB Controller Configuration</title>\
 | 
			
		||||
    <style>\
 | 
			
		||||
      body { background-color: #cccccc; font-family: Arial, Helvetica, Sans-Serif; Color: #000088; }\
 | 
			
		||||
    </style>\
 | 
			
		||||
  </head>\
 | 
			
		||||
  <body>\
 | 
			
		||||
    <h1>RGB Controller Configuration</h1><br>\
 | 
			
		||||
    <h2>Set IP address</h2>\
 | 
			
		||||
    Needs reboot to apply<br>\
 | 
			
		||||
    Set to 0.0.0.0 for DHCP\
 | 
			
		||||
    <form method=\"post\" enctype=\"application/x-www-form-urlencoded\" action=\"/postform/\">\
 | 
			
		||||
      <input type=\"text\" name=\"ipa\" value=\"0\" size=\"3\">.\
 | 
			
		||||
      <input type=\"text\" name=\"ipb\" value=\"0\" size=\"3\">.\
 | 
			
		||||
      <input type=\"text\" name=\"ipc\" value=\"0\" size=\"3\">.\
 | 
			
		||||
      <input type=\"text\" name=\"ipd\" value=\"0\" size=\"3\">\
 | 
			
		||||
      <input type=\"submit\" value=\"Set\">\
 | 
			
		||||
    </form><br>\
 | 
			
		||||
    <h2>Set Hostname</h2>\
 | 
			
		||||
    Needs reboot to apply<br>\
 | 
			
		||||
    Max 64 characters\
 | 
			
		||||
    <form method=\"post\" enctype=\"application/x-www-form-urlencoded\" action=\"/postform/\">\
 | 
			
		||||
      <input type=\"text\" name=\"hostname\" value=\"" + String(HOSTNAME) + "\" size=\"20\">\
 | 
			
		||||
      <input type=\"submit\" value=\"Set\">\
 | 
			
		||||
    </form><br>\
 | 
			
		||||
    <h2>DMX512 Start Universe</h2>\
 | 
			
		||||
    Applies immediately<br>\
 | 
			
		||||
    Between (inclusive) 1-65000\
 | 
			
		||||
    <form method=\"post\" enctype=\"application/x-www-form-urlencoded\" action=\"/postform/\">\
 | 
			
		||||
      <input type=\"text\" name=\"universe\" value=\"" + String(START_UNIVERSE) + "\" size=\"5\">\
 | 
			
		||||
      <input type=\"submit\" value=\"Set\">\
 | 
			
		||||
    </form><br>\
 | 
			
		||||
    <form method=\"post\" enctype=\"application/x-www-form-urlencoded\" action=\"/postform/\">\
 | 
			
		||||
      <input type=\"submit\" name=\"reboot\" value=\"Reboot\">\
 | 
			
		||||
    </form><br>\
 | 
			
		||||
  </body>\
 | 
			
		||||
</html>";
 | 
			
		||||
  httpServer.on("/postform/", handleForm);
 | 
			
		||||
 | 
			
		||||
  httpServer.onNotFound(handleNotFound);
 | 
			
		||||
 | 
			
		||||
  httpServer.begin();
 | 
			
		||||
  MDNS.addService("http", "tcp", 80);
 | 
			
		||||
  print("OTA Updates enabled. Open http://");
 | 
			
		||||
  print(HOSTNAME);
 | 
			
		||||
  print(update_path);
 | 
			
		||||
  print(" in your browser and login with username ");
 | 
			
		||||
  print(update_username);
 | 
			
		||||
  print(" and password ");
 | 
			
		||||
  println(update_password);
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  if(ENABLE_NTP) {
 | 
			
		||||
    println("Starting NTP client.");
 | 
			
		||||
    NTP.begin(ntpserver);
 | 
			
		||||
    NTP.waitSet([]() { print("."); }, 15000);
 | 
			
		||||
    time_t now = time(nullptr);
 | 
			
		||||
    println("");
 | 
			
		||||
    gmtime_r(&now, &timeinfo);
 | 
			
		||||
    print("Current time: ");
 | 
			
		||||
    println(asctime(&timeinfo));
 | 
			
		||||
  }
 | 
			
		||||
  ready += 1;
 | 
			
		||||
  while (ready == 1) {
 | 
			
		||||
    delay(50);
 | 
			
		||||
  }
 | 
			
		||||
  println("Startup Complete. Listening for HTTP and e1.31 (sACN) connections...");
 | 
			
		||||
  initinfo += clientbuffer;
 | 
			
		||||
    //e131.beginMulticast(ssid, passphrase, UNIVERSE);  
 | 
			
		||||
  printer = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void setup1() {
 | 
			
		||||
  while(ready == 0)
 | 
			
		||||
    delay(50);
 | 
			
		||||
  pinMode(LED_BUILTIN, OUTPUT);
 | 
			
		||||
  pinMode(32+1, OUTPUT);
 | 
			
		||||
  digitalWrite(LED_BUILTIN, HIGH);
 | 
			
		||||
  println("Initializing LED outputs and universe mappings...");
 | 
			
		||||
 | 
			
		||||
  #ifdef STRIP1
 | 
			
		||||
    pins[0] = STRIP1;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP2
 | 
			
		||||
    pins[1] = STRIP2;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP3
 | 
			
		||||
    pins[2] = STRIP3;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP4
 | 
			
		||||
    pins[3] = STRIP4;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP5
 | 
			
		||||
    pins[4] = STRIP5;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP6
 | 
			
		||||
    pins[5] = STRIP6;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP7
 | 
			
		||||
    pins[6] = STRIP7;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP8
 | 
			
		||||
    pins[7] = STRIP8;
 | 
			
		||||
  #endif
 | 
			
		||||
  // Populate universes and offsets
 | 
			
		||||
  int offsetcount = 0;
 | 
			
		||||
  int currentsize = 0;
 | 
			
		||||
@@ -179,7 +453,7 @@ void setup() {
 | 
			
		||||
      calculate[currentsize] = offsetcount;
 | 
			
		||||
      
 | 
			
		||||
      PRINTFUNC("  Universe ");
 | 
			
		||||
      PRINTFUNC(currentsize + 1 + START_UNIVERSE);
 | 
			
		||||
      PRINTFUNC(currentsize + START_UNIVERSE);
 | 
			
		||||
      PRINTFUNC(", Light count ");
 | 
			
		||||
      PRINTFUNC(MAX_PIXELS_PER_UNIVERSE);
 | 
			
		||||
      PRINTFUNC(", Size ");
 | 
			
		||||
@@ -191,7 +465,7 @@ void setup() {
 | 
			
		||||
    universes[currentsize] = tmp;
 | 
			
		||||
    calculate[currentsize] = offsetcount;
 | 
			
		||||
    PRINTFUNC("  Universe ");
 | 
			
		||||
    PRINTFUNC(currentsize + 1 + START_UNIVERSE);
 | 
			
		||||
    PRINTFUNC(currentsize + START_UNIVERSE);
 | 
			
		||||
    PRINTFUNC(", Light count ");
 | 
			
		||||
    PRINTFUNC(tmp);
 | 
			
		||||
    PRINTFUNC(", Size ");
 | 
			
		||||
@@ -199,118 +473,123 @@ void setup() {
 | 
			
		||||
    offsetcount += tmp;
 | 
			
		||||
    currentsize += 1;
 | 
			
		||||
  }       
 | 
			
		||||
  println("========= PicoLighter v1.0 Initialized =========");
 | 
			
		||||
  initinfo += clientbuffer;
 | 
			
		||||
    //e131.beginMulticast(ssid, passphrase, UNIVERSE);  
 | 
			
		||||
  ready = 0;
 | 
			
		||||
  printer = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void setup1() {
 | 
			
		||||
  pinMode(LED_BUILTIN, OUTPUT);
 | 
			
		||||
  pinMode(32+1, OUTPUT);
 | 
			
		||||
  digitalWrite(LED_BUILTIN, HIGH);
 | 
			
		||||
  #ifdef STRIP1
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP1, RGB_ORDER>(ledstrip, calculate[0], strips[0]);
 | 
			
		||||
    pins[0] = STRIP1;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP2
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP2, RGB_ORDER>(ledstrip, calculate[1], strips[1]);
 | 
			
		||||
    pins[1] = STRIP2;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP3
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP3, RGB_ORDER>(ledstrip, calculate[2], strips[2]);
 | 
			
		||||
    pins[2] = STRIP3;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP4
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP4, RGB_ORDER>(ledstrip, calculate[3], strips[3]);
 | 
			
		||||
    pins[3] = STRIP4;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP5
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP5, RGB_ORDER>(ledstrip, calculate[4], strips[4]);
 | 
			
		||||
    pins[4] = STRIP5;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP6
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP6, RGB_ORDER>(ledstrip, calculate[5], strips[5]);
 | 
			
		||||
    pins[5] = STRIP6;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP7
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP7, RGB_ORDER>(ledstrip, calculate[6], strips[6]);
 | 
			
		||||
    pins[6] = STRIP7;
 | 
			
		||||
  #endif
 | 
			
		||||
  #ifdef STRIP8
 | 
			
		||||
    FastLED.addLeds<LED_TYPE, STRIP8, RGB_ORDER>(ledstrip, calculate[7], strips[7]);
 | 
			
		||||
    pins[7] = STRIP8;
 | 
			
		||||
  #endif
 | 
			
		||||
  // Test all lights
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  for (int i = 0; i < MAX_LEDS; i++) {
 | 
			
		||||
    ledstrip[i] = CRGB(0, 0, 50);
 | 
			
		||||
    FastLED.show();
 | 
			
		||||
    delay(1);
 | 
			
		||||
    ledstrip[i] = CRGB(0, 0, 0);
 | 
			
		||||
  }
 | 
			
		||||
  FastLED.show();
 | 
			
		||||
  // Test all lights
 | 
			
		||||
  /*for (int i = 0; i < MAX_LEDS; i++) {
 | 
			
		||||
    ledstrip[i] = CRGB(0, 0, 50);
 | 
			
		||||
    FastLED.show();
 | 
			
		||||
    //delay(1);
 | 
			
		||||
    ledstrip[i] = CRGB(0, 0, 0);
 | 
			
		||||
  }
 | 
			
		||||
  FastLED.show();*/
 | 
			
		||||
  //delay(3000);
 | 
			
		||||
  #ifdef INT_WIFI
 | 
			
		||||
    WiFi.noLowPowerMode();
 | 
			
		||||
  #endif
 | 
			
		||||
  ready = 1;
 | 
			
		||||
  
 | 
			
		||||
  ready += 1;
 | 
			
		||||
  while (ready == 1) {
 | 
			
		||||
    delay(100);
 | 
			
		||||
    delay(50);
 | 
			
		||||
  }
 | 
			
		||||
  // If we get here, then network is good to go
 | 
			
		||||
  println("Starting mDNS client.");
 | 
			
		||||
  MDNS.begin(HOSTNAME);
 | 
			
		||||
  httpUpdater.setup(&httpServer, update_path, update_username, update_password);
 | 
			
		||||
 | 
			
		||||
  httpServer.begin();
 | 
			
		||||
  MDNS.addService("http", "tcp", 80);
 | 
			
		||||
  print("OTA Updates enabled. Open http://");
 | 
			
		||||
  print(HOSTNAME);
 | 
			
		||||
  print(update_path);
 | 
			
		||||
  print(" in your browser and login with username ");
 | 
			
		||||
  print(update_username);
 | 
			
		||||
  print(" and password ");
 | 
			
		||||
  println(update_password);
 | 
			
		||||
  server.begin();
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  if(ENABLE_NTP) {
 | 
			
		||||
    println("Starting NTP client.");
 | 
			
		||||
    NTP.begin(ntpserver);
 | 
			
		||||
    NTP.waitSet([]() { print("."); }, 15000);
 | 
			
		||||
    time_t now = time(nullptr);
 | 
			
		||||
    println("");
 | 
			
		||||
    gmtime_r(&now, &timeinfo);
 | 
			
		||||
    print("Current time: ");
 | 
			
		||||
    println(asctime(&timeinfo));
 | 
			
		||||
  }
 | 
			
		||||
  //rp2040.wdt_begin(8000);
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
  /* Parse a packet and update pixels */
 | 
			
		||||
    if(e131.parsePacket()) {
 | 
			
		||||
      // Offset by start universe
 | 
			
		||||
      // as all local functions count from 0
 | 
			
		||||
      write_universe(e131.universe - START_UNIVERSE, e131.data);
 | 
			
		||||
    }
 | 
			
		||||
    else if (blankcount > 1000) {
 | 
			
		||||
        status = 0;
 | 
			
		||||
        blankcount = 0;
 | 
			
		||||
    } else {
 | 
			
		||||
      blankcount ++;
 | 
			
		||||
  /* Parse a packet */
 | 
			
		||||
  println("Start loop");
 | 
			
		||||
  int channels = 0;
 | 
			
		||||
  if(channels = e131.parsePacket()) {
 | 
			
		||||
    // Offset by start universe
 | 
			
		||||
    // as all local functions count from 0
 | 
			
		||||
    status = 0;
 | 
			
		||||
    if(e131.universe > START_UNIVERSE - 1) {
 | 
			
		||||
      while (status2 == 1) {
 | 
			
		||||
        delay(0);
 | 
			
		||||
      }
 | 
			
		||||
      write_universe(e131.universe - START_UNIVERSE, e131.data, channels);
 | 
			
		||||
      println("Done Writing");
 | 
			
		||||
    }
 | 
			
		||||
    status = 1;
 | 
			
		||||
  }
 | 
			
		||||
  println("mid loop");
 | 
			
		||||
  httpServer.handleClient();
 | 
			
		||||
  MDNS.update();
 | 
			
		||||
  println("end loop");
 | 
			
		||||
  if(newconfig == true) {
 | 
			
		||||
    println("Waiting for core 1 to idle...");
 | 
			
		||||
    ready = 3;
 | 
			
		||||
    while(ready == 3)
 | 
			
		||||
      delay(50);
 | 
			
		||||
    println("Configuration changed - saving to flash...");
 | 
			
		||||
    EEPROM.commit();
 | 
			
		||||
    newconfig = false;
 | 
			
		||||
    ready = 2;
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop1() {
 | 
			
		||||
  if(status == 1) {
 | 
			
		||||
    FastLED.show();
 | 
			
		||||
  rp2040.wdt_reset();
 | 
			
		||||
  if(BOOTSEL) {
 | 
			
		||||
    bootsel_count++;
 | 
			
		||||
    delay(50);
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    bootsel_count = 0;
 | 
			
		||||
  }
 | 
			
		||||
  if(bootsel_count > 60) { // 3 seconds
 | 
			
		||||
    Serial.print("Wiping configuration...");
 | 
			
		||||
    digitalWrite(LED_BUILTIN, LOW);
 | 
			
		||||
    delay(50);
 | 
			
		||||
    for(int i = 0; i < 5; i++) { // blink 5 times to indicate wipe
 | 
			
		||||
      digitalWrite(LED_BUILTIN, HIGH);
 | 
			
		||||
      delay(125);
 | 
			
		||||
      digitalWrite(LED_BUILTIN, LOW);
 | 
			
		||||
      delay(125);
 | 
			
		||||
    }
 | 
			
		||||
    wipe_eeprom();
 | 
			
		||||
    rp2040.reboot();
 | 
			
		||||
    
 | 
			
		||||
  }
 | 
			
		||||
  if(ready == 3) {
 | 
			
		||||
    ready = 4;
 | 
			
		||||
    while(ready == 4)
 | 
			
		||||
      delay(50);
 | 
			
		||||
  }
 | 
			
		||||
  if(status == 1) {
 | 
			
		||||
    status2 = 1;
 | 
			
		||||
    FastLED.show();
 | 
			
		||||
    status2 = 0;
 | 
			
		||||
  }
 | 
			
		||||
  httpServer.handleClient();
 | 
			
		||||
  MDNS.update();
 | 
			
		||||
  if (millis() % 100 > 50) { // reset LED
 | 
			
		||||
    digitalWrite(LED_BUILTIN, HIGH);
 | 
			
		||||
  }
 | 
			
		||||
@@ -320,55 +599,18 @@ void loop1() {
 | 
			
		||||
  }
 | 
			
		||||
  //status = 0;
 | 
			
		||||
  //delay(50);
 | 
			
		||||
  float temp = analogReadTemp();
 | 
			
		||||
  if (temp > 50.0) {
 | 
			
		||||
  float cputemp = analogReadTemp();
 | 
			
		||||
  if (cputemp > 50.0) {
 | 
			
		||||
    println("ERROR: Overtemperature triggered!");
 | 
			
		||||
    rp2040.reboot();
 | 
			
		||||
  }
 | 
			
		||||
  WiFiClient client = server.available();
 | 
			
		||||
  if (client) {
 | 
			
		||||
    PRINTLNFUNC("Client connected");
 | 
			
		||||
    clientbuffer = "";
 | 
			
		||||
    printer = 1;
 | 
			
		||||
    client.println(initinfo);
 | 
			
		||||
    client.println("Press d + ENTER to toggle RGB debug.");
 | 
			
		||||
    while (client.connected()) {
 | 
			
		||||
      if(status == 1) {
 | 
			
		||||
        FastLED.show();
 | 
			
		||||
      }
 | 
			
		||||
      httpServer.handleClient();
 | 
			
		||||
      MDNS.update();
 | 
			
		||||
      if (millis() % 100 > 50) { // reset LED
 | 
			
		||||
        digitalWrite(LED_BUILTIN, HIGH);
 | 
			
		||||
      }
 | 
			
		||||
      else if (millis() % 100 < 50 && status == 1) {
 | 
			
		||||
        //status = 0;
 | 
			
		||||
        digitalWrite(LED_BUILTIN, LOW);
 | 
			
		||||
      }
 | 
			
		||||
      //status = 0;
 | 
			
		||||
      //delay(50);
 | 
			
		||||
      float temp = analogReadTemp(); // read temp in celsius
 | 
			
		||||
      if (temp > 50.0) {
 | 
			
		||||
        println("ERROR: Overtemperature triggered!");
 | 
			
		||||
        rp2040.reboot();
 | 
			
		||||
      }
 | 
			
		||||
      if(clientbuffer != (String) "") {
 | 
			
		||||
        client.print(clientbuffer);
 | 
			
		||||
        clientbuffer = "";
 | 
			
		||||
      }
 | 
			
		||||
      while(client.available()) {
 | 
			
		||||
        char c = client.read();
 | 
			
		||||
        if (c == 'd') {
 | 
			
		||||
          if (debug == 1) {
 | 
			
		||||
            debug = 0;
 | 
			
		||||
          } else {
 | 
			
		||||
            debug = 1;
 | 
			
		||||
          }
 | 
			
		||||
        }
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
    client.stop();
 | 
			
		||||
    printer = 0;
 | 
			
		||||
  }
 | 
			
		||||
  
 | 
			
		||||
  float envtemp = analogRead(28);
 | 
			
		||||
  envtemp = envtemp / 1024.0 * 3300; // voltage in mV
 | 
			
		||||
  envtemp /= 10.0; // 10.0 mv/C
 | 
			
		||||
  envtemp -= 50; // offset 500mV = 0C
 | 
			
		||||
 | 
			
		||||
  // TODO: report temps somehow to dashboard
 | 
			
		||||
  
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user