|
|
@ -9,6 +9,8 @@
|
|
|
|
#include <FastLED.h>
|
|
|
|
#include <FastLED.h>
|
|
|
|
#include "config.h"
|
|
|
|
#include "config.h"
|
|
|
|
#include <EEPROM.h>
|
|
|
|
#include <EEPROM.h>
|
|
|
|
|
|
|
|
#include <pico/stdlib.h>
|
|
|
|
|
|
|
|
#include <hardware/vreg.h>
|
|
|
|
|
|
|
|
|
|
|
|
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
|
|
|
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
|
|
|
// Begin code
|
|
|
|
// Begin code
|
|
|
@ -27,6 +29,7 @@ int universes[LED_STRIPS * 4];
|
|
|
|
CRGB ledstrip[MAX_LEDS];
|
|
|
|
CRGB ledstrip[MAX_LEDS];
|
|
|
|
int pins[8];
|
|
|
|
int pins[8];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t * livedata;
|
|
|
|
// Networking
|
|
|
|
// Networking
|
|
|
|
|
|
|
|
|
|
|
|
WebServer httpServer(80);
|
|
|
|
WebServer httpServer(80);
|
|
|
@ -40,8 +43,10 @@ String clientbuffer = "";
|
|
|
|
String initinfo = "";
|
|
|
|
String initinfo = "";
|
|
|
|
bool debug = 1;
|
|
|
|
bool debug = 1;
|
|
|
|
bool printer = 1;
|
|
|
|
bool printer = 1;
|
|
|
|
|
|
|
|
int channels = 0;
|
|
|
|
// Colors (RGB)
|
|
|
|
// Colors (RGB)
|
|
|
|
int bootsel_count = 0;
|
|
|
|
int bootsel_count = 0;
|
|
|
|
|
|
|
|
int nopackets = 0;
|
|
|
|
|
|
|
|
|
|
|
|
const uint8_t RED[PIXEL_SIZE]= {0x20, 0x00, 0x00};
|
|
|
|
const uint8_t RED[PIXEL_SIZE]= {0x20, 0x00, 0x00};
|
|
|
|
const uint8_t ORANGE[PIXEL_SIZE]= {0x20, 0x10, 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 MAX_PIXELS_PER_UNIVERSE 512 / PIXEL_SIZE /* Number of pixels */
|
|
|
|
#define CHANNEL_START 1 /* Channel to start listening at */
|
|
|
|
#define CHANNEL_START 1 /* Channel to start listening at */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Wiznet5500lwIP eth(17, SPI, 21); //, 21); // 17 : cs, 21 : INTn
|
|
|
|
E131 e131;
|
|
|
|
E131 e131;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template <class T> T print(T in) {
|
|
|
|
template <class T> T print(T in) {
|
|
|
|
Serial.print(String(in));
|
|
|
|
Serial.print(String(in));
|
|
|
|
if(printer) clientbuffer += String(in);
|
|
|
|
if(printer) clientbuffer += String(in);
|
|
|
@ -212,10 +219,10 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
PRINTFUNC("Universes size: ");
|
|
|
|
PRINTFUNC("Universes size: ");
|
|
|
|
PRINTLNFUNC(sizeof(universes));*/
|
|
|
|
PRINTLNFUNC(sizeof(universes));*/
|
|
|
|
int write_size = universes[universe];
|
|
|
|
int write_size = universes[universe];
|
|
|
|
PRINTFUNC("Length: ");
|
|
|
|
/*PRINTFUNC("Length: ");
|
|
|
|
PRINTLNFUNC(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
|
|
|
|
PRINTLNFUNC(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
|
|
|
|
PRINTFUNC("Data: ");
|
|
|
|
PRINTFUNC("Data: ");
|
|
|
|
PRINTLNFUNC(size);
|
|
|
|
PRINTLNFUNC(size);*/
|
|
|
|
if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2 > size) {
|
|
|
|
if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2 > size) {
|
|
|
|
println("Write size too big!!");
|
|
|
|
println("Write size too big!!");
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -247,12 +254,16 @@ void write_universe(long universe, uint8_t data[], long size) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void setup() {
|
|
|
|
void setup() {
|
|
|
|
|
|
|
|
vreg_voltage v = VREG_VOLTAGE_1_20;
|
|
|
|
|
|
|
|
vreg_set_voltage(v);
|
|
|
|
|
|
|
|
set_sys_clock_khz(252000, false);
|
|
|
|
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 serial
|
|
|
|
delay(3000); // Wait for serial
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pinMode(21, INPUT);
|
|
|
|
println("\r\nStarting RGB Controller...");
|
|
|
|
println("\r\nStarting RGB Controller...");
|
|
|
|
pinMode(20, OUTPUT);
|
|
|
|
pinMode(20, OUTPUT);
|
|
|
|
println("Resetting W5500 Ethernet Driver...");
|
|
|
|
println("Resetting W5500 Ethernet Driver...");
|
|
|
@ -312,10 +323,46 @@ void setup() {
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
rp2040.wdt_reset();
|
|
|
|
|
|
|
|
|
|
|
|
println("Configuration loaded.");
|
|
|
|
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.");
|
|
|
|
println("Connection failed. Retrying.");
|
|
|
|
rp2040.reboot();
|
|
|
|
rp2040.reboot();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Serial.print(F("\r\n- IP Address: "));
|
|
|
|
|
|
|
|
Serial.println(eth.localIP());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e131.begin(E131_UNICAST);
|
|
|
|
#ifdef INT_WIFI
|
|
|
|
#ifdef INT_WIFI
|
|
|
|
WiFi.noLowPowerMode();
|
|
|
|
WiFi.noLowPowerMode();
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
@ -526,25 +573,33 @@ void setup1() {
|
|
|
|
|
|
|
|
|
|
|
|
void loop() {
|
|
|
|
void loop() {
|
|
|
|
/* Parse a packet */
|
|
|
|
/* Parse a packet */
|
|
|
|
println("Start loop");
|
|
|
|
//println("Start loop");
|
|
|
|
int channels = 0;
|
|
|
|
|
|
|
|
if(channels = e131.parsePacket()) {
|
|
|
|
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
|
|
|
|
status = 0;
|
|
|
|
//delay(0);
|
|
|
|
if(e131.universe > START_UNIVERSE - 1) {
|
|
|
|
livedata = e131.data;
|
|
|
|
while (status2 == 1) {
|
|
|
|
|
|
|
|
delay(0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
write_universe(e131.universe - START_UNIVERSE, e131.data, channels);
|
|
|
|
|
|
|
|
println("Done Writing");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
status = 1;
|
|
|
|
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();
|
|
|
|
httpServer.handleClient();
|
|
|
|
MDNS.update();
|
|
|
|
MDNS.update();
|
|
|
|
println("end loop");
|
|
|
|
//println("end loop");
|
|
|
|
if(newconfig == true) {
|
|
|
|
if(newconfig == true) {
|
|
|
|
println("Waiting for core 1 to idle...");
|
|
|
|
println("Waiting for core 1 to idle...");
|
|
|
|
ready = 3;
|
|
|
|
ready = 3;
|
|
|
@ -585,11 +640,16 @@ void loop1() {
|
|
|
|
while(ready == 4)
|
|
|
|
while(ready == 4)
|
|
|
|
delay(50);
|
|
|
|
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();
|
|
|
|
FastLED.show();
|
|
|
|
status2 = 0;
|
|
|
|
//println("Done Writing");
|
|
|
|
|
|
|
|
status = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
status2 = 0;
|
|
|
|
|
|
|
|
|
|
|
|
if (millis() % 100 > 50) { // reset LED
|
|
|
|
if (millis() % 100 > 50) { // reset LED
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
digitalWrite(LED_BUILTIN, HIGH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|