|
|
|
@ -9,6 +9,8 @@
|
|
|
|
|
#include <FastLED.h>
|
|
|
|
|
#include "config.h"
|
|
|
|
|
#include <EEPROM.h>
|
|
|
|
|
#include <pico/stdlib.h>
|
|
|
|
|
#include <hardware/vreg.h>
|
|
|
|
|
|
|
|
|
|
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
|
|
|
|
// Begin code
|
|
|
|
@ -27,6 +29,7 @@ int universes[LED_STRIPS * 4];
|
|
|
|
|
CRGB ledstrip[MAX_LEDS];
|
|
|
|
|
int pins[8];
|
|
|
|
|
|
|
|
|
|
uint8_t * livedata;
|
|
|
|
|
// Networking
|
|
|
|
|
|
|
|
|
|
WebServer httpServer(80);
|
|
|
|
@ -40,8 +43,10 @@ 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};
|
|
|
|
@ -55,8 +60,10 @@ 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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> T print(T in) {
|
|
|
|
|
Serial.print(String(in));
|
|
|
|
|
if(printer) clientbuffer += String(in);
|
|
|
|
@ -212,10 +219,10 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
|
PRINTFUNC("Universes size: ");
|
|
|
|
|
PRINTLNFUNC(sizeof(universes));*/
|
|
|
|
|
int write_size = universes[universe];
|
|
|
|
|
PRINTFUNC("Length: ");
|
|
|
|
|
/*PRINTFUNC("Length: ");
|
|
|
|
|
PRINTLNFUNC(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
|
|
|
|
|
PRINTFUNC("Data: ");
|
|
|
|
|
PRINTLNFUNC(size);
|
|
|
|
|
PRINTLNFUNC(size);*/
|
|
|
|
|
if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2 > size) {
|
|
|
|
|
println("Write size too big!!");
|
|
|
|
|
return;
|
|
|
|
@ -247,12 +254,16 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
|
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...");
|
|
|
|
|
pinMode(20, OUTPUT);
|
|
|
|
|
println("Resetting W5500 Ethernet Driver...");
|
|
|
|
@ -312,10 +323,46 @@ void setup() {
|
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
|
|
|
|
|
|
println("Configuration loaded.");
|
|
|
|
|
if (!e131.begin()) {
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
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()) {
|
|
|
|
|
Serial.println("No wired Ethernet hardware detected. Check pinouts, wiring.");
|
|
|
|
|
println("Connection failed. Retrying.");
|
|
|
|
|
rp2040.reboot();
|
|
|
|
|
}
|
|
|
|
|
int count = 0;
|
|
|
|
|
while (!eth.connected() && count < 32) {
|
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
|
count++;
|
|
|
|
|
Serial.print(".");
|
|
|
|
|
delay(250);
|
|
|
|
|
}
|
|
|
|
|
if (!eth.connected()) {
|
|
|
|
|
println("Connection failed. Retrying.");
|
|
|
|
|
rp2040.reboot();
|
|
|
|
|
}
|
|
|
|
|
Serial.print(F("\r\n- IP Address: "));
|
|
|
|
|
Serial.println(eth.localIP());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e131.begin(E131_UNICAST);
|
|
|
|
|
#ifdef INT_WIFI
|
|
|
|
|
WiFi.noLowPowerMode();
|
|
|
|
|
#endif
|
|
|
|
@ -526,25 +573,33 @@ void setup1() {
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
|
/* Parse a packet */
|
|
|
|
|
println("Start loop");
|
|
|
|
|
int channels = 0;
|
|
|
|
|
//println("Start loop");
|
|
|
|
|
|
|
|
|
|
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");
|
|
|
|
|
}
|
|
|
|
|
//delay(0);
|
|
|
|
|
livedata = e131.data;
|
|
|
|
|
status = 1;
|
|
|
|
|
delayMicroseconds(5000);
|
|
|
|
|
//Serial.print(eth.isLinked());
|
|
|
|
|
nopackets = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
nopackets++;
|
|
|
|
|
}
|
|
|
|
|
if(nopackets > 50000) {
|
|
|
|
|
nopackets = 0;
|
|
|
|
|
println("Resetting network");
|
|
|
|
|
eth.end();
|
|
|
|
|
delay(5);
|
|
|
|
|
eth.begin();
|
|
|
|
|
println("Reset network");
|
|
|
|
|
}
|
|
|
|
|
println("mid loop");
|
|
|
|
|
//println("mid loop");
|
|
|
|
|
httpServer.handleClient();
|
|
|
|
|
MDNS.update();
|
|
|
|
|
println("end loop");
|
|
|
|
|
//println("end loop");
|
|
|
|
|
if(newconfig == true) {
|
|
|
|
|
println("Waiting for core 1 to idle...");
|
|
|
|
|
ready = 3;
|
|
|
|
@ -585,11 +640,16 @@ void loop1() {
|
|
|
|
|
while(ready == 4)
|
|
|
|
|
delay(50);
|
|
|
|
|
}
|
|
|
|
|
if(status == 1) {
|
|
|
|
|
status2 = 1;
|
|
|
|
|
status2 = 1;
|
|
|
|
|
if(status == 1 && e131.universe > START_UNIVERSE - 1 && channels > 0) {
|
|
|
|
|
write_universe(e131.universe - START_UNIVERSE, livedata, channels);
|
|
|
|
|
FastLED.show();
|
|
|
|
|
status2 = 0;
|
|
|
|
|
//println("Done Writing");
|
|
|
|
|
status = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
status2 = 0;
|
|
|
|
|
|
|
|
|
|
if (millis() % 100 > 50) { // reset LED
|
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
|
}
|
|
|
|
|