Compare commits
4 Commits
17ef48ff82
...
neopixel-s
Author | SHA1 | Date | |
---|---|---|---|
d400850658 | |||
cb753616cc | |||
e0249dcadf | |||
181dcc98ca |
@ -13,7 +13,7 @@ platform = https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||
board = pico
|
||||
framework = arduino
|
||||
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
|
||||
upload_port = /run/media/amelia/RPI-RP2/
|
||||
debug_tool = cmsis-dap
|
||||
@ -21,7 +21,6 @@ upload_protocol = cmsis-dap
|
||||
monitor_speed = 115200
|
||||
board_build.filesystem_size = 1m
|
||||
board_build.f_cpu = 133000000L
|
||||
; build_flags = -O3
|
||||
; board_flags = -DWIFICC=CYW43_COUNTRY_USA
|
||||
lib_deps =
|
||||
https://github.com/FastLED/FastLED#master
|
||||
lib_deps =
|
||||
adafruit/Adafruit NeoPixel@^1.12.0
|
||||
adafruit/Adafruit NeoPXL8@^1.2.6
|
||||
|
52
src/FastLED_RGBW.h
Normal file
52
src/FastLED_RGBW.h
Normal file
@ -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
|
25
src/config.h
25
src/config.h
@ -3,13 +3,20 @@
|
||||
|
||||
#define DEBUG
|
||||
|
||||
// Amount of color channels per pixel - i.e. RGB = 3, RGBW = 4
|
||||
#define PIXEL_SIZE 3
|
||||
#define LIGHTTEST
|
||||
|
||||
// Total LED count
|
||||
// set to 128*8 for 4 channel, 170*8 for 3 channel
|
||||
#define MAX_LEDS 170*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
|
||||
#define LED_TYPE WS2812
|
||||
|
||||
@ -24,13 +31,13 @@
|
||||
// Define the data pin connection to each strip
|
||||
// 0-7 for ARGB Controller PCB
|
||||
#define STRIP1 0
|
||||
#define STRIP2 1
|
||||
#define STRIP3 2
|
||||
#define STRIP4 3
|
||||
#define STRIP5 4
|
||||
#define STRIP6 5
|
||||
#define STRIP7 6
|
||||
#define STRIP8 7
|
||||
// #define STRIP2 1
|
||||
// #define STRIP3 2
|
||||
// #define STRIP4 3
|
||||
// #define STRIP5 4
|
||||
// #define STRIP6 5
|
||||
// #define STRIP7 6
|
||||
// #define STRIP8 7
|
||||
|
||||
// enable pin, if any
|
||||
// 8 on ARGB controller
|
||||
|
231
src/main.cpp
231
src/main.cpp
@ -6,13 +6,15 @@
|
||||
#include <HTTPUpdateServer.h>
|
||||
#include <WebServer.h>
|
||||
#include "e131.h"
|
||||
#include <FastLED.h>
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
//#include <FastLED.h>
|
||||
//#include "FastLED_RGBW.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
|
||||
bool core1_separate_stack = true;
|
||||
|
||||
@ -24,9 +26,30 @@ bool core1_separate_stack = true;
|
||||
#define PRINTLNFUNC
|
||||
#endif
|
||||
|
||||
int calculate[LED_STRIPS * 4];
|
||||
int calculate[LED_STRIPS * 4];
|
||||
int universes[LED_STRIPS * 4];
|
||||
CRGB ledstrip[MAX_LEDS];
|
||||
|
||||
|
||||
Adafruit_NeoPixel *pixel1;
|
||||
Adafruit_NeoPixel *pixel2;
|
||||
Adafruit_NeoPixel *pixel3;
|
||||
Adafruit_NeoPixel *pixel4;
|
||||
Adafruit_NeoPixel *pixel5;
|
||||
Adafruit_NeoPixel *pixel6;
|
||||
Adafruit_NeoPixel *pixel7;
|
||||
Adafruit_NeoPixel *pixel8;
|
||||
const int strips[LED_STRIPS] = {170, 170, 170, 170, 170, 170, 170, 170};
|
||||
int offsets[(LED_STRIPS+1)];
|
||||
|
||||
// #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];
|
||||
|
||||
uint8_t * livedata;
|
||||
@ -69,15 +92,70 @@ float cputemp;
|
||||
float airtemp;
|
||||
int datapos = 0;
|
||||
|
||||
inline void setpixelrgb(int idx, byte r, byte g, byte b, byte w = 0) {
|
||||
if (idx < offsets[1]) {
|
||||
pixel1->setPixelColor(idx - offsets[0], pixel1->Color(r,g,b,w));
|
||||
}
|
||||
else if (idx < offsets[2]) {
|
||||
pixel2->setPixelColor(idx - offsets[1], pixel2->Color(r,g,b,w));
|
||||
}
|
||||
else if (idx < offsets[3]) {
|
||||
pixel3->setPixelColor(idx - offsets[2], pixel3->Color(r,g,b,w));
|
||||
}
|
||||
else if (idx < offsets[4]) {
|
||||
pixel4->setPixelColor(idx - offsets[3], pixel4->Color(r,g,b,w));
|
||||
}
|
||||
else if (idx < offsets[5]) {
|
||||
pixel5->setPixelColor(idx - offsets[4], pixel5->Color(r,g,b,w));
|
||||
}
|
||||
else if (idx < offsets[6]) {
|
||||
pixel6->setPixelColor(idx - offsets[5], pixel6->Color(r,g,b,w));
|
||||
}
|
||||
else if (idx < offsets[7]) {
|
||||
pixel7->setPixelColor(idx - offsets[6], pixel7->Color(r,g,b,w));
|
||||
}
|
||||
else if (idx < offsets[8]) {
|
||||
pixel8->setPixelColor(idx - offsets[7], pixel8->Color(r,g,b,w));
|
||||
}
|
||||
}
|
||||
|
||||
inline void showpixels() {
|
||||
#ifdef STRIP1
|
||||
pixel1->show();
|
||||
#endif
|
||||
#ifdef STRIP2
|
||||
pixel2->show();
|
||||
#endif
|
||||
#ifdef STRIP3
|
||||
pixel3->show();
|
||||
#endif
|
||||
#ifdef STRIP4
|
||||
pixel4->show();
|
||||
#endif
|
||||
#ifdef STRIP5
|
||||
pixel5->show();
|
||||
#endif
|
||||
#ifdef STRIP6
|
||||
pixel6->show();
|
||||
#endif
|
||||
#ifdef STRIP7
|
||||
pixel7->show();
|
||||
#endif
|
||||
#ifdef STRIP8
|
||||
pixel8->show();
|
||||
#endif
|
||||
|
||||
}
|
||||
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);
|
||||
return (T)true;
|
||||
}
|
||||
|
||||
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) {
|
||||
clientbuffer += String(in);
|
||||
clientbuffer += "\n";
|
||||
@ -183,9 +261,9 @@ void handleForm() {
|
||||
if(reboot) {
|
||||
EEPROM.commit();
|
||||
for (int i = 0; i < MAX_LEDS; i++) {
|
||||
ledstrip[i] = CRGB(0, 0, 0);
|
||||
setpixelrgb(i, 0, 0, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
showpixels();
|
||||
ready = 3; // trigger core 1 to stop
|
||||
delay(250);
|
||||
rp2040.reboot();
|
||||
@ -215,28 +293,31 @@ void handleNotFound() {
|
||||
|
||||
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));*/
|
||||
//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));*/
|
||||
//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) + 2 > 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)) {
|
||||
/*if(offset + write_size > sizeof(ledstrip)) {
|
||||
println("Write size too big!!");
|
||||
println(String(offset + write_size) + " with strip size " + sizeof(ledstrip));
|
||||
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
//status = 0;
|
||||
for (int i = 0; i < write_size; i++) {
|
||||
int j = i * PIXEL_SIZE + (CHANNEL_START - 1);
|
||||
@ -248,7 +329,11 @@ void write_universe(long universe, uint8_t data[], long size) {
|
||||
Serial.print(data[j+2]);
|
||||
Serial.print(" ");
|
||||
}*/
|
||||
ledstrip[offset + i] = CRGB(data[j], data[j+1], data[j+2]);
|
||||
#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();
|
||||
@ -260,16 +345,19 @@ 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);
|
||||
vreg_voltage v = VREG_VOLTAGE_1_20;
|
||||
vreg_set_voltage(v);
|
||||
set_sys_clock_khz(252000, false);
|
||||
pinMode(23, OUTPUT);
|
||||
pinMode(23, HIGH);
|
||||
Serial.begin(115200);
|
||||
//rp2040.wdt_begin(8000);
|
||||
pinMode(24, INPUT); // VBUS detect - check for USB connection
|
||||
if (digitalRead(24)) {
|
||||
delay(3000); // Wait for serial
|
||||
}
|
||||
pinMode(21, INPUT);
|
||||
//pinMode(24, INPUT); // VBUS detect - check for USB connection
|
||||
//if (digitalRead(24)) {
|
||||
// delay(3000); // Wait for serial
|
||||
//}
|
||||
|
||||
pinMode(21, INPUT); // interrupt for W500
|
||||
Serial.println("");
|
||||
println("Starting RGB Controller...");
|
||||
pinMode(20, OUTPUT);
|
||||
@ -323,6 +411,7 @@ void setup() {
|
||||
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
|
||||
@ -472,6 +561,10 @@ void setup1() {
|
||||
pinMode(32+1, OUTPUT);
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
println("Initializing LED outputs and universe mappings...");
|
||||
offsets[0] = 0;
|
||||
for (int i = 1; i <= LED_STRIPS; i++) {
|
||||
offsets[i] = offsets[i-1] + strips[i-1];
|
||||
}
|
||||
|
||||
#ifdef STRIP1
|
||||
pins[0] = STRIP1;
|
||||
@ -501,7 +594,11 @@ void setup1() {
|
||||
int offsetcount = 0;
|
||||
int currentsize = 0;
|
||||
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 ");
|
||||
Serial.print(i);
|
||||
@ -519,7 +616,9 @@ void setup1() {
|
||||
Serial.print(", Light count ");
|
||||
Serial.print(MAX_PIXELS_PER_UNIVERSE);
|
||||
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;
|
||||
currentsize += 1;
|
||||
tmp -= MAX_PIXELS_PER_UNIVERSE;
|
||||
@ -531,49 +630,63 @@ void setup1() {
|
||||
Serial.print(", Light count ");
|
||||
Serial.print(tmp);
|
||||
Serial.print(", Size ");
|
||||
Serial.println(tmp * PIXEL_SIZE);
|
||||
Serial.print(tmp * PIXEL_SIZE);
|
||||
Serial.print(", Offset ");
|
||||
Serial.println(calculate[currentsize]);
|
||||
offsetcount += tmp;
|
||||
currentsize += 1;
|
||||
}
|
||||
|
||||
#ifdef STRIP1
|
||||
FastLED.addLeds<LED_TYPE, STRIP1, RGB_ORDER>(ledstrip, calculate[0], strips[0]);
|
||||
pixel1 = new Adafruit_NeoPixel(strips[0], pins[0], NEO_GRB + NEO_KHZ800);
|
||||
pixel1->begin();
|
||||
#endif
|
||||
#ifdef STRIP2
|
||||
FastLED.addLeds<LED_TYPE, STRIP2, RGB_ORDER>(ledstrip, calculate[1], strips[1]);
|
||||
pixel2 = new Adafruit_NeoPixel(strips[1], pins[1], NEO_GRB + NEO_KHZ800);
|
||||
pixel2->begin();
|
||||
#endif
|
||||
#ifdef STRIP3
|
||||
FastLED.addLeds<LED_TYPE, STRIP3, RGB_ORDER>(ledstrip, calculate[2], strips[2]);
|
||||
pixel3 = new Adafruit_NeoPixel(strips[2], pins[2], NEO_GRB + NEO_KHZ800);
|
||||
pixel3->begin();
|
||||
#endif
|
||||
#ifdef STRIP4
|
||||
FastLED.addLeds<LED_TYPE, STRIP4, RGB_ORDER>(ledstrip, calculate[3], strips[3]);
|
||||
pixel4 = new Adafruit_NeoPixel(strips[3], pins[3], NEO_GRB + NEO_KHZ800);
|
||||
pixel4->begin();
|
||||
#endif
|
||||
#ifdef STRIP5
|
||||
FastLED.addLeds<LED_TYPE, STRIP5, RGB_ORDER>(ledstrip, calculate[4], strips[4]);
|
||||
pixel5 = new Adafruit_NeoPixel(strips[4], pins[4], NEO_GRB + NEO_KHZ800);
|
||||
pixel5->begin();
|
||||
#endif
|
||||
#ifdef STRIP6
|
||||
FastLED.addLeds<LED_TYPE, STRIP6, RGB_ORDER>(ledstrip, calculate[5], strips[5]);
|
||||
pixel6 = new Adafruit_NeoPixel(strips[5], pins[5], NEO_GRB + NEO_KHZ800);
|
||||
pixel6->begin();
|
||||
#endif
|
||||
#ifdef STRIP7
|
||||
FastLED.addLeds<LED_TYPE, STRIP7, RGB_ORDER>(ledstrip, calculate[6], strips[6]);
|
||||
pixel7 = new Adafruit_NeoPixel(strips[6], pins[6], NEO_GRB + NEO_KHZ800);
|
||||
pixel7->begin();
|
||||
#endif
|
||||
#ifdef STRIP8
|
||||
FastLED.addLeds<LED_TYPE, STRIP8, RGB_ORDER>(ledstrip, calculate[7], strips[7]);
|
||||
pixel8 = new Adafruit_NeoPixel(strips[7], pins[7], NEO_GRB + NEO_KHZ800);
|
||||
pixel8->begin();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
for (int i = 0; i < MAX_LEDS; i++) {
|
||||
ledstrip[i] = CRGB(0, 0, 0);
|
||||
setpixelrgb(i, 0, 0, 0);
|
||||
}
|
||||
FastLED.show();
|
||||
showpixels();
|
||||
// Test all lights
|
||||
/*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();*/
|
||||
#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
|
||||
//delay(3000);
|
||||
|
||||
ready += 1;
|
||||
@ -586,9 +699,13 @@ void setup1() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
void loop() {
|
||||
/* Parse a packet */
|
||||
//println("Start loop");
|
||||
if (millis() % 100 > 50) { // reset LED
|
||||
digitalWrite(LED_BUILTIN, HIGH);
|
||||
}
|
||||
|
||||
if(channels = e131.parsePacket()) {
|
||||
// Offset by start universe
|
||||
@ -625,7 +742,11 @@ void loop() {
|
||||
}
|
||||
|
||||
void loop1() {
|
||||
rp2040.wdt_reset();
|
||||
//rp2040.wdt_reset();
|
||||
if (millis() % 100 < 50) {
|
||||
//status = 0;
|
||||
digitalWrite(LED_BUILTIN, LOW);
|
||||
}
|
||||
if(BOOTSEL) {
|
||||
bootsel_count++;
|
||||
delay(50);
|
||||
@ -654,21 +775,15 @@ void loop1() {
|
||||
}
|
||||
status2 = 1;
|
||||
if(status == 1 && e131.universe > START_UNIVERSE - 1 && channels > 0) {
|
||||
write_universe(e131.universe - START_UNIVERSE, livedata, channels);
|
||||
FastLED.show();
|
||||
write_universe(e131.universe - START_UNIVERSE - 1, livedata, channels);
|
||||
showpixels();
|
||||
//println("Done Writing");
|
||||
status = 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;
|
||||
//delay(50);
|
||||
float cputemp2 = analogReadTemp();
|
||||
|
Reference in New Issue
Block a user