-
Notifications
You must be signed in to change notification settings - Fork 3
/
sketch_aug05c.ino
240 lines (146 loc) · 4.29 KB
/
sketch_aug05c.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiUdp.h>
#define USE_SPI 1
#define FASTLED_ALLOW_INTERRUPTS 0
#define INTERRUPT_THRESHOLD 1
#include "FastLED.h"
FASTLED_USING_NAMESPACE
#define FASTLED_SHOW_CORE 0
WiFiUDP Udp2;
#define LED_WIDTH 123
#define LED_HEIGHT 48
#define NUM_LEDS LED_WIDTH*LED_HEIGHT
CRGB leds[NUM_LEDS];
CRGB Tpic[NUM_LEDS];
char *artnetPacket2;
// Artnet settings
//Artnet artnet;
CRGB artnetled[32*32];
//manage the the core0
// -- Task handles for use in the notifications
static TaskHandle_t FastLEDshowTaskHandle2 = 0;
static TaskHandle_t userTaskHandle = 0;
void FastLEDshowESP322()
{
if (userTaskHandle == 0) {
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 200 );
// -- Store the handle of the current task, so that the show task can
// notify it when it's done
// noInterrupts();
userTaskHandle = xTaskGetCurrentTaskHandle();
// -- Trigger the show task
xTaskNotifyGive(FastLEDshowTaskHandle2);
//to thge contrary to the other one we do not wait for the display task to come back
}
}
void FastLEDshowTask2(void *pvParameters)
{
const TickType_t xMaxBlockTime = pdMS_TO_TICKS( 500 );
// -- Run forever...
for(;;) {
// -- Wait for the trigger
ulTaskNotifyTake(pdTRUE,portMAX_DELAY);
memcpy(leds,Tpic,LED_WIDTH*LED_HEIGHT*sizeof(CRGB));
FastLED.show();
userTaskHandle=0; //so we can't have two display tasks at the same time
}
}
void fill(CRGB color)
{
fill_solid(leds, NUM_LEDS, color);
fill_solid(Tpic, NUM_LEDS, color);
}
bool firsttime=true;
uint32_t syncmax1=0;
uint32_t syncmax2=0;
void setup() {
Serial.begin(115200);
xTaskCreatePinnedToCore(FastLEDshowTask2, "FastLEDshowTask2", 1000, NULL,3, &FastLEDshowTaskHandle2, FASTLED_SHOW_CORE);
FastLED.addLeds<NEOPIXEL, 12>(leds, 0, NUM_LEDS);
//or your way of calling the led
FastLED.setBrightness(64);
fill(CRGB::Black);
FastLED.show();
FastLED.delay(2000);
WiFi.mode(WIFI_STA);
Serial.printf("Connecting to %s\n", "");
Serial.printf("Connecting ");
WiFi.begin("xxxxx", "xxxx");
//WiFi.begin("DomainePutterie", "Jeremyyves");
while (WiFi.status() != WL_CONNECTED) {
Serial.println(WiFi.status());
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
//server.begin();
int nbNeededUniverses=LED_HEIGHT/2;
if(nbNeededUniverses<=32)
{
if(nbNeededUniverses<32)
syncmax1=(1<<nbNeededUniverses)-1;
else
syncmax1=0xFFFFFFFF;
syncmax2=0;
}
else
{
syncmax1=0xFFFFFFFF;
if(nbNeededUniverses-32<32)
syncmax2=(1<<(nbNeededUniverses-32))-1;
else
syncmax2=0xFFFFFFFF;
//syncmax2=0;
}
Udp2.begin(100);
artnetPacket2=(char*)malloc((LED_WIDTH*3*2+1)*sizeof(char));
if(artnetPacket2==NULL)
{
Serial.println("impossible to create buffer");
return;
}
else
{
Serial.println("buffer créé");
}
}
void loop() {
uint32_t sync=0;
uint32_t sync2=0;
while (sync!=syncmax1 or sync2!=syncmax2)//sync!=syncmax or sync2!=syncmax2
{
int packetSize = Udp2.parsePacket();
if(packetSize>0)
{
Udp2.read(artnetPacket2, packetSize);
memcpy(&Tpic[LED_WIDTH*2*(artnetPacket2[0])],artnetPacket2 + 1,LED_WIDTH*3*2);
//Serial.printf("univers:%d\n",artnetPacket2[0]);
if(artnetPacket2[0]==255)
{
Serial.printf("new value bru:%d\n",artnetPacket2[1]);
FastLED.setBrightness(artnetPacket2[1]);
}
else
{
if (artnetPacket2[0]==0)
{
sync=1;
sync2=0;
}
else
{
if(artnetPacket2[0]<32)
sync=sync | (1<<artnetPacket2[0]);
else
sync2=sync2 | (1<<(artnetPacket2[0]-32));
}
}
//free(artnetPacket);
}
}
FastLEDshowESP322();
}