latest test

ethernet-argb-controller
Cole Deck 2 months ago
parent 17ef48ff82
commit 181dcc98ca

@ -13,7 +13,7 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git
board = pico board = pico
framework = arduino framework = arduino
platform_packages = platform_packages =
framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#lw framework-arduinopico@https://github.com/earlephilhower/arduino-pico.git#master
board_build.core = earlephilhower board_build.core = earlephilhower
upload_port = /run/media/amelia/RPI-RP2/ upload_port = /run/media/amelia/RPI-RP2/
debug_tool = cmsis-dap debug_tool = cmsis-dap

@ -0,0 +1,52 @@
/* FastLED_RGBW
*
* Hack to enable SK6812 RGBW strips to work with FastLED.
*
* Original code by Jim Bumgardner (http://krazydad.com).
* Modified by David Madison (http://partsnotincluded.com).
*
*/
#ifndef FastLED_RGBW_h
#define FastLED_RGBW_h
struct CRGBW {
union {
struct {
union {
uint8_t g;
uint8_t green;
};
union {
uint8_t r;
uint8_t red;
};
union {
uint8_t b;
uint8_t blue;
};
union {
uint8_t w;
uint8_t white;
};
};
uint8_t raw[4];
};
CRGBW(){}
CRGBW(uint8_t rd, uint8_t grn, uint8_t blu, uint8_t wht){
r = rd;
g = grn;
b = blu;
w = wht;
}
inline void operator = (const CRGB c) __attribute__((always_inline)){
this->r = c.r;
this->g = c.g;
this->b = c.b;
this->white = 0;
}
};
inline uint16_t getRGBWsize(uint16_t nleds){
uint16_t nbytes = nleds * 4;
if(nbytes % 3 > 0) return nbytes / 3 + 1;
else return nbytes / 3;
}
#endif

@ -3,12 +3,19 @@
#define DEBUG #define DEBUG
// Amount of color channels per pixel - i.e. RGB = 3, RGBW = 4 #define LIGHTTEST
#define PIXEL_SIZE 3
// Total LED count // Total LED count
// set to 128*8 for 4 channel, 170*8 for 3 channel // set to 128*8 for 4 channel, 170*8 for 3 channel
#define MAX_LEDS 170*8 #define MAX_LEDS 128*8
//#define RGBW_MODE
// Amount of color channels per pixel - i.e. RGB = 3, RGBW = 4
#ifdef RGBW_MODE
#define PIXEL_SIZE 4
#else
#define PIXEL_SIZE 3
#endif
// LED driver chip model - depends on strip // LED driver chip model - depends on strip
#define LED_TYPE WS2812 #define LED_TYPE WS2812

@ -7,12 +7,13 @@
#include <WebServer.h> #include <WebServer.h>
#include "e131.h" #include "e131.h"
#include <FastLED.h> #include <FastLED.h>
#include "FastLED_RGBW.h"
#include "config.h" #include "config.h"
#include <EEPROM.h> #include <EEPROM.h>
#include <pico/stdlib.h> #include <pico/stdlib.h>
#include <hardware/vreg.h> #include <hardware/vreg.h>
int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
// Begin code // Begin code
bool core1_separate_stack = true; bool core1_separate_stack = true;
@ -24,9 +25,18 @@ bool core1_separate_stack = true;
#define PRINTLNFUNC #define PRINTLNFUNC
#endif #endif
int calculate[LED_STRIPS * 4]; int calculate[LED_STRIPS * 4];
int universes[LED_STRIPS * 4]; int universes[LED_STRIPS * 4];
CRGB ledstrip[MAX_LEDS];
#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
int pins[8]; int pins[8];
uint8_t * livedata; uint8_t * livedata;
@ -71,13 +81,15 @@ int datapos = 0;
template <class T> T print(T in) { template <class T> T print(T in) {
Serial.print(String(millis()/1000.0) + ": " + String(in)); if(Serial)
Serial.print(String(millis()/1000.0) + ": " + String(in));
if(printer) clientbuffer += String(in); if(printer) clientbuffer += String(in);
return (T)true; return (T)true;
} }
template <class T> T println(T in) { template <class T> T println(T in) {
Serial.println(String(millis()/1000.0) + ": " + String(in)); if(Serial)
Serial.println(String(millis()/1000.0) + ": " + String(in));
if(printer) { if(printer) {
clientbuffer += String(in); clientbuffer += String(in);
clientbuffer += "\n"; clientbuffer += "\n";
@ -215,28 +227,31 @@ void handleNotFound() {
void write_universe(long universe, uint8_t data[], long size) { void write_universe(long universe, uint8_t data[], long size) {
// universe starts at 0 // universe starts at 0
/*print("Universe: "); //print("Universe: ");
Serial.println(universe); //Serial.println(universe);
print("Calculate size: "); //print("Calculate size: ");
Serial.println(sizeof(calculate));*/ //Serial.println(sizeof(calculate));
int offset = calculate[universe]; int offset = calculate[universe];
/*print("Offset: "); //print("Offset: ");
Serial.println(offset); //Serial.println(offset);
print("Universes size: "); //print("Universes size: ");
Serial.println(sizeof(universes));*/ //Serial.println(sizeof(universes));
int write_size = universes[universe]; int write_size = universes[universe];
/*print("Length: "); /*print("Length: ");
Serial.println(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2); Serial.println(write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2);
print("Data: "); print("Data: ");
Serial.println(size);*/ Serial.println(size);*/
if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) + 2 > size) { if (write_size * PIXEL_SIZE + (CHANNEL_START - 1) > size) {
println("Write size too big!!"); println("Write size too big!!");
println(String(write_size * PIXEL_SIZE + (CHANNEL_START - 1)) + " with data size " + String(size));
return; return;
} }
if(offset + write_size > sizeof(ledstrip)) { /*if(offset + write_size > sizeof(ledstrip)) {
println("Write size too big!!"); println("Write size too big!!");
println(String(offset + write_size) + " with strip size " + sizeof(ledstrip));
return; return;
} }*/
//status = 0; //status = 0;
for (int i = 0; i < write_size; i++) { for (int i = 0; i < write_size; i++) {
int j = i * PIXEL_SIZE + (CHANNEL_START - 1); int j = i * PIXEL_SIZE + (CHANNEL_START - 1);
@ -248,7 +263,11 @@ void write_universe(long universe, uint8_t data[], long size) {
Serial.print(data[j+2]); Serial.print(data[j+2]);
Serial.print(" "); Serial.print(" ");
}*/ }*/
ledstrip[offset + i] = CRGB(data[j], data[j+1], data[j+2]); #ifdef RGBW_MODE
ledstrip[offset + i] = CRGB(data[j], data[j+1], data[j+2]);
#else
ledstrip[offset + i] = CRGB(data[j], data[j+1], data[j+2]);
#endif
//ledstrip[strip].setPixelColor(i + offset, data[j], data[j+1], data[j+2]); //ledstrip[strip].setPixelColor(i + offset, data[j], data[j+1], data[j+2]);
} }
//FastLED.show(); //FastLED.show();
@ -260,16 +279,19 @@ void write_universe(long universe, uint8_t data[], long size) {
} }
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); set_sys_clock_khz(252000, false);
Serial.begin(115200); pinMode(23, OUTPUT);
pinMode(23, HIGH);
//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);
pinMode(21, INPUT); // interrupt for W500
Serial.println(""); Serial.println("");
println("Starting RGB Controller..."); println("Starting RGB Controller...");
pinMode(20, OUTPUT); pinMode(20, OUTPUT);
@ -323,6 +345,7 @@ void setup() {
EEPROM.commit(); EEPROM.commit();
} }
IP_ADDR = IPAddress(EEPROM.read(0),EEPROM.read(1),EEPROM.read(2),EEPROM.read(3)); 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()) if (!IP_ADDR.isSet())
ETH_MODE = "dhcp"; ETH_MODE = "dhcp";
else else
@ -501,7 +524,11 @@ void setup1() {
int offsetcount = 0; int offsetcount = 0;
int currentsize = 0; int currentsize = 0;
for (int i = 0; i < LED_STRIPS; i++) { for (int i = 0; i < LED_STRIPS; i++) {
int tmp = strips[i]; #ifdef RGBW_MODE
int tmp = strips[i] * 3 / 4;
#else
int tmp = strips[i];
#endif
print("Strip "); print("Strip ");
Serial.print(i); Serial.print(i);
@ -519,7 +546,9 @@ void setup1() {
Serial.print(", Light count "); Serial.print(", Light count ");
Serial.print(MAX_PIXELS_PER_UNIVERSE); Serial.print(MAX_PIXELS_PER_UNIVERSE);
Serial.print(", Size "); Serial.print(", Size ");
Serial.println(MAX_PIXELS_PER_UNIVERSE * PIXEL_SIZE); Serial.print(MAX_PIXELS_PER_UNIVERSE * PIXEL_SIZE);
Serial.print(", Offset ");
Serial.println(calculate[currentsize]);
offsetcount += MAX_PIXELS_PER_UNIVERSE; offsetcount += MAX_PIXELS_PER_UNIVERSE;
currentsize += 1; currentsize += 1;
tmp -= MAX_PIXELS_PER_UNIVERSE; tmp -= MAX_PIXELS_PER_UNIVERSE;
@ -531,7 +560,9 @@ void setup1() {
Serial.print(", Light count "); Serial.print(", Light count ");
Serial.print(tmp); Serial.print(tmp);
Serial.print(", Size "); Serial.print(", Size ");
Serial.println(tmp * PIXEL_SIZE); Serial.print(tmp * PIXEL_SIZE);
Serial.print(", Offset ");
Serial.println(calculate[currentsize]);
offsetcount += tmp; offsetcount += tmp;
currentsize += 1; currentsize += 1;
} }
@ -567,13 +598,15 @@ void setup1() {
} }
FastLED.show(); FastLED.show();
// Test all lights // Test all lights
/*for (int i = 0; i < MAX_LEDS; i++) { #ifdef LIGHTTEST
ledstrip[i] = CRGB(0, 0, 50); 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(); FastLED.show();
//delay(1); #endif
ledstrip[i] = CRGB(0, 0, 0);
}
FastLED.show();*/
//delay(3000); //delay(3000);
ready += 1; ready += 1;
@ -589,6 +622,9 @@ void setup1() {
void loop() { void loop() {
/* Parse a packet */ /* Parse a packet */
//println("Start loop"); //println("Start loop");
if (millis() % 100 > 50) { // reset LED
digitalWrite(LED_BUILTIN, HIGH);
}
if(channels = e131.parsePacket()) { if(channels = e131.parsePacket()) {
// Offset by start universe // Offset by start universe
@ -625,7 +661,11 @@ void loop() {
} }
void loop1() { void loop1() {
rp2040.wdt_reset(); //rp2040.wdt_reset();
if (millis() % 100 < 50) {
//status = 0;
digitalWrite(LED_BUILTIN, LOW);
}
if(BOOTSEL) { if(BOOTSEL) {
bootsel_count++; bootsel_count++;
delay(50); delay(50);
@ -654,7 +694,7 @@ void loop1() {
} }
status2 = 1; status2 = 1;
if(status == 1 && e131.universe > START_UNIVERSE - 1 && channels > 0) { if(status == 1 && e131.universe > START_UNIVERSE - 1 && channels > 0) {
write_universe(e131.universe - START_UNIVERSE, livedata, channels); write_universe(e131.universe - START_UNIVERSE - 1, livedata, channels);
FastLED.show(); FastLED.show();
//println("Done Writing"); //println("Done Writing");
status = 0; status = 0;
@ -662,13 +702,7 @@ void loop1() {
status2 = 0; status2 = 0;
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; //status = 0;
//delay(50); //delay(50);
float cputemp2 = analogReadTemp(); float cputemp2 = analogReadTemp();

Loading…
Cancel
Save