|
|
@ -1,159 +1,737 @@
|
|
|
|
#include <Arduino.h>
|
|
|
|
// Includes
|
|
|
|
|
|
|
|
//#include <WiFi.h>
|
|
|
|
|
|
|
|
//#include <WiFiServer.h>
|
|
|
|
#include <W5500lwIP.h>
|
|
|
|
#include <W5500lwIP.h>
|
|
|
|
#include <LEAmDNS.h>
|
|
|
|
#include <LEAmDNS.h>
|
|
|
|
#include <WebServer.h>
|
|
|
|
|
|
|
|
#include <HTTPUpdateServer.h>
|
|
|
|
#include <HTTPUpdateServer.h>
|
|
|
|
|
|
|
|
#include <WebServer.h>
|
|
|
|
|
|
|
|
#include "e131.h"
|
|
|
|
|
|
|
|
//#include <Adafruit_NeoPixel.h>
|
|
|
|
|
|
|
|
#include <Adafruit_NeoPXL8.h>
|
|
|
|
|
|
|
|
//#include <FastLED.h>
|
|
|
|
|
|
|
|
//#include "FastLED_RGBW.h"
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <EEPROM.h>
|
|
|
|
#include <pico/stdlib.h>
|
|
|
|
#include <pico/stdlib.h>
|
|
|
|
#include <hardware/vreg.h>
|
|
|
|
#include <hardware/vreg.h>
|
|
|
|
|
|
|
|
|
|
|
|
# include <lwip/ip_addr.h>
|
|
|
|
|
|
|
|
# include <lwip/igmp.h>
|
|
|
|
|
|
|
|
# define _UDP WiFiUDP
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Begin code
|
|
|
|
// Begin code
|
|
|
|
bool core1_separate_stack = true;
|
|
|
|
//bool core1_separate_stack = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
|
|
|
|
#define PRINTFUNC print
|
|
|
|
|
|
|
|
#define PRINTLNFUNC println
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define PRINTFUNC
|
|
|
|
|
|
|
|
#define PRINTLNFUNC
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int calculate[LED_STRIPS * 4];
|
|
|
|
|
|
|
|
int universes[LED_STRIPS * 4];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int strips[LED_STRIPS] = {MAX_LEDS, MAX_LEDS, MAX_LEDS, MAX_LEDS, MAX_LEDS, MAX_LEDS, MAX_LEDS, MAX_LEDS}; // for compatibility
|
|
|
|
|
|
|
|
int8_t pins[LED_STRIPS] = {STRIP1, STRIP2, STRIP3, STRIP4, STRIP5, STRIP6, STRIP7, STRIP8};
|
|
|
|
|
|
|
|
//const int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
|
|
|
|
|
|
|
//int offsets[(LED_STRIPS+1)];
|
|
|
|
|
|
|
|
Adafruit_NeoPXL8 leds(170, pins, RGB_ORDER);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// #ifdef RGBW_MODE
|
|
|
|
|
|
|
|
// // EVIL! hack to support RGBW ICs
|
|
|
|
|
|
|
|
// CRGBW leds[MAX_LEDS];
|
|
|
|
|
|
|
|
// CRGB *ledstrip = (CRGB *) &leds[0]; // yes, we just casted a 4-byte value array to a pseudo 3-byte value array
|
|
|
|
|
|
|
|
// int strips[LED_STRIPS] = {getRGBWsize(128), getRGBWsize(128), getRGBWsize(128), getRGBWsize(128), getRGBWsize(128), getRGBWsize(128), getRGBWsize(128), getRGBWsize(128)};
|
|
|
|
|
|
|
|
// #else
|
|
|
|
|
|
|
|
// int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
|
|
|
|
|
|
|
// CRGB ledstrip[MAX_LEDS];
|
|
|
|
|
|
|
|
// #endif
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t raw[4096];
|
|
|
|
|
|
|
|
_UDP udp;
|
|
|
|
uint8_t * livedata;
|
|
|
|
int nopackets = 0;
|
|
|
|
// Networking
|
|
|
|
Wiznet5500lwIP eth(17, SPI, 21); // 17 : CS, 21 : INTn
|
|
|
|
|
|
|
|
// don't think the interrupt pin is actually used
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WebServer httpServer(80);
|
|
|
|
WebServer httpServer(80);
|
|
|
|
HTTPUpdateServer httpUpdater;
|
|
|
|
HTTPUpdateServer httpUpdater;
|
|
|
|
|
|
|
|
bool status = 0;
|
|
|
|
|
|
|
|
bool status2 = 0;
|
|
|
|
|
|
|
|
byte ready = 0;
|
|
|
|
|
|
|
|
bool newconfig = false;
|
|
|
|
|
|
|
|
struct tm timeinfo;
|
|
|
|
|
|
|
|
String clientbuffer = "";
|
|
|
|
|
|
|
|
String initinfo = "";
|
|
|
|
|
|
|
|
bool debug = 1;
|
|
|
|
|
|
|
|
bool printer = 1;
|
|
|
|
|
|
|
|
int channels = 0;
|
|
|
|
|
|
|
|
// Colors (RGB)
|
|
|
|
|
|
|
|
int bootsel_count = 0;
|
|
|
|
|
|
|
|
int nopackets = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const uint8_t RED[PIXEL_SIZE]= {0x20, 0x00, 0x00};
|
|
|
|
|
|
|
|
const uint8_t ORANGE[PIXEL_SIZE]= {0x20, 0x10, 0x00};
|
|
|
|
|
|
|
|
const uint8_t YELLOW[PIXEL_SIZE]= {0x20, 0x20, 0x00};
|
|
|
|
|
|
|
|
const uint8_t GREEN[PIXEL_SIZE]= {0x00, 0x20, 0x00};
|
|
|
|
|
|
|
|
const uint8_t CYAN[PIXEL_SIZE]= {0x00, 0x20, 0x20};
|
|
|
|
|
|
|
|
const uint8_t BLUE[PIXEL_SIZE]= {0x00, 0x00, 0x20};
|
|
|
|
|
|
|
|
const uint8_t PURPLE[PIXEL_SIZE]= {0x20, 0x00, 0x20};
|
|
|
|
|
|
|
|
const uint8_t BLACK[PIXEL_SIZE]= {0x00, 0x00, 0x00};
|
|
|
|
|
|
|
|
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 */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Wiznet5500lwIP eth(17, SPI, 21); //, 21); // 17 : cs, 21 : INTn
|
|
|
|
|
|
|
|
E131 e131;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
float cputemparray[TEMP_SAMPLES];
|
|
|
|
|
|
|
|
float airtemparray[TEMP_SAMPLES];
|
|
|
|
|
|
|
|
float cputemp;
|
|
|
|
|
|
|
|
float airtemp;
|
|
|
|
|
|
|
|
int datapos = 0;
|
|
|
|
|
|
|
|
#ifdef RGBW_MODE
|
|
|
|
|
|
|
|
inline void setpixelrgb(int idx, byte r, byte g, byte b, byte w) {
|
|
|
|
|
|
|
|
leds.setPixelColor(idx, r, g, b, w);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
inline void setpixelrgb(int idx, byte r, byte g, byte b) {
|
|
|
|
|
|
|
|
leds.setPixelColor(idx, r, g, b);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
inline void showpixels() {
|
|
|
|
|
|
|
|
leds.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T> T print(T in) {
|
|
|
|
|
|
|
|
if(Serial)
|
|
|
|
|
|
|
|
Serial.print(String(millis()/1000.0) + ": " + String(in));
|
|
|
|
|
|
|
|
if(printer) clientbuffer += String(in);
|
|
|
|
|
|
|
|
return (T)true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> T println(T in) {
|
|
|
|
|
|
|
|
if(Serial)
|
|
|
|
|
|
|
|
Serial.println(String(millis()/1000.0) + ": " + String(in));
|
|
|
|
|
|
|
|
if(printer) {
|
|
|
|
|
|
|
|
clientbuffer += String(in);
|
|
|
|
|
|
|
|
clientbuffer += "\n";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return (T)true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void initUnicast() {
|
|
|
|
void wipe_eeprom() {
|
|
|
|
delay(100);
|
|
|
|
|
|
|
|
udp.begin(5568);
|
|
|
|
for(int i = 0; i < 64+16; i++) {
|
|
|
|
if (Serial) {
|
|
|
|
EEPROM.write(i, (byte)0);
|
|
|
|
Serial.print(F("- Unicast port: "));
|
|
|
|
}
|
|
|
|
Serial.println(5568);
|
|
|
|
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++) {
|
|
|
|
|
|
|
|
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++) {
|
|
|
|
|
|
|
|
setpixelrgb(i, 0, 0, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showpixels();
|
|
|
|
|
|
|
|
ready = 3; // trigger core 1 to stop
|
|
|
|
|
|
|
|
delay(250);
|
|
|
|
|
|
|
|
rp2040.reboot();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int readPacket() {
|
|
|
|
void handleNotFound() {
|
|
|
|
int size = udp.parsePacket();
|
|
|
|
String message = "File Not Found\n\n";
|
|
|
|
if (size) {
|
|
|
|
message += "URI: ";
|
|
|
|
udp.readBytes(raw, size);
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*else {
|
|
|
|
httpServer.send(404, "text/plain", message);
|
|
|
|
Serial.println("Error: packet size " + String(size));
|
|
|
|
println(message);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
|
|
|
|
// universe starts at 0
|
|
|
|
|
|
|
|
//print("Universe: ");
|
|
|
|
|
|
|
|
//Serial.println(universe);
|
|
|
|
|
|
|
|
//print("Calculate size: ");
|
|
|
|
|
|
|
|
//Serial.println(sizeof(calculate));
|
|
|
|
|
|
|
|
int offset = calculate[universe];
|
|
|
|
|
|
|
|
//print("Offset: ");
|
|
|
|
|
|
|
|
//Serial.println(offset);
|
|
|
|
|
|
|
|
//print("Universes size: ");
|
|
|
|
|
|
|
|
//Serial.println(sizeof(universes));
|
|
|
|
|
|
|
|
int write_size = universes[universe];
|
|
|
|
|
|
|
|
/*print("Length: ");
|
|
|
|
|
|
|
|
Serial.println(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
|
|
|
|
|
|
|
|
print("Data: ");
|
|
|
|
|
|
|
|
Serial.println(size);*/
|
|
|
|
|
|
|
|
if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) > size) {
|
|
|
|
|
|
|
|
println("Write size too big!!");
|
|
|
|
|
|
|
|
println(String(write_size * PIXEL_SIZE + (CHANNEL_START - 1)) + " with data size " + String(size));
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*if(offset + write_size > sizeof(ledstrip)) {
|
|
|
|
|
|
|
|
println("Write size too big!!");
|
|
|
|
|
|
|
|
println(String(offset + write_size) + " with strip size " + sizeof(ledstrip));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
}*/
|
|
|
|
}*/
|
|
|
|
return size;
|
|
|
|
//status = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < write_size; i++) {
|
|
|
|
|
|
|
|
int j = i * PIXEL_SIZE + (CHANNEL_START - 1);
|
|
|
|
|
|
|
|
/*if(debug) {
|
|
|
|
|
|
|
|
Serial.print(data[j]);
|
|
|
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
|
|
|
Serial.print(data[j+1]);
|
|
|
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
|
|
|
Serial.print(data[j+2]);
|
|
|
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
#ifdef RGBW_MODE
|
|
|
|
|
|
|
|
setpixelrgb(offset + i, data[j], data[j+1], data[j+2]);
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
setpixelrgb(offset + i, data[j], data[j+1], data[j+2]);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//ledstrip[strip].setPixelColor(i + offset, data[j], data[j+1], data[j+2]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
//FastLED.show();
|
|
|
|
|
|
|
|
//status = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//println("Done writing.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
//vreg_voltage v = VREG_VOLTAGE_1_20;
|
|
|
|
vreg_voltage v = VREG_VOLTAGE_1_20;
|
|
|
|
//vreg_set_voltage(v);
|
|
|
|
vreg_set_voltage(v);
|
|
|
|
//set_sys_clock_khz(252000, false); // play with this value
|
|
|
|
set_sys_clock_khz(252000, false);
|
|
|
|
|
|
|
|
pinMode(23, OUTPUT);
|
|
|
|
|
|
|
|
pinMode(23, HIGH);
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.begin(115200);
|
|
|
|
//rp2040.wdt_begin(8000);
|
|
|
|
//rp2040.wdt_begin(8000);
|
|
|
|
|
|
|
|
|
|
|
|
pinMode(24, INPUT); // VBUS detect - check for USB connection
|
|
|
|
pinMode(24, INPUT); // VBUS detect - check for USB connection
|
|
|
|
if (digitalRead(24)) {
|
|
|
|
if (digitalRead(24)) {
|
|
|
|
delay(3000); // Wait for USB serial if connected
|
|
|
|
delay(3000); // Wait for serial
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.println("\r\nStarting RGB Controller...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pinMode(21, INPUT); // interrupt pin - probably unused
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pinMode(20, OUTPUT); // W5500 RSTn wired to 20
|
|
|
|
pinMode(21, INPUT); // interrupt for W500
|
|
|
|
Serial.println("Resetting W5500 Ethernet Driver...");
|
|
|
|
Serial.println("");
|
|
|
|
|
|
|
|
println("Starting RGB Controller...");
|
|
|
|
|
|
|
|
pinMode(20, OUTPUT);
|
|
|
|
|
|
|
|
println("Resetting W5500 Ethernet Driver...");
|
|
|
|
digitalWrite(20, LOW); // reset W5500 ethernet
|
|
|
|
digitalWrite(20, LOW); // reset W5500 ethernet
|
|
|
|
delay(1); // for 1 ms
|
|
|
|
delay(1); // for 1 ms
|
|
|
|
digitalWrite(20, HIGH);
|
|
|
|
digitalWrite(20, HIGH);
|
|
|
|
|
|
|
|
|
|
|
|
SPI.setRX(16);
|
|
|
|
SPI.setRX(16);
|
|
|
|
SPI.setCS(17);
|
|
|
|
SPI.setCS(17);
|
|
|
|
SPI.setSCK(18);
|
|
|
|
SPI.setSCK(18);
|
|
|
|
SPI.setTX(19);
|
|
|
|
SPI.setTX(19);
|
|
|
|
eth.setSPISpeed(10000000); // play with this value
|
|
|
|
pinMode(ENABLEPIN, OUTPUT);
|
|
|
|
lwipPollingPeriod(3); // play with this value
|
|
|
|
println("Enabling outputs...");
|
|
|
|
eth.setHostname("RGBController");
|
|
|
|
digitalWrite(ENABLEPIN, LOW); // Enable buffer output!
|
|
|
|
|
|
|
|
//pinMode(0, OUTPUT);
|
|
|
|
Serial.println(F("Setting IP"));
|
|
|
|
//digitalWrite(0, HIGH);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//eth.config(IPAddress(192,168,68,130), INADDR_NONE); // static IP; comment out for DHCP
|
|
|
|
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));
|
|
|
|
|
|
|
|
//IP_ADDR = IPAddress(192,168,5,5);
|
|
|
|
|
|
|
|
if (!IP_ADDR.isSet())
|
|
|
|
|
|
|
|
ETH_MODE = "dhcp";
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
ETH_MODE = "staticip";
|
|
|
|
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println("Configuration loaded.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ETH_MODE == "staticip") {
|
|
|
|
|
|
|
|
println("Setting static IP...");
|
|
|
|
|
|
|
|
eth.config(IP_ADDR, INADDR_NONE);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
println(F("Requesting Address via DHCP..."));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SPI.setRX(16);
|
|
|
|
|
|
|
|
SPI.setCS(17);
|
|
|
|
|
|
|
|
SPI.setSCK(18);
|
|
|
|
|
|
|
|
SPI.setTX(19);
|
|
|
|
|
|
|
|
eth.setSPISpeed(ETH_SPI_SPD);
|
|
|
|
|
|
|
|
lwipPollingPeriod(1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//char * hostname_char;
|
|
|
|
|
|
|
|
//HOSTNAME.toCharArray(hostname_char, 32);
|
|
|
|
|
|
|
|
eth.setHostname(HOSTNAME);
|
|
|
|
|
|
|
|
|
|
|
|
if (!eth.begin()) {
|
|
|
|
if (!eth.begin()) {
|
|
|
|
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
|
|
|
|
println("No wired Ethernet hardware detected. Check pinouts, wiring.");
|
|
|
|
Serial.println("Connection failed. Retrying.");
|
|
|
|
println("Connection failed. Retrying.");
|
|
|
|
rp2040.reboot();
|
|
|
|
rp2040.reboot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
while (!eth.connected() && count < 32) { // wait 8 seconds for connection
|
|
|
|
while (!eth.connected() && count < 32) {
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
count++;
|
|
|
|
count++;
|
|
|
|
Serial.print(".");
|
|
|
|
print(".");
|
|
|
|
delay(250);
|
|
|
|
delay(250);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!eth.connected()) {
|
|
|
|
if (!eth.connected()) {
|
|
|
|
Serial.println("Connection failed. Retrying.");
|
|
|
|
println("Connection failed. Retrying.");
|
|
|
|
rp2040.reboot();
|
|
|
|
rp2040.reboot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Serial.print(F("\r\n- IP Address: "));
|
|
|
|
print("- IP Address: ");
|
|
|
|
Serial.println(eth.localIP());
|
|
|
|
Serial.println(eth.localIP());
|
|
|
|
|
|
|
|
|
|
|
|
initUnicast();
|
|
|
|
|
|
|
|
MDNS.begin("RGBController");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
httpUpdater.setup(&httpServer, "/update", "admin", "admin");
|
|
|
|
e131.begin(E131_UNICAST);
|
|
|
|
|
|
|
|
#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();
|
|
|
|
httpServer.begin();
|
|
|
|
MDNS.addService("http", "tcp", 80);
|
|
|
|
MDNS.addService("http", "tcp", 80);
|
|
|
|
|
|
|
|
print("OTA Updates enabled. Open http://");
|
|
|
|
|
|
|
|
Serial.print(HOSTNAME);
|
|
|
|
|
|
|
|
Serial.print(update_path);
|
|
|
|
|
|
|
|
Serial.print(" in your browser and login with username ");
|
|
|
|
|
|
|
|
Serial.print(update_username);
|
|
|
|
|
|
|
|
Serial.print(" and password ");
|
|
|
|
|
|
|
|
Serial.println(update_password);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(ENABLE_NTP) {
|
|
|
|
|
|
|
|
println("Starting NTP client.");
|
|
|
|
|
|
|
|
NTP.begin(ntpserver);
|
|
|
|
|
|
|
|
NTP.waitSet([]() { Serial.print("."); }, 15000);
|
|
|
|
|
|
|
|
time_t now = time(nullptr);
|
|
|
|
|
|
|
|
Serial.println("");
|
|
|
|
|
|
|
|
gmtime_r(&now, &timeinfo);
|
|
|
|
|
|
|
|
print("Current time: ");
|
|
|
|
|
|
|
|
Serial.println(asctime(&timeinfo));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ready += 1;
|
|
|
|
|
|
|
|
while (ready == 1) {
|
|
|
|
|
|
|
|
delay(50);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println("Starting temperature monitoring...");
|
|
|
|
|
|
|
|
pinMode(AIRTEMP_PIN, INPUT);
|
|
|
|
|
|
|
|
for(int i = 0; i < TEMP_SAMPLES; i++) {
|
|
|
|
|
|
|
|
cputemparray[i] = analogReadTemp();
|
|
|
|
|
|
|
|
airtemparray[i] = analogRead(AIRTEMP_PIN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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...");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Populate universes and offsets
|
|
|
|
|
|
|
|
int offsetcount = 0;
|
|
|
|
|
|
|
|
int currentsize = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < LED_STRIPS; i++) {
|
|
|
|
|
|
|
|
#ifdef RGBW_MODE
|
|
|
|
|
|
|
|
int tmp = strips[i] * 3 / 4;
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
int tmp = strips[i];
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print("Strip ");
|
|
|
|
|
|
|
|
Serial.print(i);
|
|
|
|
|
|
|
|
Serial.print(", Pin ");
|
|
|
|
|
|
|
|
Serial.print(pins[i]);
|
|
|
|
|
|
|
|
Serial.print(", Light count ");
|
|
|
|
|
|
|
|
Serial.println(tmp);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while(tmp > MAX_PIXELS_PER_UNIVERSE) {
|
|
|
|
|
|
|
|
universes[currentsize] = MAX_PIXELS_PER_UNIVERSE;
|
|
|
|
|
|
|
|
calculate[currentsize] = offsetcount;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
print(" Universe ");
|
|
|
|
|
|
|
|
Serial.print(currentsize + START_UNIVERSE);
|
|
|
|
|
|
|
|
Serial.print(", Light count ");
|
|
|
|
|
|
|
|
Serial.print(MAX_PIXELS_PER_UNIVERSE);
|
|
|
|
|
|
|
|
Serial.print(", Size ");
|
|
|
|
|
|
|
|
Serial.print(MAX_PIXELS_PER_UNIVERSE * PIXEL_SIZE);
|
|
|
|
|
|
|
|
Serial.print(", Offset ");
|
|
|
|
|
|
|
|
Serial.println(calculate[currentsize]);
|
|
|
|
|
|
|
|
offsetcount += MAX_PIXELS_PER_UNIVERSE;
|
|
|
|
|
|
|
|
currentsize += 1;
|
|
|
|
|
|
|
|
tmp -= MAX_PIXELS_PER_UNIVERSE;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
universes[currentsize] = tmp;
|
|
|
|
|
|
|
|
calculate[currentsize] = offsetcount;
|
|
|
|
|
|
|
|
print(" Universe ");
|
|
|
|
|
|
|
|
Serial.print(currentsize + START_UNIVERSE);
|
|
|
|
|
|
|
|
Serial.print(", Light count ");
|
|
|
|
|
|
|
|
Serial.print(tmp);
|
|
|
|
|
|
|
|
Serial.print(", Size ");
|
|
|
|
|
|
|
|
Serial.print(tmp * PIXEL_SIZE);
|
|
|
|
|
|
|
|
Serial.print(", Offset ");
|
|
|
|
|
|
|
|
Serial.println(calculate[currentsize]);
|
|
|
|
|
|
|
|
offsetcount += tmp;
|
|
|
|
|
|
|
|
currentsize += 1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!leds.begin(true)) {
|
|
|
|
|
|
|
|
println("Failure to initialize LEDs!");
|
|
|
|
|
|
|
|
delay(1000);
|
|
|
|
|
|
|
|
//rp2040.reboot();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
println("LED driver initialized.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
leds.setLatchTime(500);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (uint32_t color = 0x440000; color > 0; color >>= 8) {
|
|
|
|
|
|
|
|
leds.fill(color);
|
|
|
|
|
|
|
|
leds.show();
|
|
|
|
|
|
|
|
delay(500);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=0; i<8; i++) {
|
|
|
|
|
|
|
|
if (pins && (pins[i] < 0)) {
|
|
|
|
|
|
|
|
print("No leds on pin ");
|
|
|
|
|
|
|
|
Serial.println(pins[i]);
|
|
|
|
|
|
|
|
continue; // No pixels on this pin
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
leds.fill(0);
|
|
|
|
|
|
|
|
uint32_t color = 0x0000aa;
|
|
|
|
|
|
|
|
leds.fill(color, i * MAX_LEDS, MAX_LEDS);
|
|
|
|
|
|
|
|
leds.show();
|
|
|
|
|
|
|
|
delay(300);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef INT_WIFI
|
|
|
|
for (int i = 0; i < MAX_LEDS; i++) {
|
|
|
|
WiFi.noLowPowerMode();
|
|
|
|
setpixelrgb(i, 0, 0, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showpixels();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Test all lights
|
|
|
|
|
|
|
|
#ifdef LIGHTTEST
|
|
|
|
|
|
|
|
for (int i = 0; i < MAX_LEDS; i++) {
|
|
|
|
|
|
|
|
setpixelrgb(i, 0, 0, 50);
|
|
|
|
|
|
|
|
showpixels();
|
|
|
|
|
|
|
|
delay(1);
|
|
|
|
|
|
|
|
setpixelrgb(i, 0, 0, 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
showpixels();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//delay(3000);
|
|
|
|
|
|
|
|
|
|
|
|
Serial.println("Startup Complete. Listening for e1.31 (sACN) connections...");
|
|
|
|
ready += 1;
|
|
|
|
}
|
|
|
|
while (ready == 1) {
|
|
|
|
|
|
|
|
delay(50);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//rp2040.wdt_begin(8000);
|
|
|
|
|
|
|
|
|
|
|
|
void setup1() {
|
|
|
|
|
|
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
|
|
|
|
|
|
//pinMode(32+1, OUTPUT);
|
|
|
|
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
|
/* Parse a packet */
|
|
|
|
/* Parse a packet */
|
|
|
|
//println("Start loop");
|
|
|
|
//println("Start loop");
|
|
|
|
int size;
|
|
|
|
if (millis() % 100 > 50) { // reset LED
|
|
|
|
if(size = readPacket()) {
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(channels = e131.parsePacket()) {
|
|
|
|
// Offset by start universe
|
|
|
|
// Offset by start universe
|
|
|
|
// as all local functions count from 0
|
|
|
|
// as all local functions count from 0
|
|
|
|
//delay(0);
|
|
|
|
//delay(0);
|
|
|
|
Serial.println("Got valid packet of size " + String(size) + " at " + String(millis()/1000.0));
|
|
|
|
livedata = e131.data;
|
|
|
|
//delayMicroseconds(1000);
|
|
|
|
status = 1;
|
|
|
|
|
|
|
|
delayMicroseconds(3000);
|
|
|
|
|
|
|
|
//print(eth.isLinked());
|
|
|
|
nopackets = 0;
|
|
|
|
nopackets = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
//delayMicroseconds(500);
|
|
|
|
|
|
|
|
nopackets++;
|
|
|
|
nopackets++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(nopackets > 50000) {
|
|
|
|
if(nopackets > 50000) {
|
|
|
|
nopackets = 0;
|
|
|
|
nopackets = 0;
|
|
|
|
|
|
|
|
println("No packets processed recently.");
|
|
|
|
delay(5);
|
|
|
|
delay(5);
|
|
|
|
Serial.println("No packets recieved in a while.... at " + String(millis()/1000.0));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//println("mid loop");
|
|
|
|
MDNS.update();
|
|
|
|
|
|
|
|
httpServer.handleClient();
|
|
|
|
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() {
|
|
|
|
void loop1() {
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
//rp2040.wdt_reset();
|
|
|
|
delay(50);
|
|
|
|
if (millis() % 100 < 50) {
|
|
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
|
|
//status = 0;
|
|
|
|
delay(50);
|
|
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(BOOTSEL) {
|
|
|
|
|
|
|
|
bootsel_count++;
|
|
|
|
|
|
|
|
delay(50);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
bootsel_count = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(bootsel_count > 60) { // 3 seconds
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
status2 = 1;
|
|
|
|
|
|
|
|
if(status == 1 && e131.universe > START_UNIVERSE - 1 && channels > 0) {
|
|
|
|
|
|
|
|
write_universe(e131.universe - START_UNIVERSE - 1, livedata, channels);
|
|
|
|
|
|
|
|
showpixels();
|
|
|
|
|
|
|
|
//println("Done Writing");
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
status2 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//status = 0;
|
|
|
|
|
|
|
|
//delay(50);
|
|
|
|
|
|
|
|
float cputemp2 = analogReadTemp();
|
|
|
|
|
|
|
|
float airtemp2 = analogRead(AIRTEMP_PIN);
|
|
|
|
|
|
|
|
airtemp2 = airtemp2 / 1024.0 * 3300; // voltage in mV
|
|
|
|
|
|
|
|
airtemp2 /= 10.0; // 10.0 mv/C
|
|
|
|
|
|
|
|
airtemp2 -= 50; // offset 500mV = 0C
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cputemparray[datapos] = cputemp2;
|
|
|
|
|
|
|
|
airtemparray[datapos] = airtemp2;
|
|
|
|
|
|
|
|
if(datapos >= TEMP_SAMPLES - 1) {
|
|
|
|
|
|
|
|
datapos = 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
|
|
|
datapos++;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cputemp2 = 0;
|
|
|
|
|
|
|
|
airtemp2 = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < TEMP_SAMPLES; i++) {
|
|
|
|
|
|
|
|
if(i != datapos) {
|
|
|
|
|
|
|
|
cputemp2 += cputemparray[i];
|
|
|
|
|
|
|
|
airtemp2 += airtemparray[i];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cputemp = cputemp2 / (TEMP_SAMPLES - 1);
|
|
|
|
|
|
|
|
airtemp = airtemp2 / (TEMP_SAMPLES - 1);
|
|
|
|
|
|
|
|
// TODO: report temps somehow to dashboard
|
|
|
|
|
|
|
|
//println("CPUTEMP " + String(cputemp) + " AIRTEMP " + String(airtemp));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|