|
|
|
@ -63,15 +63,21 @@ const uint8_t WHITE[PIXEL_SIZE]= {0x20, 0x20, 0x20};
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> T print(T in) {
|
|
|
|
|
Serial.print(String(in));
|
|
|
|
|
Serial.print(String(millis()/1000.0) + ": " + String(in));
|
|
|
|
|
if(printer) clientbuffer += String(in);
|
|
|
|
|
return (T)true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template <class T> T println(T in) {
|
|
|
|
|
Serial.println(String(in));
|
|
|
|
|
Serial.println(String(millis()/1000.0) + ": " + String(in));
|
|
|
|
|
if(printer) {
|
|
|
|
|
clientbuffer += String(in);
|
|
|
|
|
clientbuffer += "\n";
|
|
|
|
@ -118,7 +124,7 @@ void handleForm() {
|
|
|
|
|
bool ipset = false;
|
|
|
|
|
bool reboot = false;
|
|
|
|
|
for (uint8_t i = 0; i < httpServer.args(); i++) {
|
|
|
|
|
Serial.println(httpServer.argName(i));
|
|
|
|
|
println(httpServer.argName(i));
|
|
|
|
|
if (httpServer.argName(i) == "ipa") {
|
|
|
|
|
ipset = true;
|
|
|
|
|
}
|
|
|
|
@ -209,20 +215,20 @@ void handleNotFound() {
|
|
|
|
|
|
|
|
|
|
void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
|
// universe starts at 0
|
|
|
|
|
/*PRINTFUNC("Universe: ");
|
|
|
|
|
PRINTLNFUNC(universe);
|
|
|
|
|
PRINTFUNC("Calculate size: ");
|
|
|
|
|
PRINTLNFUNC(sizeof(calculate));*/
|
|
|
|
|
/*print("Universe: ");
|
|
|
|
|
Serial.println(universe);
|
|
|
|
|
print("Calculate size: ");
|
|
|
|
|
Serial.println(sizeof(calculate));*/
|
|
|
|
|
int offset = calculate[universe];
|
|
|
|
|
/*PRINTFUNC("Offset: ");
|
|
|
|
|
PRINTLNFUNC(offset);
|
|
|
|
|
PRINTFUNC("Universes size: ");
|
|
|
|
|
PRINTLNFUNC(sizeof(universes));*/
|
|
|
|
|
/*print("Offset: ");
|
|
|
|
|
Serial.println(offset);
|
|
|
|
|
print("Universes size: ");
|
|
|
|
|
Serial.println(sizeof(universes));*/
|
|
|
|
|
int write_size = universes[universe];
|
|
|
|
|
/*PRINTFUNC("Length: ");
|
|
|
|
|
PRINTLNFUNC(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
|
|
|
|
|
PRINTFUNC("Data: ");
|
|
|
|
|
PRINTLNFUNC(size);*/
|
|
|
|
|
/*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) + 2 > size) {
|
|
|
|
|
println("Write size too big!!");
|
|
|
|
|
return;
|
|
|
|
@ -235,12 +241,12 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
|
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(" ");
|
|
|
|
|
Serial.print(data[j]);
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
Serial.print(data[j+1]);
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
Serial.print(data[j+2]);
|
|
|
|
|
Serial.print(" ");
|
|
|
|
|
}*/
|
|
|
|
|
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]);
|
|
|
|
@ -248,23 +254,24 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
|
//FastLED.show();
|
|
|
|
|
//status = 1;
|
|
|
|
|
|
|
|
|
|
//PRINTLNFUNC("Done writing.");
|
|
|
|
|
//println("Done writing.");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
vreg_voltage v = VREG_VOLTAGE_1_20;
|
|
|
|
|
vreg_set_voltage(v);
|
|
|
|
|
set_sys_clock_khz(252000, false);
|
|
|
|
|
//vreg_voltage v = VREG_VOLTAGE_1_20;
|
|
|
|
|
//vreg_set_voltage(v);
|
|
|
|
|
//set_sys_clock_khz(252000, false);
|
|
|
|
|
Serial.begin(115200);
|
|
|
|
|
rp2040.wdt_begin(8000);
|
|
|
|
|
//rp2040.wdt_begin(8000);
|
|
|
|
|
pinMode(24, INPUT); // VBUS detect - check for USB connection
|
|
|
|
|
if (digitalRead(24)) {
|
|
|
|
|
delay(3000); // Wait for serial
|
|
|
|
|
}
|
|
|
|
|
pinMode(21, INPUT);
|
|
|
|
|
println("\r\nStarting RGB Controller...");
|
|
|
|
|
Serial.println("");
|
|
|
|
|
println("Starting RGB Controller...");
|
|
|
|
|
pinMode(20, OUTPUT);
|
|
|
|
|
println("Resetting W5500 Ethernet Driver...");
|
|
|
|
|
digitalWrite(20, LOW); // reset W5500 ethernet
|
|
|
|
@ -325,11 +332,11 @@ void setup() {
|
|
|
|
|
println("Configuration loaded.");
|
|
|
|
|
|
|
|
|
|
if(ETH_MODE == "staticip") {
|
|
|
|
|
Serial.println("Setting static IP");
|
|
|
|
|
println("Setting static IP...");
|
|
|
|
|
eth.config(IP_ADDR, INADDR_NONE);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Serial.println(F("Requesting Address via DHCP"));
|
|
|
|
|
println(F("Requesting Address via DHCP..."));
|
|
|
|
|
}
|
|
|
|
|
SPI.setRX(16);
|
|
|
|
|
SPI.setCS(17);
|
|
|
|
@ -343,7 +350,7 @@ void setup() {
|
|
|
|
|
eth.setHostname(HOSTNAME);
|
|
|
|
|
|
|
|
|
|
if (!eth.begin()) {
|
|
|
|
|
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
|
|
|
|
|
println("No wired Ethernet hardware detected. Check pinouts, wiring.");
|
|
|
|
|
println("Connection failed. Retrying.");
|
|
|
|
|
rp2040.reboot();
|
|
|
|
|
}
|
|
|
|
@ -351,14 +358,14 @@ void setup() {
|
|
|
|
|
while (!eth.connected() && count < 32) {
|
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
|
count++;
|
|
|
|
|
Serial.print(".");
|
|
|
|
|
print(".");
|
|
|
|
|
delay(250);
|
|
|
|
|
}
|
|
|
|
|
if (!eth.connected()) {
|
|
|
|
|
println("Connection failed. Retrying.");
|
|
|
|
|
rp2040.reboot();
|
|
|
|
|
}
|
|
|
|
|
Serial.print(F("\r\n- IP Address: "));
|
|
|
|
|
print("- IP Address: ");
|
|
|
|
|
Serial.println(eth.localIP());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -422,28 +429,36 @@ void setup() {
|
|
|
|
|
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);
|
|
|
|
|
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([]() { print("."); }, 15000);
|
|
|
|
|
NTP.waitSet([]() { Serial.print("."); }, 15000);
|
|
|
|
|
time_t now = time(nullptr);
|
|
|
|
|
println("");
|
|
|
|
|
Serial.println("");
|
|
|
|
|
gmtime_r(&now, &timeinfo);
|
|
|
|
|
print("Current time: ");
|
|
|
|
|
println(asctime(&timeinfo));
|
|
|
|
|
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);
|
|
|
|
@ -488,35 +503,35 @@ void setup1() {
|
|
|
|
|
for (int i = 0; i < LED_STRIPS; i++) {
|
|
|
|
|
int tmp = strips[i];
|
|
|
|
|
|
|
|
|
|
PRINTFUNC("Strip ");
|
|
|
|
|
PRINTFUNC(i);
|
|
|
|
|
PRINTFUNC(", Pin ");
|
|
|
|
|
PRINTFUNC(pins[i]);
|
|
|
|
|
PRINTFUNC(", Light count ");
|
|
|
|
|
PRINTLNFUNC(tmp);
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
PRINTFUNC(" Universe ");
|
|
|
|
|
PRINTFUNC(currentsize + START_UNIVERSE);
|
|
|
|
|
PRINTFUNC(", Light count ");
|
|
|
|
|
PRINTFUNC(MAX_PIXELS_PER_UNIVERSE);
|
|
|
|
|
PRINTFUNC(", Size ");
|
|
|
|
|
PRINTLNFUNC(MAX_PIXELS_PER_UNIVERSE * PIXEL_SIZE);
|
|
|
|
|
print(" Universe ");
|
|
|
|
|
Serial.print(currentsize + START_UNIVERSE);
|
|
|
|
|
Serial.print(", Light count ");
|
|
|
|
|
Serial.print(MAX_PIXELS_PER_UNIVERSE);
|
|
|
|
|
Serial.print(", Size ");
|
|
|
|
|
Serial.println(MAX_PIXELS_PER_UNIVERSE * PIXEL_SIZE);
|
|
|
|
|
offsetcount += MAX_PIXELS_PER_UNIVERSE;
|
|
|
|
|
currentsize += 1;
|
|
|
|
|
tmp -= MAX_PIXELS_PER_UNIVERSE;
|
|
|
|
|
}
|
|
|
|
|
universes[currentsize] = tmp;
|
|
|
|
|
calculate[currentsize] = offsetcount;
|
|
|
|
|
PRINTFUNC(" Universe ");
|
|
|
|
|
PRINTFUNC(currentsize + START_UNIVERSE);
|
|
|
|
|
PRINTFUNC(", Light count ");
|
|
|
|
|
PRINTFUNC(tmp);
|
|
|
|
|
PRINTFUNC(", Size ");
|
|
|
|
|
PRINTLNFUNC(tmp * PIXEL_SIZE);
|
|
|
|
|
print(" Universe ");
|
|
|
|
|
Serial.print(currentsize + START_UNIVERSE);
|
|
|
|
|
Serial.print(", Light count ");
|
|
|
|
|
Serial.print(tmp);
|
|
|
|
|
Serial.print(", Size ");
|
|
|
|
|
Serial.println(tmp * PIXEL_SIZE);
|
|
|
|
|
offsetcount += tmp;
|
|
|
|
|
currentsize += 1;
|
|
|
|
|
}
|
|
|
|
@ -581,8 +596,8 @@ void loop() {
|
|
|
|
|
//delay(0);
|
|
|
|
|
livedata = e131.data;
|
|
|
|
|
status = 1;
|
|
|
|
|
delayMicroseconds(5000);
|
|
|
|
|
//Serial.print(eth.isLinked());
|
|
|
|
|
delayMicroseconds(3000);
|
|
|
|
|
//print(eth.isLinked());
|
|
|
|
|
nopackets = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
@ -590,11 +605,8 @@ void loop() {
|
|
|
|
|
}
|
|
|
|
|
if(nopackets > 50000) {
|
|
|
|
|
nopackets = 0;
|
|
|
|
|
println("Resetting network");
|
|
|
|
|
eth.end();
|
|
|
|
|
println("No packets processed recently.");
|
|
|
|
|
delay(5);
|
|
|
|
|
eth.begin();
|
|
|
|
|
println("Reset network");
|
|
|
|
|
}
|
|
|
|
|
//println("mid loop");
|
|
|
|
|
httpServer.handleClient();
|
|
|
|
@ -622,7 +634,7 @@ void loop1() {
|
|
|
|
|
bootsel_count = 0;
|
|
|
|
|
}
|
|
|
|
|
if(bootsel_count > 60) { // 3 seconds
|
|
|
|
|
Serial.print("Wiping configuration...");
|
|
|
|
|
print("Wiping configuration...");
|
|
|
|
|
digitalWrite(LED_BUILTIN, LOW);
|
|
|
|
|
delay(50);
|
|
|
|
|
for(int i = 0; i < 5; i++) { // blink 5 times to indicate wipe
|
|
|
|
@ -659,18 +671,32 @@ void loop1() {
|
|
|
|
|
}
|
|
|
|
|
//status = 0;
|
|
|
|
|
//delay(50);
|
|
|
|
|
float cputemp = analogReadTemp();
|
|
|
|
|
if (cputemp > 50.0) {
|
|
|
|
|
println("ERROR: Overtemperature triggered!");
|
|
|
|
|
rp2040.reboot();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
float envtemp = analogRead(28);
|
|
|
|
|
envtemp = envtemp / 1024.0 * 3300; // voltage in mV
|
|
|
|
|
envtemp /= 10.0; // 10.0 mv/C
|
|
|
|
|
envtemp -= 50; // offset 500mV = 0C
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|