-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheOS.h
553 lines (456 loc) · 11.6 KB
/
eOS.h
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
/*
eOS library for USB and Ethernet UDPis placed under the MIT license
Copyright (c) 2020 Stefan Staub
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
fader is a linear 10kOhm, from Bourns or ALPS and can be 45/60/100mm long
put 10nF ceramic capitors between ground and fader levelers to prevent analog noise
Arduino UNO, MEGA:
use IOREF instead +5V to the top (single pin) of the fader (100%)
GND to the center button pin (2 pins, the outer pin is normaly for the leveler) of the fader (0%)
TEENSY:
+3.3V to the top (single pin) of the fader (100%)
use ANALOG GND instead the normal GND to the center button pin (2 pins, the outer pin is normaly for the leveler) of the fader (0%)
put 100nF ceramic capitors between ground and the input of the buttons
*/
#ifndef EOS_H
#define EOS_H
#include "Arduino.h"
#include "OSCMessage.h"
#include "Udp.h"
#define SUBSCRIBE 1
#define UNSUBSCRIBE 0
#define EDGE_DOWN 1
#define EDGE_UP 0
#define FORWARD 0
#define REVERSE 1
#define INT_ACC 4 // only used for intens
#define WHEEL_ACC 1
#define FADER_UPDATE_RATE_MS 40 // update each 40ms
#define THRESHOLD 4 // Jitter threshold of the faders
enum interface_t {EOSUSB, EOSUDP};
/**
* @brief Class definitions for a general interface
*
*/
class EOS {
public:
/**
* @brief Construct a new EOS object for Etnernet communication over udp
*
* @param udp UPD instance
* @param ip destination IP
* @param port destination Port
* @param interface Interface type EOSUDP
*/
EOS(UDP &udp, IPAddress ip, uint16_t port, interface_t interface = EOSUDP);
/**
* @brief Construct a new EOS object for Serial communication
*
* @param interface Interface type EOSUSB
*/
EOS(interface_t interface = EOSUSB);
/**
* @brief send OSC message
*
* @param msg OSC message
* @param ip optional destination IP address
* @param port optional destination port
*/
void sendOSC(OSCMessage& msg, IPAddress ip, uint16_t port);
/**
* @brief send OSC message
*
* @param msg
*/
void sendOSC(OSCMessage& msg);
private:
UDP *udp;
HardwareSerial *s;
IPAddress ip;
uint16_t port;
interface_t interface;
};
/**
* @brief send an OSC message
*
* @param msg OSC message
*/
//void sendOSC(OSCMessage& msg);
/**
* @brief Filter for messages you want receive
*
*
* @param message you want receive
*/
void filter(String pattern);
/**
* @brief Subscribe a parameter you want receive
*
* @param parameter for subscription
*/
void subscribe(String parameter);
/**
* @brief Unsubscribe a parameter
*
* @param parameter for unsubscription
*/
void unSubscribe(String parameter);
/**
* @brief send a ping without a message
*
*/
void ping();
/**
* @brief send a ping with a meassge
*
* @param message
*/
void ping(String message);
/**
* @brief send a string to the command line
*
* @param cmd command line String
*/
void command(String cmd);
/**
* @brief send a new command line string
*
* @param cmd command line String
*/
void newCommand(String newCmd);
/**
* @brief set the user
*
* @param userID user
*/
void user(int16_t userID);
/**
* @brief modes for the encoder button if available
*
*/
enum ButtonMode {
HOME, FINE
};
/**
* @brief initialise the Shift button for encoders and wheels
*
* @param pin of the shift button
*/
void shiftButton(uint8_t pin);
/**
* @brief Class definitions for Encoder controlling parameters by their name
*
*/
class Encoder {
public:
/**
* @brief Construct a new Encoder object
*
* @param pinA pin A of the encoder
* @param pinB pin B of the encoder
* @param direction the direction for the wheel can be FORWARD or REVERSE
*/
Encoder(uint8_t pinA, uint8_t pinB, uint8_t direction = FORWARD);
/**
* @brief add an optional encoder button
*
* @param buttonPin pin of the button
* @param buttonMode the parameter function of the button, in the moment Home or FINE
*/
void button(uint8_t buttonPin, ButtonMode buttonMode = HOME);
/**
* @brief set the parameter which should controlled by the encoder
*
* @param param parameter name as a String
*/
void parameter(String param);
/**
* @brief get the parameter which is controlled by the encoder
*
* @return String
*/
String parameter();
/**
* @brief update the output of the encoder, must be in the loop
*
*/
void update();
private:
String param;
uint8_t pinA;
uint8_t pinB;
uint8_t buttonPin;
ButtonMode buttonMode;
uint8_t pinALast;
uint8_t pinACurrent;
uint8_t buttonPinLast;
uint8_t direction;
int8_t encoderMotion;
};
/**
* @brief Class definition for Wheels, controlling parameters by their index
*
*/
class Wheel {
public:
/**
* @brief Construct a new Wheel object
*
* @param pinA pin A of the encoder
* @param pinB pinB of the encoder
* @param direction the direction for the wheel can be FORWARD or REVERSE
*/
Wheel(uint8_t pinA, uint8_t pinB, uint8_t direction = FORWARD);
/**
* @brief add an optional encoder button
*
* @param buttonPin pin of the button
* @param buttonMode the parameter function of the button, in the moment only FINE
*/
void button(uint8_t buttonPin, ButtonMode buttonMode = FINE);
/**
* @brief set the index number of the wheel
*
* @param idx index
*/
void index(uint8_t idx);
/**
* @brief get the parameter which is controlled by the encoder
*
* @return uint8_t the wheel idx
*/
uint8_t index();
/**
* @brief update the output of the Wheel, must be in the loop
*
*/
void update();
private:
uint8_t idx;
uint8_t pinA;
uint8_t pinB;
uint8_t buttonPin;
uint8_t pinALast;
uint8_t pinACurrent;
uint8_t buttonPinLast;
uint8_t buttonMode;
uint8_t direction;
int8_t encoderMotion;
};
/**
* @brief Class definitions for Key commands
*
*/
class Key {
public:
/**
* @brief Construct a new Key object
*
* @param pin button pin
* @param key EOS Key command
*/
Key(uint8_t pin, String key);
/**
* @brief update the state of the Key button, must in while() loop
*
*/
void update();
private:
String keyPattern;
uint8_t pin;
uint8_t last;
};
/**
* @brief Class definitions for a Submaster
*
*/
class Submaster {
public:
/**
* @brief Construct a new Submaster object
*
* @param analogPin pin for fader leveler
* @param firePin pin for the fire button
* @param sub submaster number
*/
Submaster(uint8_t analogPin, uint8_t firePin, uint8_t sub);
/**
* @brief update the state of the Submaster and fire button, must in while() loop
*
*/
void update();
private:
String subPattern;
uint8_t analogPin;
uint8_t firePin;
int16_t analogLast;
uint8_t fireLast;
uint32_t updateTime;
};
/**
* @brief initialise a fader bank
*
* @param page fader page of the console, standard is 1
* @param faders number of faders, standard is 10
* @param bank number of the OSC fader bank, standard is 1
*/
void initFaders(uint8_t page = 1, uint8_t faders = 10, uint8_t bank = 1);
/**
* @brief Fader object with stop and fire buttons
*
*/
class Fader {
public:
/**
* @brief Construct a new Fader object
*
* @param analogPin pin for the fader leveler
* @param firePin pin for the fire button
* @param stopPin pin for the stop button
* @param fader number of the fader inside the bank
* @param bank number of the OSC fader bank, standard is 1
*/
Fader(uint8_t analogPin, uint8_t firePin, uint8_t stopPin, uint8_t fader, uint8_t bank = 1);
/**
* @brief update the state of the Fader and fire / stop buttons, must in while() loop
*
*/
void update();
/**
* @brief set the OSC fader bank of the fader object
*
* @param bank OSC fader bank
*/
void faderBank(uint8_t bank);
/**
* @brief get the OSC bank number of the fader object
*
* @return uint8_t number of the OSC fader bank
*/
uint8_t faderBank();
/**
* @brief set the fader number of the fader object
*
* @param fader number of the fader
*/
void faderNumber(uint8_t fader);
/**
* @brief get the fader number of the fader object
*
* @return uint8_t fader number
*/
uint8_t faderNumber();
private:
String faderPattern;
uint8_t bank;
uint8_t fader;
uint8_t analogPin;
uint8_t firePin;
uint8_t stopPin;
int16_t analogLast;
uint8_t fireLast;
uint8_t stopLast;
uint32_t updateTime;
};
/**
* @brief Class definitions for a Macro button
*
*/
class Macro {
public:
/**
* @brief Construct a new Macro object
*
* @param pin macro button pin
* @param macro number of the macro
*/
Macro(uint8_t pin, uint16_t macro);
/**
* @brief update the state of the Macro button, must in while() loop
*
*/
void update();
private:
String firePattern;
uint8_t pin;
uint8_t last;
};
class OscButton {
public:
/**
* @brief Construct a new osc Button object for sending an integer value
*
* @param pin button pin
* @param pattern OSC address
* @param integer32 value must cast (int32_t) when using with a non matching size
* @param ip optional destination IP address
* @param port optional destination port
*/
OscButton(uint8_t pin, String pattern, int32_t integer32);
OscButton(uint8_t pin, String pattern, int32_t integer32, IPAddress ip, uint16_t port);
/**
* @brief Construct a new osc Button object for sending a float value
*
* @param pin button pin
* @param pattern OSC address
* @param float32 float value
* @param ip optional destination IP address
* @param port optional destination port
*/
OscButton(uint8_t pin, String pattern, float float32);
OscButton(uint8_t pin, String pattern, float float32, IPAddress ip, uint16_t port);
/**
* @brief Construct a new osc Button object for ssending a String
*
* @param pin button pin
* @param pattern OSC address
* @param message String message
* @param ip optional destination IP address
* @param port optional destination port
*/
OscButton(uint8_t pin, String pattern, String message);
OscButton(uint8_t pin, String pattern, String message, IPAddress ip, uint16_t portt);
/**
* @brief Construct a new osc Button object with no value
*
* @param pin button pin
* @param pattern OSC address
* @param ip optional destination IP address
* @param port optional destination port
*/
OscButton(uint8_t pin, String pattern);
OscButton(uint8_t pin, String pattern, IPAddress ip, uint16_t port);
/**
* @brief update the state of the Macro button, must in while() loop
*
*/
void update();
private:
enum osc_t {NONE, INT32, FLOAT32, STRING};
osc_t typ;
String pattern;
int32_t integer32;
float float32;
String message;
IPAddress ip;
uint16_t port;
uint8_t pin;
uint8_t last;
};
#endif