Skip to content

Commit 32a04f4

Browse files
authored
Merge pull request #4 from miles-p/punch/add_ui
Punch/add UI
2 parents 82bf6e8 + ab184dd commit 32a04f4

3 files changed

Lines changed: 176 additions & 34 deletions

File tree

include/main.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#ifndef MAIN_H
2+
#define MAIN_H
3+
4+
#include <Arduino.h>
5+
#include <SPI.h>
6+
#include <Ethernet.h>
7+
#include <EthernetUdp.h>
8+
#include <ArtnetEther.h>
9+
#include <FastLED.h>
10+
11+
// Config switches
12+
#define DEBUG 0 // 1: DEBUG at 115200, 0: No DEBUG
13+
#define DHCP 1 // 1: Use DHCP, 0: Use static IP as defined in main
14+
#define TEST_MODE 1 // 1: Just run some LEDs on Red, 0: normal behaviour
15+
16+
// Pin definitions
17+
#define WS2812_DATA_PIN 6
18+
#define NETWORK_STATUS_PIN 4
19+
#define LED_WRITE_STATUS_PIN 3
20+
21+
// LED Configuration
22+
#define NUM_LEDS 33
23+
#define ARTNET_PORT 6454
24+
#define START_UNIVERSE 0 // we may not want to begin on universe 0 (remember that artnet is 0-indexed)
25+
#define LEDS_PER_UNIVERSE 170
26+
#define CHANNELS_PER_UNIVERSE (LEDS_PER_UNIVERSE * 3)
27+
28+
// Calculated constants
29+
extern const uint8_t NUM_UNIVERSES;
30+
extern const uint8_t ALL_UNI_MASK;
31+
32+
// Network configuration
33+
extern byte mac[];
34+
extern IPAddress ip;
35+
extern ArtnetEtherReceiver artnet;
36+
37+
// LED data
38+
extern CRGB leds[];
39+
extern uint8_t universesReceived;
40+
extern unsigned long lastShowTime;
41+
extern const unsigned long MIN_SHOW_INTERVAL;
42+
43+
// Function declarations
44+
void led_status(String led, bool state);
45+
void artnet_callback(const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote);
46+
void led_hello();
47+
void led_oh_shit(int led_pin);
48+
void init_leds();
49+
void init_networking();
50+
51+
#endif // MAIN_H

platformio.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@
1212
platform = atmelavr
1313
board = uno
1414
framework = arduino
15-
monitor_speed = 115200
15+
upload_protocol = usbtiny
16+
upload_flags = -e

src/main.cpp

Lines changed: 123 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,36 @@
44
// All Rights Reserved 2025
55
// Licensed under the GNU GPL License.
66

7-
#define DEBUG 1 // 1: DEBUG at 115200, 0: No DEBUG
8-
9-
// Required libraries
10-
#include <SPI.h>
11-
#include <Ethernet.h>
12-
#include <EthernetUdp.h>
13-
#include <ArtnetEther.h>
14-
#include <FastLED.h>
15-
16-
// Defined constants
17-
#define LED_PIN 6
18-
#define NUM_LEDS 33
19-
#define ARTNET_PORT 6454
20-
#define START_UNIVERSE 0 // we may not want to begin on universe 0 (remember that artnet is 0-indexed)
21-
#define LEDS_PER_UNIVERSE 170
22-
#define CHANNELS_PER_UNIVERSE (LEDS_PER_UNIVERSE * 3)
23-
24-
// Tracking for smart refresh
7+
#include "main.h"
8+
9+
// Global variable definitions
2510
const uint8_t NUM_UNIVERSES = (NUM_LEDS + LEDS_PER_UNIVERSE - 1) / LEDS_PER_UNIVERSE;
2611
const uint8_t ALL_UNI_MASK = (1 << NUM_UNIVERSES) - 1;
2712

28-
29-
// Static IP and MAC address
3013
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
31-
IPAddress ip(192, 168, 1, 50); // Set your desired static IP here
14+
IPAddress ip(192, 168, 1, 50);
3215
ArtnetEtherReceiver artnet;
3316

34-
/// @brief Array to hold the LED data
3517
CRGB leds[NUM_LEDS];
3618
uint8_t universesReceived = 0;
3719
unsigned long lastShowTime = 0;
3820
const unsigned long MIN_SHOW_INTERVAL = 8; // ~125fps max
3921

40-
void artnet_callback(
41-
const uint8_t *data, uint16_t size,
42-
const ArtDmxMetadata &metadata,
43-
const ArtNetRemoteInfo &remote
44-
) {
22+
void led_status(String led, bool state) {
23+
#if DEBUG
24+
Serial.print(led);
25+
Serial.print(" LED is now ");
26+
Serial.println(state ? "ON" : "OFF");
27+
#endif
28+
29+
if (led == "network") {
30+
digitalWrite(NETWORK_STATUS_PIN, state ? HIGH : LOW);
31+
} else if (led == "led_write") {
32+
digitalWrite(LED_WRITE_STATUS_PIN, state ? HIGH : LOW);
33+
}
34+
}
35+
36+
void artnet_callback( const uint8_t *data, uint16_t size, const ArtDmxMetadata &metadata, const ArtNetRemoteInfo &remote ) {
4537
uint8_t rel = metadata.universe - START_UNIVERSE;
4638
if (rel >= NUM_UNIVERSES) return;
4739

@@ -62,27 +54,115 @@ void artnet_callback(
6254
Serial.println(universesReceived, HEX);
6355
#endif
6456

65-
if (universesReceived == ALL_UNI_MASK &&
66-
now - lastShowTime >= MIN_SHOW_INTERVAL) {
67-
57+
if (universesReceived == ALL_UNI_MASK && now - lastShowTime >= MIN_SHOW_INTERVAL) {
58+
led_status("led_write", true);
6859
FastLED.show();
6960
lastShowTime = now;
7061
universesReceived = 0;
62+
led_status("led_write", false);
7163
}
7264
}
7365

66+
void led_hello() {
67+
// do a little dance to say hello
68+
digitalWrite(LED_WRITE_STATUS_PIN, HIGH);
69+
delay(200);
70+
digitalWrite(LED_WRITE_STATUS_PIN, LOW);
71+
delay(200);
72+
digitalWrite(LED_WRITE_STATUS_PIN, HIGH);
73+
delay(200);
74+
digitalWrite(LED_WRITE_STATUS_PIN, LOW);
75+
delay(200);
76+
77+
digitalWrite(NETWORK_STATUS_PIN, HIGH);
78+
delay(200);
79+
digitalWrite(NETWORK_STATUS_PIN, LOW);
80+
delay(200);
81+
digitalWrite(NETWORK_STATUS_PIN, HIGH);
82+
delay(200);
83+
digitalWrite(NETWORK_STATUS_PIN, LOW);
84+
delay(200);
85+
86+
digitalWrite(LED_WRITE_STATUS_PIN, HIGH);
87+
digitalWrite(NETWORK_STATUS_PIN, HIGH);
88+
delay(200);
89+
digitalWrite(LED_WRITE_STATUS_PIN, LOW);
90+
digitalWrite(NETWORK_STATUS_PIN, LOW);
91+
delay(200);
92+
digitalWrite(LED_WRITE_STATUS_PIN, HIGH);
93+
digitalWrite(NETWORK_STATUS_PIN, HIGH);
94+
delay(200);
95+
digitalWrite(LED_WRITE_STATUS_PIN, LOW);
96+
digitalWrite(NETWORK_STATUS_PIN, LOW);
97+
delay(200);
98+
digitalWrite(LED_WRITE_STATUS_PIN, HIGH);
99+
digitalWrite(NETWORK_STATUS_PIN, HIGH);
100+
delay(200);
101+
digitalWrite(LED_WRITE_STATUS_PIN, LOW);
102+
digitalWrite(NETWORK_STATUS_PIN, LOW);
103+
delay(200);
104+
digitalWrite(LED_WRITE_STATUS_PIN, HIGH);
105+
digitalWrite(NETWORK_STATUS_PIN, HIGH);
106+
delay(200);
107+
digitalWrite(LED_WRITE_STATUS_PIN, LOW);
108+
digitalWrite(NETWORK_STATUS_PIN, LOW);
109+
delay(200);
110+
}
111+
112+
void led_oh_shit(int led_pin) {
113+
while(1) {
114+
digitalWrite(led_pin, HIGH);
115+
delay(250);
116+
digitalWrite(led_pin, LOW);
117+
delay(250);
118+
}
119+
}
74120

75121
void init_leds() {
76-
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
122+
// initialize FastLED
123+
FastLED.addLeds<WS2812B, WS2812_DATA_PIN, GRB>(leds, NUM_LEDS);
77124
FastLED.setMaxRefreshRate(0); // Remove artificial frame rate limit
78125
FastLED.setDither(false);
79126
FastLED.setCorrection(UncorrectedColor);
80127
FastLED.clear();
81128
FastLED.show();
129+
130+
// initialize status pins
131+
pinMode(NETWORK_STATUS_PIN, OUTPUT);
132+
pinMode(LED_WRITE_STATUS_PIN, OUTPUT);
133+
134+
led_hello();
82135
}
83136

84137
void init_networking() {
85-
Ethernet.begin(mac, ip);
138+
if (DHCP) {
139+
if (Ethernet.begin(mac)) {
140+
// DHCP configured successfully :)
141+
} else {
142+
// shit shit shit shit shit
143+
led_oh_shit(NETWORK_STATUS_PIN);
144+
}
145+
} else {
146+
Ethernet.begin(mac, ip);
147+
}
148+
149+
if (Ethernet.linkStatus() == LinkON) {
150+
led_status("network", true);
151+
} else {
152+
led_oh_shit(NETWORK_STATUS_PIN);
153+
}
154+
155+
#if DEBUG
156+
Serial.print("Ethernet initialized with IP: ");
157+
Serial.println(Ethernet.localIP());
158+
Serial.print("Subnet Mask: ");
159+
Serial.println(Ethernet.subnetMask());
160+
Serial.print("Gateway IP: ");
161+
Serial.println(Ethernet.gatewayIP());
162+
Serial.print("Link Status: ");
163+
Serial.println(Ethernet.linkStatus() == LinkON ? "LinkON" : "LinkOFF");
164+
#endif
165+
86166
delay(100);
87167
artnet.begin(ARTNET_PORT);
88168
artnet.subscribeArtDmx(artnet_callback);
@@ -106,5 +186,15 @@ void setup() {
106186
}
107187

108188
void loop() {
109-
artnet.parse();
189+
if (TEST_MODE) {
190+
for (int i = 0; i < NUM_LEDS; i++) {
191+
leds[i] = CRGB::Red;
192+
}
193+
194+
FastLED.show();
195+
while (1); // halt!
196+
197+
} else {
198+
artnet.parse();
199+
}
110200
}

0 commit comments

Comments
 (0)