-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain_runlights.cpp
352 lines (314 loc) · 14.1 KB
/
main_runlights.cpp
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
//Adapted from C# code from Linked2 Software (www.Linked2Software.com) Building Lighting Control Systems
//DMX-512 Test Application Visual Studio 2012 C++
//Original C# written by Richard A. Blackwell with example source provided by Enttec.com
//New C++ adapation written by Chloe A. LeGendre
//
//ref: DMX controller with FTDI driver: https://www.enttec.com/?main_menu=Products&pn=70303
//ref: 64-bit .dll installed in C:/Windows/System32 from http://www.ftdichip.com/Drivers/CDM/CDM21218_Setup.zip
//ref: DLLs the Dynamic Way https://msdn.microsoft.com/en-us/library/ms810279.aspx
//ref: what is DMX? http://dmxusb.com/what-is-dmx/
//ref: light 1 example RGBW: https://www.amazon.com/Coidak-CO820-12LEDs-Colorful-DMX512/dp/B01CTVHUAK/
//ref: light 2 example RGBAW: http://www.blizzardlighting.com/products/par-cans-and-wash-lights/item/355-hotbox-5-rgbaw
#include "stdafx.h"
#include <iostream>
#include "RGBxx.h"
#include "OpenDMX.h"
#include "DMXLight.h"
#include "lightGroup.h"
//required for DLL loading and some data types
#include <windows.h>
//load DLL **CHANGE FILENAME HERE**
bool loadDLL(HINSTANCE &dllHandle){
//absolute path filename of DLL **CHANGE HERE**
wchar_t* file = L"C:\\Users\\legendre\\Documents\\Visual Studio 2012\\Projects\\DMX_CPP\\DMX_CPP\\ftd2xx.dll";
//try to load DLL
dllHandle = LoadLibrary(file);
if ( NULL == dllHandle) {
std::cout << "Could not load the dynamic library" << std::endl;
return true;
}
else return false; //success
}
int main(int argc, char* argv[]){
DWORD milliseconds = 25; //suggested interval for DMX
bool isVerbose = false; //set to true for logging DMX status to console for debugging purposes
OpenDMX myOpenDMX = OpenDMX::OpenDMX(isVerbose);
HINSTANCE dllHandle_ = NULL;
bool failure = loadDLL(dllHandle_);
if (!failure){
myOpenDMX.dllHandle = dllHandle_;
failure = myOpenDMX.start();
if (!failure){ //if we successfully started DMX communication.
bool failure = myOpenDMX.initOpenDMX();
if (failure){
return failure;
}
//---------
//make a light. RGBW example (Coidak)
//---------
int light1_startIDX = 1; //program this number with buttons on the light - the DMX light address
//this information comes from the help booklet for your light, describing the DMX channels used by the light.
int light1_numChannels = 8;
int light1_numColors = 4; //RGBW
bool light1_has_master_dimming = true;
bool light1_has_amber_channel = false;
int light1_master_dimming_channel = 4;
int light1_red_dimming_channel = 5;
int light1_green_dimming_channel = 6;
int light1_blue_dimming_channel = 7;
int light1_white_dimming_channel = 8;
//constructor and initialization
DMXLight myRGBWLight = DMXLight::DMXLight("RGBW Coidak", light1_startIDX, light1_numColors, light1_numChannels);
myRGBWLight.setRChannel(light1_red_dimming_channel);
myRGBWLight.setGChannel(light1_green_dimming_channel);
myRGBWLight.setBChannel(light1_blue_dimming_channel);
myRGBWLight.setWChannel(light1_white_dimming_channel);
myRGBWLight.setHasDimmingChannel(light1_has_master_dimming);
myRGBWLight.setDimmingChannel(light1_master_dimming_channel);
myRGBWLight.setHasAmberChannel(light1_has_amber_channel);
if (!myRGBWLight.lightCorrectlyInitialized()){
system("pause");
return 1;
}
//---------
//make a light. RGBAW example (Blizzard hotbox)
//---------
int light2_startIDX = 9; //program this number with buttons on the light - the DMX light address
//this information comes from the help booklet for your light, describing the DMX channels used by the light.
int light2_numChannels = 5;
int light2_numColors = 5;
bool light2_has_master_dimming = false;
int light2_red_dimming_channel = 1;
int light2_green_dimming_channel = 2;
int light2_blue_dimming_channel = 3;
int light2_amber_dimming_channel = 4;
int light2_white_dimming_channel = 5;
//constructor and initialization
DMXLight myRGBAWLight = DMXLight::DMXLight("RGBAW Blizzard Hotbox", light2_startIDX, light2_numColors, light2_numChannels);
myRGBAWLight.setRChannel(light2_red_dimming_channel);
myRGBAWLight.setGChannel(light2_green_dimming_channel);
myRGBAWLight.setBChannel(light2_blue_dimming_channel);
myRGBAWLight.setAChannel(light2_amber_dimming_channel);
myRGBAWLight.setWChannel(light2_white_dimming_channel);
myRGBAWLight.setHasDimmingChannel(light2_has_master_dimming);
if (!myRGBAWLight.lightCorrectlyInitialized()){
system("pause");
return 1;
}
/*
//---------
//test some automatic functions for light 1 only
//---------
myRGBWLight.allColorsRampDown(myOpenDMX,1,milliseconds);
myRGBWLight.allRedOn(myOpenDMX,1,milliseconds);
myRGBWLight.allBlueOn(myOpenDMX,1,milliseconds);
myRGBWLight.allGreenOn(myOpenDMX,1,milliseconds);
myRGBWLight.allWhiteOn(myOpenDMX,1,milliseconds);
myRGBWLight.randomPattern(myOpenDMX,1,milliseconds);
myRGBWLight.rainbowCrossDissolve(myOpenDMX,2,milliseconds);
*/
/*
//---------
//test some automatic functions for light 2 only
//---------
myRGBAWLight.allColorsRampDown(myOpenDMX,1,milliseconds);
myRGBAWLight.allRedOn(myOpenDMX,1,milliseconds);
myRGBAWLight.allBlueOn(myOpenDMX,1,milliseconds);
myRGBAWLight.allGreenOn(myOpenDMX,1,milliseconds);
myRGBAWLight.allWhiteOn(myOpenDMX,1,milliseconds);
myRGBAWLight.randomPattern(myOpenDMX,1,milliseconds);
myRGBAWLight.rainbowCrossDissolve(myOpenDMX,2,milliseconds);
*/
//---------
//make a light group and add lights to it
//---------
lightGroup myLights = lightGroup::lightGroup();
myLights.addLight(myRGBWLight);
myLights.addLight(myRGBAWLight);
/*
//---------
//test some automatic functions for light group
//---------
myLights.allOnSingleColor(myOpenDMX, "r", 1, milliseconds);
myLights.allOnSingleColor(myOpenDMX, "g", 1, milliseconds);
myLights.allOnSingleColor(myOpenDMX, "b", 1, milliseconds);
myLights.allOnSingleColor(myOpenDMX, "a", 1, milliseconds);
myLights.allOnSingleColor(myOpenDMX, "w", 1, milliseconds);
myLights.rainbowCrossDissolve(myOpenDMX,1,milliseconds);
*/
/*
//---------
//test remove light//
//---------
myLights.removeLight(myRGBWLight);
myLights.allOnSingleColor(myOpenDMX, "g", 1, milliseconds);
myLights.allOnSingleColor(myOpenDMX, "b", 1, milliseconds);
*/
//command line IO
int lightIDXinput;
bool outerDoContinue = true;
while (outerDoContinue){
std::cout << "Enter a light. Options are: " << std::endl;
std::cout << "all lights (0), ";
std::cout << "light1 only (1), ";
std::cout << "light2 only (2) ";
std::cout << "QUIT (-1)" << std::endl;
std::cin >> lightIDXinput;
switch (lightIDXinput){
case 0:{
int input;
bool doContinue = true;
while(doContinue){
std::cout << "Enter a lighting command. Options are:" << std::endl;
std::cout << "all colors ramp down (1), ";
std::cout << "all red on (2), " ;
std::cout << "all green on (3), " ;
std::cout << "all blue on (4), " ;
std::cout << "all amber on (5), " ;
std::cout << "all white on (6), " ;
std::cout << "random pattern (7), " ;
std::cout << "rainbow cross dissolve (8), ";
std::cout << "quit (0)." << std::endl;
std::cin >> input;
switch (input){
case 1: myLights.allColorsRampDown(myOpenDMX, 1, milliseconds); break;
case 2: myLights.allOnSingleColor(myOpenDMX, "r", 1, milliseconds); break;
case 3: myLights.allOnSingleColor(myOpenDMX, "g", 1, milliseconds); break;
case 4: myLights.allOnSingleColor(myOpenDMX, "b", 1, milliseconds); break;
case 5: myLights.allOnSingleColor(myOpenDMX, "a", 1, milliseconds); break;
case 6: myLights.allOnSingleColor(myOpenDMX, "w", 1, milliseconds); break;
case 7: myLights.randomPattern(myOpenDMX,1,milliseconds); break;
case 8: myLights.rainbowCrossDissolve(myOpenDMX,1,milliseconds); break;
case 0: doContinue = false; break;
default: std::cout << "Invalid argument. please select again." << std::endl;
}
} //end while doCont
break;
}
case 1:{
int input;
bool doContinue = true;
while(doContinue){
std::cout << "Enter a lighting command. Options are:" << std::endl;
std::cout << "all colors ramp down (1), ";
std::cout << "all red on (2), " ;
std::cout << "all green on (3), " ;
std::cout << "all blue on (4), " ;
std::cout << "all amber on (5), " ;
std::cout << "all white on (6), " ;
std::cout << "random pattern (7), " ;
std::cout << "rainbow cross dissolve (8), ";
std::cout << "quit (0)." << std::endl;
std::cin >> input;
switch (input){
case 1: myRGBWLight.allColorsRampDown(myOpenDMX,1,milliseconds); break;
case 2: myRGBWLight.allRedOn(myOpenDMX,1,milliseconds); break;
case 3: myRGBWLight.allGreenOn(myOpenDMX,1,milliseconds); break;
case 4: myRGBWLight.allBlueOn(myOpenDMX,1,milliseconds); break;
case 5: myRGBWLight.allAmberOn(myOpenDMX,1,milliseconds); break;
case 6: myRGBWLight.allWhiteOn(myOpenDMX,1,milliseconds); break;
case 7: myRGBWLight.randomPattern(myOpenDMX,1,milliseconds); break;
case 8: myRGBWLight.rainbowCrossDissolve(myOpenDMX,1,milliseconds); break;
case 0: doContinue = false; break;
default: std::cout << "Invalid argument. please select again." << std::endl;
}
} //end while doCont
break;
}
case 2: {
int input;
bool doContinue = true;
while(doContinue){
std::cout << "Enter a lighting command. Options are:" << std::endl;
std::cout << "all colors ramp down (1), ";
std::cout << "all red on (2), " ;
std::cout << "all green on (3), " ;
std::cout << "all blue on (4), " ;
std::cout << "all amber on (5), " ;
std::cout << "all white on (6), " ;
std::cout << "random pattern (7), " ;
std::cout << "rainbow cross dissolve (8), ";
std::cout << "quit (0)." << std::endl;
std::cin >> input;
switch (input){
case 1: myRGBAWLight.allColorsRampDown(myOpenDMX,1,milliseconds); break;
case 2: myRGBAWLight.allRedOn(myOpenDMX,1,milliseconds); break;
case 3: myRGBAWLight.allGreenOn(myOpenDMX,1,milliseconds); break;
case 4: myRGBAWLight.allBlueOn(myOpenDMX,1,milliseconds); break;
case 5: myRGBAWLight.allAmberOn(myOpenDMX,1,milliseconds); break;
case 6: myRGBAWLight.allWhiteOn(myOpenDMX,1,milliseconds); break;
case 7: myRGBAWLight.randomPattern(myOpenDMX,1,milliseconds); break;
case 8: myRGBAWLight.rainbowCrossDissolve(myOpenDMX,1,milliseconds); break;
case 0: doContinue = false; break;
default: std::cout << "Invalid argument. please select again." << std::endl;
}
} //end while doCont
break;
}
case -1: outerDoContinue = false; break;
default: std::cout << "Invalid argument. please select again." << std::endl;
}
}
/*
int input;
bool doContinue = true;
while(doContinue){
std::cout << "Enter a command. Options are:" << std::endl;
std::cout << "all colors ramp down (1), ";
std::cout << "all red on (2), " ;
std::cout << "all green on (3), " ;
std::cout << "all blue on (4), " ;
std::cout << "all amber on (5), " ;
std::cout << "all white on (6), " ;
std::cout << "random pattern (7), " ;
std::cout << "rainbow cross dissolve (8), ";
std::cout << "quit (0)." << std::endl;
std::cin >> input;
switch (input){
case 1: myRGBWLight.allColorsRampDown(myOpenDMX,1,milliseconds); break;
case 2: myRGBWLight.allRedOn(myOpenDMX,1,milliseconds); break;
case 3: myRGBWLight.allGreenOn(myOpenDMX,1,milliseconds); break;
case 4: myRGBWLight.allBlueOn(myOpenDMX,1,milliseconds); break;
case 5: myRGBWLight.allAmberOn(myOpenDMX,1,milliseconds); break;
case 6: myRGBWLight.allWhiteOn(myOpenDMX,1,milliseconds); break;
case 7: myRGBWLight.randomPattern(myOpenDMX,1,milliseconds); break;
case 8: myRGBWLight.rainbowCrossDissolve(myOpenDMX,1,milliseconds); break;
case 0: doContinue = false; break;
default: std::cout << "Invalid argument. please select again." << std::endl;
}
switch (input){
case 1: myRGBAWLight.allColorsRampDown(myOpenDMX,1,milliseconds); break;
case 2: myRGBAWLight.allRedOn(myOpenDMX,1,milliseconds); break;
case 3: myRGBAWLight.allGreenOn(myOpenDMX,1,milliseconds); break;
case 4: myRGBAWLight.allBlueOn(myOpenDMX,1,milliseconds); break;
case 5: myRGBAWLight.allAmberOn(myOpenDMX,1,milliseconds); break;
case 6: myRGBAWLight.allWhiteOn(myOpenDMX,1,milliseconds); break;
case 7: myRGBAWLight.randomPattern(myOpenDMX,1,milliseconds); break;
case 8: myRGBAWLight.rainbowCrossDissolve(myOpenDMX,1,milliseconds); break;
case 0: doContinue = false; break;
default: std::cout << "Invalid argument. please select again." << std::endl;
}
switch (input){
case 1: myLights.allColorsRampDown(myOpenDMX, 1, milliseconds); break;
case 2: myLights.allOnSingleColor(myOpenDMX, "r", 1, milliseconds); break;
case 3: myLights.allOnSingleColor(myOpenDMX, "g", 1, milliseconds); break;
case 4: myLights.allOnSingleColor(myOpenDMX, "b", 1, milliseconds); break;
case 5: myLights.allOnSingleColor(myOpenDMX, "a", 1, milliseconds); break;
case 6: myLights.allOnSingleColor(myOpenDMX, "w", 1, milliseconds); break;
case 7: myLights.randomPattern(myOpenDMX,1,milliseconds); break;
case 8: myLights.rainbowCrossDissolve(myOpenDMX,1,milliseconds); break;
case 0: doContinue = false; break;
default: std::cout << "Invalid argument. please select again." << std::endl;
} //end switch
} //end while doContinue
*/
} //end if
else{
system("pause");
return 1;
}
}
FreeLibrary(dllHandle_);
system("pause");
return 0;
}