From 5423fcb44fcb49b99033270cf0a720c5b2bffe01 Mon Sep 17 00:00:00 2001 From: Miles Punch <71351127+miles-p@users.noreply.github.com> Date: Wed, 26 Nov 2025 12:38:58 +1100 Subject: [PATCH 1/4] status LEDs working --- src/main.cpp | 59 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 13 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index b63bf95..8aef7e3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,7 @@ // All Rights Reserved 2025 // Licensed under the GNU GPL License. -#define DEBUG 1 // 1: DEBUG at 115200, 0: No DEBUG +#define DEBUG 0 // 1: DEBUG at 115200, 0: No DEBUG // Required libraries #include @@ -14,7 +14,9 @@ #include // Defined constants -#define LED_PIN 6 +#define WS2812_DATA_PIN 6 +#define NETWORK_STATUS_PIN 3 +#define LED_WRITE_STATUS_PIN 4 #define NUM_LEDS 33 #define ARTNET_PORT 6454 #define START_UNIVERSE 0 // we may not want to begin on universe 0 (remember that artnet is 0-indexed) @@ -25,7 +27,6 @@ const uint8_t NUM_UNIVERSES = (NUM_LEDS + LEDS_PER_UNIVERSE - 1) / LEDS_PER_UNIVERSE; const uint8_t ALL_UNI_MASK = (1 << NUM_UNIVERSES) - 1; - // Static IP and MAC address byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress ip(192, 168, 1, 50); // Set your desired static IP here @@ -37,11 +38,21 @@ uint8_t universesReceived = 0; unsigned long lastShowTime = 0; const unsigned long MIN_SHOW_INTERVAL = 8; // ~125fps max -void artnet_callback( - const uint8_t *data, uint16_t size, - const ArtDmxMetadata &metadata, - const ArtNetRemoteInfo &remote -) { +void led_status(String led, bool state) { + #if DEBUG + Serial.print(led); + Serial.print(" LED is now "); + Serial.println(state ? "ON" : "OFF"); + #endif + + if (led == "network") { + digitalWrite(NETWORK_STATUS_PIN, state ? HIGH : LOW); + } else if (led == "led_write") { + digitalWrite(LED_WRITE_STATUS_PIN, state ? HIGH : LOW); + } +} + +void artnet_callback( const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote ) { uint8_t rel = metadata.universe - START_UNIVERSE; if (rel >= NUM_UNIVERSES) return; @@ -62,27 +73,49 @@ void artnet_callback( Serial.println(universesReceived, HEX); #endif - if (universesReceived == ALL_UNI_MASK && - now - lastShowTime >= MIN_SHOW_INTERVAL) { - + if (universesReceived == ALL_UNI_MASK && now - lastShowTime >= MIN_SHOW_INTERVAL) { + led_status("led_write", true); FastLED.show(); lastShowTime = now; universesReceived = 0; + led_status("led_write", false); } } - void init_leds() { - FastLED.addLeds(leds, NUM_LEDS); + // initialize FastLED + FastLED.addLeds(leds, NUM_LEDS); FastLED.setMaxRefreshRate(0); // Remove artificial frame rate limit FastLED.setDither(false); FastLED.setCorrection(UncorrectedColor); FastLED.clear(); FastLED.show(); + + // initialize status pins + pinMode(NETWORK_STATUS_PIN, OUTPUT); + pinMode(LED_WRITE_STATUS_PIN, OUTPUT); } void init_networking() { Ethernet.begin(mac, ip); + + #if DEBUG + Serial.print("Ethernet initialized with IP: "); + Serial.println(Ethernet.localIP()); + Serial.print("Subnet Mask: "); + Serial.println(Ethernet.subnetMask()); + Serial.print("Gateway IP: "); + Serial.println(Ethernet.gatewayIP()); + Serial.print("Link Status: "); + Serial.println(Ethernet.linkStatus() == LinkON ? "LinkON" : "LinkOFF"); + #endif + + if (Ethernet.linkStatus() == LinkOFF) { + led_status("network", false); + } else { + led_status("network", true); + } + delay(100); artnet.begin(ARTNET_PORT); artnet.subscribeArtDmx(artnet_callback); From 0fab3f3b03e1368614969767d6fd1abcffe96d35 Mon Sep 17 00:00:00 2001 From: Miles Punch <71351127+miles-p@users.noreply.github.com> Date: Fri, 5 Dec 2025 17:46:22 +1100 Subject: [PATCH 2/4] led now has warning status indicator --- include/main.h | 13 +++++++ platformio.ini | 3 +- src/main.cpp | 92 ++++++++++++++++++++++++++++++++++++++++---------- 3 files changed, 89 insertions(+), 19 deletions(-) create mode 100644 include/main.h diff --git a/include/main.h b/include/main.h new file mode 100644 index 0000000..6815b4c --- /dev/null +++ b/include/main.h @@ -0,0 +1,13 @@ +// config switches +#define DEBUG 0 // 1: DEBUG at 115200, 0: No DEBUG +#define DHCP 1 // 1: Use DHCP, 0: Use static IP as defined in main + +// Defined constants +#define WS2812_DATA_PIN 6 +#define NETWORK_STATUS_PIN 4 +#define LED_WRITE_STATUS_PIN 3 +#define NUM_LEDS 33 +#define ARTNET_PORT 6454 +#define START_UNIVERSE 0 // we may not want to begin on universe 0 (remember that artnet is 0-indexed) +#define LEDS_PER_UNIVERSE 170 +#define CHANNELS_PER_UNIVERSE (LEDS_PER_UNIVERSE * 3) \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index cf558c0..6897eb7 100644 --- a/platformio.ini +++ b/platformio.ini @@ -12,4 +12,5 @@ platform = atmelavr board = uno framework = arduino -monitor_speed = 115200 \ No newline at end of file +upload_protocol = usbtiny +upload_flags = -e \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index 8aef7e3..91547f0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,8 +4,6 @@ // All Rights Reserved 2025 // Licensed under the GNU GPL License. -#define DEBUG 0 // 1: DEBUG at 115200, 0: No DEBUG - // Required libraries #include #include @@ -13,15 +11,7 @@ #include #include -// Defined constants -#define WS2812_DATA_PIN 6 -#define NETWORK_STATUS_PIN 3 -#define LED_WRITE_STATUS_PIN 4 -#define NUM_LEDS 33 -#define ARTNET_PORT 6454 -#define START_UNIVERSE 0 // we may not want to begin on universe 0 (remember that artnet is 0-indexed) -#define LEDS_PER_UNIVERSE 170 -#define CHANNELS_PER_UNIVERSE (LEDS_PER_UNIVERSE * 3) +#include "main.h" // Tracking for smart refresh const uint8_t NUM_UNIVERSES = (NUM_LEDS + LEDS_PER_UNIVERSE - 1) / LEDS_PER_UNIVERSE; @@ -82,6 +72,61 @@ void artnet_callback( const uint8_t *data, uint16_t size, const ArtDmxMetadata & } } +void led_hello() { + // do a little dance to say hello + digitalWrite(LED_WRITE_STATUS_PIN, HIGH); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, LOW); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, HIGH); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, LOW); + delay(200); + + digitalWrite(NETWORK_STATUS_PIN, HIGH); + delay(200); + digitalWrite(NETWORK_STATUS_PIN, LOW); + delay(200); + digitalWrite(NETWORK_STATUS_PIN, HIGH); + delay(200); + digitalWrite(NETWORK_STATUS_PIN, LOW); + delay(200); + + digitalWrite(LED_WRITE_STATUS_PIN, HIGH); + digitalWrite(NETWORK_STATUS_PIN, HIGH); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, LOW); + digitalWrite(NETWORK_STATUS_PIN, LOW); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, HIGH); + digitalWrite(NETWORK_STATUS_PIN, HIGH); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, LOW); + digitalWrite(NETWORK_STATUS_PIN, LOW); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, HIGH); + digitalWrite(NETWORK_STATUS_PIN, HIGH); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, LOW); + digitalWrite(NETWORK_STATUS_PIN, LOW); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, HIGH); + digitalWrite(NETWORK_STATUS_PIN, HIGH); + delay(200); + digitalWrite(LED_WRITE_STATUS_PIN, LOW); + digitalWrite(NETWORK_STATUS_PIN, LOW); + delay(200); +} + +void led_oh_shit(int led_pin) { + while(1) { + digitalWrite(led_pin, HIGH); + delay(250); + digitalWrite(led_pin, LOW); + delay(250); + } +} + void init_leds() { // initialize FastLED FastLED.addLeds(leds, NUM_LEDS); @@ -94,10 +139,27 @@ void init_leds() { // initialize status pins pinMode(NETWORK_STATUS_PIN, OUTPUT); pinMode(LED_WRITE_STATUS_PIN, OUTPUT); + + led_hello(); } void init_networking() { - Ethernet.begin(mac, ip); + if (DHCP) { + if (Ethernet.begin(mac)) { + // DHCP configured successfully :) + } else { + // shit shit shit shit shit + led_oh_shit(NETWORK_STATUS_PIN); + } + } else { + Ethernet.begin(mac, ip); + } + + if (Ethernet.linkStatus() == LinkON) { + led_status("network", true); + } else { + led_oh_shit(NETWORK_STATUS_PIN); + } #if DEBUG Serial.print("Ethernet initialized with IP: "); @@ -110,12 +172,6 @@ void init_networking() { Serial.println(Ethernet.linkStatus() == LinkON ? "LinkON" : "LinkOFF"); #endif - if (Ethernet.linkStatus() == LinkOFF) { - led_status("network", false); - } else { - led_status("network", true); - } - delay(100); artnet.begin(ARTNET_PORT); artnet.subscribeArtDmx(artnet_callback); From 258c06991a889900af0e918f2762c5f7a89bfbd2 Mon Sep 17 00:00:00 2001 From: Miles Punch <71351127+miles-p@users.noreply.github.com> Date: Fri, 5 Dec 2025 19:37:14 +1100 Subject: [PATCH 3/4] added TEST_MODE --- include/main.h | 1 + src/main.cpp | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/include/main.h b/include/main.h index 6815b4c..c0ea9fb 100644 --- a/include/main.h +++ b/include/main.h @@ -1,6 +1,7 @@ // config switches #define DEBUG 0 // 1: DEBUG at 115200, 0: No DEBUG #define DHCP 1 // 1: Use DHCP, 0: Use static IP as defined in main +#define TEST_MODE 1 // 1: Just run some LEDs on Red, 0: normal behaviour // Defined constants #define WS2812_DATA_PIN 6 diff --git a/src/main.cpp b/src/main.cpp index 91547f0..d9a94bd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -195,5 +195,15 @@ void setup() { } void loop() { - artnet.parse(); + if (TEST_MODE) { + for (int i = 0; i < NUM_LEDS; i++) { + leds[i] = CRGB::Red; + } + + FastLED.show(); + while (1); // halt! + + } else { + artnet.parse(); + } } From ab184dde3b72c604cb582b85529eb3f511e1823b Mon Sep 17 00:00:00 2001 From: Miles Punch <71351127+miles-p@users.noreply.github.com> Date: Fri, 5 Dec 2025 19:50:40 +1100 Subject: [PATCH 4/4] me when i refactor the entire codebase :O --- include/main.h | 43 ++++++++++++++++++++++++++++++++++++++++--- src/main.cpp | 13 ++----------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/include/main.h b/include/main.h index c0ea9fb..9980393 100644 --- a/include/main.h +++ b/include/main.h @@ -1,14 +1,51 @@ -// config switches +#ifndef MAIN_H +#define MAIN_H + +#include +#include +#include +#include +#include +#include + +// Config switches #define DEBUG 0 // 1: DEBUG at 115200, 0: No DEBUG #define DHCP 1 // 1: Use DHCP, 0: Use static IP as defined in main #define TEST_MODE 1 // 1: Just run some LEDs on Red, 0: normal behaviour -// Defined constants +// Pin definitions #define WS2812_DATA_PIN 6 #define NETWORK_STATUS_PIN 4 #define LED_WRITE_STATUS_PIN 3 + +// LED Configuration #define NUM_LEDS 33 #define ARTNET_PORT 6454 #define START_UNIVERSE 0 // we may not want to begin on universe 0 (remember that artnet is 0-indexed) #define LEDS_PER_UNIVERSE 170 -#define CHANNELS_PER_UNIVERSE (LEDS_PER_UNIVERSE * 3) \ No newline at end of file +#define CHANNELS_PER_UNIVERSE (LEDS_PER_UNIVERSE * 3) + +// Calculated constants +extern const uint8_t NUM_UNIVERSES; +extern const uint8_t ALL_UNI_MASK; + +// Network configuration +extern byte mac[]; +extern IPAddress ip; +extern ArtnetEtherReceiver artnet; + +// LED data +extern CRGB leds[]; +extern uint8_t universesReceived; +extern unsigned long lastShowTime; +extern const unsigned long MIN_SHOW_INTERVAL; + +// Function declarations +void led_status(String led, bool state); +void artnet_callback(const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote); +void led_hello(); +void led_oh_shit(int led_pin); +void init_leds(); +void init_networking(); + +#endif // MAIN_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index d9a94bd..6822c75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,25 +4,16 @@ // All Rights Reserved 2025 // Licensed under the GNU GPL License. -// Required libraries -#include -#include -#include -#include -#include - #include "main.h" -// Tracking for smart refresh +// Global variable definitions const uint8_t NUM_UNIVERSES = (NUM_LEDS + LEDS_PER_UNIVERSE - 1) / LEDS_PER_UNIVERSE; const uint8_t ALL_UNI_MASK = (1 << NUM_UNIVERSES) - 1; -// Static IP and MAC address byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; -IPAddress ip(192, 168, 1, 50); // Set your desired static IP here +IPAddress ip(192, 168, 1, 50); ArtnetEtherReceiver artnet; -/// @brief Array to hold the LED data CRGB leds[NUM_LEDS]; uint8_t universesReceived = 0; unsigned long lastShowTime = 0;