-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDR_I2C_Encoder.cpp
813 lines (754 loc) · 32 KB
/
SDR_I2C_Encoder.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
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
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
//
// SDR_I2C_Encoder.cpp
//
//#include "SDR_RA8875.h"
#include "ICOM_IC-905_CIV.h"
#include "RadioConfig.h"
#include "SDR_I2C_Encoder.h"
#include <i2cEncoderLibV2.h>
// In RadioConfig.h use #define USE_MIDI to enable MIDI -
// Experimental dev work to use Teensy SDR controls to send out MIDI events over USB
#ifdef USE_MIDI
#include "MIDIUSB.h"
#include <Metro.h>
#define AUX_PIN 6
#define KEY_PIN 7
#define MUTE 57
#define VFOA 50
#define VFOB 51
#define VELOCITY 127
#define CHANNEL 0
#define CHANNEL4 4
// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number.
// Fourth parameter is the velocity (64 = normal, 127 = fastest).
void noteOn(uint8_t channel, byte pitch, byte velocity)
{
midiEventPacket_t noteOn = {0x09, uint8_t (0x90 | channel), pitch, velocity};
MidiUSB.sendMIDI(noteOn);
MidiUSB.flush();
}
void noteOff(uint8_t channel, byte pitch, byte velocity)
{
midiEventPacket_t noteOff = {0x0B, uint8_t (0xB0 | channel), pitch, velocity};
MidiUSB.sendMIDI(noteOff);
MidiUSB.flush();
}
void note(uint8_t channel, byte cmd_byte, byte cmd_val)
{
midiEventPacket_t note = {0x0B, uint8_t (0xB0 | channel), cmd_byte, cmd_val};
MidiUSB.sendMIDI(note);
MidiUSB.flush();
}
#endif
// These are the per-encoder function declarations
void set_I2CEncoders(void);
extern void setEncoderMode(uint8_t id);
extern uint8_t MF_client; // Flag for current owner of MF knob services
extern uint8_t curr_band; // global tracks our current band setting.
extern uint8_t user_Profile; // global tracks our current user profile
extern struct User_Settings user_settings[];
extern struct Band_Memory bandmem[];
extern struct Label labels[];
extern struct EncoderList encoder_list[];
extern bool MeterInUse; // S-meter flag to block updates while the MF knob has control
extern Metro MF_Timeout;
// One timer for each encoder list row (NUM_AUX_ENCODERS) except for 0. Can be used for GPIO or I2C encoder switches.
Metro press_timer1 = Metro(500);
Metro press_timer2 = Metro(500);
Metro press_timer3 = Metro(500);
Metro press_timer4 = Metro(500);
Metro press_timer5 = Metro(500);
Metro press_timer6 = Metro(500);
Metro press_timer7 = Metro(500);
Metro press_timer8 = Metro(500);
Metro press_timer9 = Metro(500);
Metro press_timer10 = Metro(500);
Metro press_timer11 = Metro(500);
static int32_t gpio_enc_count = 0;
//Class initialization with the I2C addresses - add more here if needed
//i2cEncoderLibV2 i2c_encoder[2] = { i2cEncoderLibV2(0x62), i2cEncoderLibV2(0x61)};
#ifdef I2C_ENC1_ADDR
void blink_I2C_ENC1_RGB(void);
i2cEncoderLibV2 I2C_ENC1(I2C_ENC1_ADDR);
uint8_t _e1 = 0;
#endif
#ifdef I2C_ENC2_ADDR
void blink_I2C_ENC2_RGB(void);
i2cEncoderLibV2 I2C_ENC2(I2C_ENC2_ADDR);
uint8_t _e2 = 0;
#endif
#ifdef I2C_ENC3_ADDR
void blink_I2C_ENC3_RGB(void);
i2cEncoderLibV2 I2C_ENC3(I2C_ENC3_ADDR);
uint8_t _e3 = 0;
#endif
#ifdef I2C_ENC4_ADDR
void blink_I2C_ENC4_RGB(void);
i2cEncoderLibV2 I2C_ENC4(I2C_ENC4_ADDR);
uint8_t _e4 = 0;
#endif
#ifdef I2C_ENC5_ADDR
void blink_I2C_ENC5_RGB(void);
i2cEncoderLibV2 I2C_ENC5(I2C_ENC5_ADDR);
uint8_t _e5 = 0;
#endif
#ifdef I2C_ENC6_ADDR
void blink_I2C_ENC6_RGB(void);
i2cEncoderLibV2 I2C_ENC6(I2C_ENC6_ADDR);
uint8_t _e6 = 0;
#endif
// create dummy objects for gpio to interface to the i2c lib
#if GPIO_ENC2_ENABLE
i2cEncoderLibV2 GPIO_ENC2(0);
#endif
#if GPIO_ENC3_ENABLE
i2cEncoderLibV2 GPIO_ENC3(0);
#endif
// These are generic callback functions - meaning when a hardware event occurs these functions are
// called with the info associated with that encoder. We can assign each encoder to things like AF and RF gain.
//void encoder_rotated(i2cEncoderLibV2* obj, uint8_t slot);
//void encoder_click(i2cEncoderLibV2* obj, uint8_t slot);
//void encoder_thresholds(i2cEncoderLibV2* obj, uint8_t slot);
void switch_timer_start(uint8_t _id);
void switch_click(i2cEncoderLibV2* obj, uint8_t _id);
extern void MF_Service(int8_t counts, uint8_t knob);
COLD void gpio_encoder_rotated(i2cEncoderLibV2* obj, int32_t _count)
{
gpio_enc_count = _count;
i2c_encoder_rotated(obj);
}
//Callback when the MF Gain encoder is rotated
COLD void i2c_encoder_rotated(i2cEncoderLibV2* obj)
{
int16_t count = 0;
uint8_t knob_assigned, z_lvl, slot;
//DPRINT(F("Encoder ID passed in = ")); DPRINTLN(obj->id);
//DPRINT(F("ID from Record lookup = ")); DPRINTLN(encoder_list[obj->id].id);
//DPRINT(F("Check MF Client ID = ")); DPRINTLN(MF_client);
//DPRINT(F("Role = ")); DPRINTLN(encoder_list[obj->id].role_A);
for (slot = 1; slot< NUM_AUX_ENCODERS; slot++)
{
//DPRINT(F("Slot # = ")); DPRINTLN(slot);
//DPRINT(F("id from slot # = ")); DPRINTLN(encoder_list[slot].id);
if ((obj->id == encoder_list[slot].id) && encoder_list[slot].enabled)
{
//DPRINTLN(F("Valid Encoder Match"));
break;
}
} // got our slot number
//DPRINT(F("slot is ")); DPRINTLN(slot);
//DPRINT(F("def is ")); DPRINTLN(encoder_list[slot].default_MF_client);
if ((encoder_list[slot].role_A == encoder_list[slot].default_MF_client) && encoder_list[slot].role_A != MF_client)
knob_assigned = MF_client;
else
knob_assigned = encoder_list[slot].role_A;
if (encoder_list[slot].type == I2C_ENC)
{
if (obj->readStatus(i2cEncoderLibV2::RINC))
{}//DPRINT(F("Increment: "));
else
{}//DPRINT(F("Decrement: "));
count = obj->readCounterInt();
//DPRINTLN(count);
}
else if (encoder_list[slot].type == GPIO_ENC)
{
count = (int16_t) gpio_enc_count;
}
// ID arrives as Role_A. Need to check which role is active. If B active, update the knob, else skip.
// If a button tap (switch) happens and it is ENCx_BTN, setEncoderMode() is called in control.cpp.
// The function assigned to that encoder shaft is set to the alternate function (a vs b) and the unset staus s set to 0.
if (knob_assigned == encoder_list[slot].role_A && encoder_list[slot].enabled && !encoder_list[slot].a_active)
{
knob_assigned = encoder_list[slot].role_B; // reassign to role B
DPRINT(F("Role B Assigned ")); DPRINTLN(encoder_list[slot].role_B);
}
MF_Service(count, knob_assigned);
//obj->writeCounter((int32_t) 0); // Reset the counter value if in absolute mode. Not required in relative mode
// Update the color
uint32_t tval = 0x00FF00; // Set the default color to green
//DPRINT(F("Knob Assigned to ")); DPRINTLN(knob_assigned);
switch(knob_assigned)
{
char string[80]; // print format stuff
case RFGAIN_BTN: sprintf(string, " RF:%d", user_settings[user_Profile].rfGain);
MeterInUse = true;
displayMeter(user_settings[user_Profile].rfGain/10, string, 5); // val, string label, color scheme
if (user_settings[user_Profile].rfGain < 2 || user_settings[user_Profile].rfGain >98)
tval = 0xFF0000; // Change to red
break;
case AFGAIN_BTN: sprintf(string, " AF:%d", user_settings[user_Profile].afGain);
MeterInUse = true;
displayMeter(user_settings[user_Profile].afGain/10, string, 5); // val, string label, color scheme
if (user_settings[user_Profile].afGain < 2 || user_settings[user_Profile].afGain >98)
tval = 0xFF0000; // Change to red
//AFgain(0);
#ifdef USE_MIDI
note(CHANNEL, 52, (user_settings[user_Profile].afGain * 1.27)); // scale 100% to 127 for MIDI max of 127.
#endif
break;
case ATTN_BTN: sprintf(string, " ATT%s", " "); //bandmem[curr_band].attenuator);
//MeterInUse = true;
//displayMeter(bandmem[curr_band].attenuator_dB/10, string, 5); // val, string label, color scheme
if (bandmem[curr_band].attenuator_dB < 2 || bandmem[curr_band].attenuator_dB > 98)
tval = 0xFF0000; // Change to red
//Attn(0);
break;
case REFLVL_BTN: sprintf(string, "Lvl:%d", bandmem[curr_band].sp_ref_lvl);
MeterInUse = true;
displayMeter((bandmem[curr_band].sp_ref_lvl+50)/10, string, 5); // val, string label, color scheme
if (bandmem[curr_band].sp_ref_lvl < -48 || bandmem[curr_band].sp_ref_lvl > 48)
tval = 0xFF0000; // Change to red
//RefLevel(0);
break;
case NB_BTN: sprintf(string, " NB:%1d", user_settings[user_Profile].nb_level);
MeterInUse = true;
displayMeter((int) user_settings[user_Profile].nb_level*1.7, string, 5); // val, string label, color scheme
if (user_settings[user_Profile].nb_level >= 6 || user_settings[user_Profile].nb_level <=0)
tval = 0xFF0000; // Change to red
//NBLevel(0);
break;
case PAN_BTN: sprintf(string, "Pan:%3d", user_settings[user_Profile].pan_level-50);
MeterInUse = true;
displayMeter(user_settings[user_Profile].pan_level/10, string, 5); // val, string label, color scheme
if (user_settings[user_Profile].pan_level < 2 || user_settings[user_Profile].pan_level > 98)
tval = 0xFF0000; // Change to red
break;
case ZOOM_BTN: z_lvl = user_settings[user_Profile].zoom_level;
if (z_lvl == 0)
z_lvl = 1;
else
z_lvl *= 2;
sprintf(string, "Zoom:%1d",z_lvl);
MeterInUse = true;
displayMeter(z_lvl, string, 5); // val, string label, color scheme
if (z_lvl < 2 || z_lvl > 3)
tval = 0xFF0000; // Change to red
break;
case FILTER_BTN: if (bandmem[curr_band].filter < 1 || bandmem[curr_band].filter >= FILTER-1 ||
bandmem[curr_band].var_filter < 200 || bandmem[curr_band].var_filter > 5800)
tval = 0xFF0000; // Change to red
break;
case RATE_BTN: if (bandmem[curr_band].tune_step < 1 || bandmem[curr_band].tune_step >= TS_STEPS-1)
tval = 0xFF0000; // Change to red
break;
case MODE_BTN: if (bandmem[curr_band].mode_A < 1 || bandmem[curr_band].mode_A >= MODES_NUM-1)
tval = 0xFF0000; // Change to red
break;
case ATU_BTN: if (bandmem[curr_band].ATU < 1 || bandmem[curr_band].ATU > 0)
tval = 0xFF0000; // Change to red
break;
case ANT_BTN: if (bandmem[curr_band].ant_sw < 1 || bandmem[curr_band].ant_sw > 0)
tval = 0xFF0000; // Change to red
break;
case BANDUP_BTN: if (bandmem[curr_band].ant_sw < 1 || bandmem[curr_band].ant_sw > 0)
tval = 0xFF0000; // Change to red
break;
case BANDDN_BTN: if (bandmem[curr_band].ant_sw < 1 || bandmem[curr_band].ant_sw > 0)
tval = 0xFF0000; // Change to red
break;
case BAND_BTN: tval = 0xFF0000; // Change to red
break;
default:
#ifdef USE_MIDI
note(CHANNEL, 50, 64+count); // MIDI jog wheel uses 64 as center
#endif
if (encoder_list[slot].type == I2C_ENC) obj->writeRGBCode(tval);
break;
}
if (encoder_list[slot].type == I2C_ENC) obj->writeRGBCode(tval); // set color
}
void knob_press(uint8_t slot)
{
DPRINT(F("Knob Press ")); DPRINTLN(encoder_list[slot].press);
#ifdef USE_MIDI
noteOn(CHANNEL, 62, 127);
noteOff(CHANNEL, 62, 0);
#else
Button_Action(encoder_list[slot].press);
#endif
}
void knob_tap(uint8_t slot)
{
DPRINT(F("Knob Tap ")); DPRINTLN(encoder_list[slot].tap);
#ifdef USE_MIDI
noteOn(CHANNEL, 63, 127);
noteOff(CHANNEL, 63, 0);
#else
Button_Action(encoder_list[slot].tap);
#endif
}
//Callback when the i2c encoder is pushed
COLD void i2c_switch_click(i2cEncoderLibV2* obj)
{
DPRINTF("I2C Click Event "); DPRINTLN(obj->id);
switch_click(obj, obj->id);
}
COLD void gpio_switch_click(uint8_t _id)
{
DPRINTF("GPIO Click Event "); DPRINTLN(_id);
switch_click(NULL, _id);
}
// works with both GPIO and I2C
COLD void switch_click(i2cEncoderLibV2* obj, uint8_t _id)
{
DPRINTF("Click Event "); DPRINTLN(_id);
for (uint8_t slot = 1; slot < NUM_AUX_ENCODERS; slot++) // one timer for each row in encoder_list structure.
{
if ((_id == encoder_list[slot].id) && encoder_list[slot].enabled)
{
uint8_t _press = 0;
DPRINTF("Slot "); DPRINTLN(slot);
switch (slot)
{
case 0: break; // VFO, ignore it
case 1: if (press_timer1.check() == 1) _press = 1; break;
case 2: if (press_timer2.check() == 1) _press = 1; break;
case 3: if (press_timer3.check() == 1) _press = 1; break;
case 4: if (press_timer4.check() == 1) _press = 1; break;
case 5: if (press_timer5.check() == 1) _press = 1; break;
case 6: if (press_timer6.check() == 1) _press = 1; break;
case 7: if (press_timer7.check() == 1) _press = 1; break;
case 8: if (press_timer8.check() == 1) _press = 1; break;
case 9: if (press_timer9.check() == 1) _press = 1; break;
case 10: if (press_timer10.check() == 1) _press = 1; break;
case 11: if (press_timer11.check() == 1) _press = 1; break;
default: DPRINTLNF("No timer found"); break;
}
if (_press)
{
if (encoder_list[slot].type == I2C_ENC) obj->writeRGBCode(0x00FF00);
knob_press(slot ); // this is a tap, call the button action
}
else
{
if (encoder_list[slot].type == I2C_ENC) obj->writeRGBCode(0x0000FF);
knob_tap(slot); // this is a tap, call the button action
}
}
}
}
//Callback when the i2c encoder is first pushed, will start a timer to see if it was long or short
COLD void i2c_switch_timer_start(i2cEncoderLibV2* obj)
{
obj->writeRGBCode(0x0000FF);
switch_timer_start(obj->id);
}
// interface for gpio encoders
COLD void gpio_switch_timer_start(uint8_t _id)
{
switch_timer_start(_id);
}
// works with both GPIO and I2C
COLD void switch_timer_start(uint8_t _id)
{
//DPRINT(F("Start Push Switch Timer ")); DPRINTLN(_id);
for (uint8_t slot = 1; slot < NUM_AUX_ENCODERS; slot++) // one timer for each row in encoder_list structure.
{
if ((_id == encoder_list[slot].id) && encoder_list[slot].enabled)
{
switch (slot)
{
case 0: break; // VFO, ignore it
case 1: press_timer1.reset(); DPRINTLN(F("Start Push Switch Timer 1")); break;
case 2: press_timer2.reset(); DPRINTLN(F("Start Push Switch Timer 2")); break;
case 3: press_timer3.reset(); DPRINTLN(F("Start Push Switch Timer 3")); break;
case 4: press_timer4.reset(); DPRINTLN(F("Start Push Switch Timer 4")); break;
case 5: press_timer5.reset(); DPRINTLN(F("Start Push Switch Timer 5")); break;
case 6: press_timer6.reset(); DPRINTLN(F("Start Push Switch Timer 6")); break;
case 7: press_timer7.reset(); DPRINTLN(F("Start Push Switch Timer 7")); break;
case 8: press_timer8.reset(); DPRINTLN(F("Start Push Switch Timer 8")); break;
case 9: press_timer9.reset(); DPRINTLN(F("Start Push Switch Timer 9")); break;
case 10: press_timer10.reset(); DPRINTLN(F("Start Push Switch Timer 10")); break;
case 11: press_timer11.reset(); DPRINTLN(F("Start Push Switch Timer 11")); break;
default: DPRINTLNF("No timer found");
}
}
}
}
//Callback when the encoder reaches the max or min
COLD void encoder_thresholds(i2cEncoderLibV2* obj)
{
if (obj->readStatus(i2cEncoderLibV2::RMAX))
;//DPRINTLN(F("Max!"));
else
;//DPRINTLN(F("Min!"));
obj->writeRGBCode(0xFF0000);
}
//Callback when the fading process finishes and set the RGB led off
COLD void encoder_fade(i2cEncoderLibV2* obj)
{
//uint8_t mfg;
#ifdef I2C_ENC1_ADDR
I2C_ENC1.updateStatus();
#endif
//mfg = MF_ENC.readStatus();
//DPRINT(F("****Checked MF_Enc (in FADE) status = ")); DPRINTLN(mfg);
//#ifdef MF_ENC_ADDR
// Check the status of the encoder (if enabled) and call the callback
//if(mfg == 0 && press_timer.check() == 1 && obj->id == user_settings[user_Profile].encoder1_client && user_settings[user_Profile].encoder1_client == MFTUNE)
//{
//VFO_AB();
//DPRINTLN(F("Long MF Knob Push- Swap VFOs "));
//obj->writeRGBCode(0x00FF00);
//}
//#endif
obj->writeRGBCode(0x000000);
}
COLD void set_I2CEncoders()
{
#if defined I2C_ENCODERS || defined GPIO_ENCODERS
uint8_t slot = 0;
#endif
pinMode(I2C_INT_PIN, INPUT_PULLUP);
//DPRINTLN(F("Setup ENC"));
#ifdef I2C_ENC1_ADDR
// find the slot assigned to I2C_ENC1_ADDR and if enabled, set it up
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == I2C_ENC1_ENABLE && encoder_list[slot].type == I2C_ENC)
{
_e1 = slot;
DPRINT(F("I2C_ENC1 Encoder Setup Slot "));DPRINTLN(slot);
I2C_ENC1.reset();
delay(20);
I2C_ENC1.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_ENABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
I2C_ENC1.id = encoder_list[slot].id;
I2C_ENC1.writeCounter((int32_t) 0); /* Reset the counter value to 0, can be a database value also*/
I2C_ENC1.writeMax((int32_t) 100); /* Set the maximum threshold*/
I2C_ENC1.writeMin((int32_t) -100); /* Set the minimum threshold */
I2C_ENC1.writeStep((int32_t) 1); /* Set the step to 1*/
/* Configure the events */
I2C_ENC1.onChange = i2c_encoder_rotated;
I2C_ENC1.onButtonRelease = i2c_switch_click;
I2C_ENC1.onMinMax = encoder_thresholds;
I2C_ENC1.onFadeProcess = encoder_fade;
I2C_ENC1.onButtonPush = i2c_switch_timer_start;
I2C_ENC1.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
//MF_ENC.writeInterruptConfig(0xff); /* Enable all the interrupt */
//MF_ENC.writeDoublePushPeriod(50); /*Set a period for the double push of 500ms */
/* Enable the I2C Encoder V2 interrupts according to the previous attached callback */
I2C_ENC1.autoconfigInterrupt();
blink_I2C_ENC1_RGB();
//DPRINTLN(F("End Encoder #1 Setup"));
break; // now have the record for this encoder
}
}
#endif
// Setup for other encoders. Uses the button number from the user settings database
#ifdef I2C_ENC2_ADDR
// Encoder 2 setup
// find the slot assigned to I2C_ENC1_ADDR and if enabled, set it up
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == I2C_ENC2_ENABLE && encoder_list[slot].type == I2C_ENC)
{
_e2 = slot;
DPRINT(F("I2C_ENC2 Encoder Setup Slot "));DPRINTLN(slot);
I2C_ENC2.reset();
delay(20);
I2C_ENC2.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_DISABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
I2C_ENC2.id = encoder_list[slot].id;
I2C_ENC2.writeCounter((int32_t) 0); /* Reset the counter value to 0, can be a database value also*/
I2C_ENC2.writeMax((int32_t) 100); /* Set the maximum threshold*/
I2C_ENC2.writeMin((int32_t) -100); /* Set the minimum threshold */
I2C_ENC2.writeStep((int32_t) 1); /* Set the step to 1*/
/* Configure the events */
I2C_ENC2.onChange = i2c_encoder_rotated;
I2C_ENC2.onButtonRelease = i2c_switch_click;
I2C_ENC2.onMinMax = encoder_thresholds;
I2C_ENC2.onFadeProcess = encoder_fade;
I2C_ENC2.onButtonPush = i2c_switch_timer_start;
I2C_ENC2.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
I2C_ENC2.autoconfigInterrupt();
blink_I2C_ENC2_RGB();
//DPRINTLN(F("End Encoder #2 Setup"));
break; // now have the record for this encoder
}
}
#endif
#ifdef I2C_ENC3_ADDR
// Encoder 3 setup
// find the slot assigned to I2C_ENC1_ADDR and if enabled, set it up
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == I2C_ENC3_ENABLE && encoder_list[slot].type == I2C_ENC)
{
_e3 = slot;
DPRINT(F("I2C_ENC3 Encoder Setup Slot "));DPRINTLN(slot);
I2C_ENC3.reset();
delay(20);
I2C_ENC3.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_DISABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
I2C_ENC3.id = encoder_list[slot].id;
I2C_ENC3.writeCounter((int32_t) 0); /* Reset the counter value to 0, can be a database value also*/
I2C_ENC3.writeMax((int32_t) 100); /* Set the maximum threshold*/
I2C_ENC3.writeMin((int32_t) -100); /* Set the minimum threshold */
I2C_ENC3.writeStep((int32_t) 1); /* Set the step to 1*/
/* Configure the events */
I2C_ENC3.onChange = i2c_encoder_rotated;
I2C_ENC3.onButtonRelease = i2c_switch_click;
I2C_ENC3.onMinMax = encoder_thresholds;
I2C_ENC3.onFadeProcess = encoder_fade;
I2C_ENC3.onButtonPush = i2c_switch_timer_start;
I2C_ENC3.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
I2C_ENC3.autoconfigInterrupt();
blink_I2C_ENC3_RGB();
//DPRINTLN(F("End Encoder #3 Setup"));
break; // now have the record for this encoder
}
}
#endif
#ifdef I2C_ENC4_ADDR
// Encoder 4 setup
// find the slot assigned to I2C_ENC1_ADDR and if enabled, set it up
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == I2C_ENC4_ENABLE && encoder_list[slot].type == I2C_ENC)
{
_e4 = slot;
DPRINT(F("I2C_ENC4 Encoder Setup Slot "));DPRINTLN(slot);
I2C_ENC4.reset();
delay(20);
I2C_ENC4.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_ENABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
I2C_ENC4.id = encoder_list[slot].id;
I2C_ENC4.writeCounter((int32_t) 0); /* Reset the counter value to 0, can be a database value also*/
I2C_ENC4.writeMax((int32_t) 100); /* Set the maximum threshold*/
I2C_ENC4.writeMin((int32_t) -100); /* Set the minimum threshold */
I2C_ENC4.writeStep((int32_t) 1); /* Set the step to 1*/
/* Configure the events */
I2C_ENC4.onChange = i2c_encoder_rotated;
I2C_ENC4.onButtonRelease = i2c_switch_click;
I2C_ENC4.onMinMax = encoder_thresholds;
I2C_ENC4.onFadeProcess = encoder_fade;
I2C_ENC4.onButtonPush = i2c_switch_timer_start;
I2C_ENC4.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
I2C_ENC4.autoconfigInterrupt();
blink_I2C_ENC4_RGB();
//DPRINTLN(F("End Encoder #4 Setup"));
break;
}
}
#endif
#ifdef I2C_ENC5_ADDR
// Encoder 5 setup
// find the slot assigned to I2C_ENC1_ADDR and if enabled, set it up
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == I2C_ENC5_ENABLE && encoder_list[slot].type == I2C_ENC)
{
_e5 = slot;
DPRINT(F("I2C_ENC5 Encoder Setup Slot "));DPRINTLN(slot);
I2C_ENC5.reset();
delay(20);
I2C_ENC5.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_DISABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
I2C_ENC5.id = encoder_list[slot].id;
I2C_ENC5.writeCounter((int32_t) 0); /* Reset the counter value to 0, can be a database value also*/
I2C_ENC5.writeMax((int32_t) 100); /* Set the maximum threshold*/
I2C_ENC5.writeMin((int32_t) -100); /* Set the minimum threshold */
I2C_ENC5.writeStep((int32_t) 1); /* Set the step to 1*/
/* Configure the events */
I2C_ENC5.onChange = i2c_encoder_rotated;
I2C_ENC5.onButtonRelease = i2c_switch_click;
I2C_ENC5.onMinMax = encoder_thresholds;
I2C_ENC5.onFadeProcess = encoder_fade;
I2C_ENC5.onButtonPush = i2c_switch_timer_start;
I2C_ENC5.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
I2C_ENC5.autoconfigInterrupt();
blink_I2C_ENC5_RGB();
//DPRINTLN(F("End Encoder #5 Setup"));
break;
}
}
#endif
#ifdef I2C_ENC6_ADDR
// Encoder 6 setup
// find the slot assigned to I2C_ENC1_ADDR and if enabled, set it up
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == I2C_ENC6_ENABLE && encoder_list[slot].type == I2C_ENC)
{
_e6 = slot;
DPRINT(F("I2C_ENC6 Encoder Setup Slot "));DPRINTLN(slot);
I2C_ENC6.reset();
delay(20);
I2C_ENC6.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_DISABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
I2C_ENC6.id = encoder_list[slot].id;
I2C_ENC6.writeCounter((int32_t) 0); /* Reset the counter value to 0, can be a database value also*/
I2C_ENC6.writeMax((int32_t) 100); /* Set the maximum threshold*/
I2C_ENC6.writeMin((int32_t) -100); /* Set the minimum threshold */
I2C_ENC6.writeStep((int32_t) 1); /* Set the step to 1*/
/* Configure the events */
I2C_ENC6.onChange = i2c_encoder_rotated;
I2C_ENC6.onButtonRelease = i2c_switch_click;
I2C_ENC6.onMinMax = encoder_thresholds;
I2C_ENC6.onFadeProcess = encoder_fade;
I2C_ENC6.onButtonPush = i2c_switch_timer_start;
I2C_ENC6.writeAntibouncingPeriod(20); /* Set an anti-bouncing of 200ms */
I2C_ENC6.autoconfigInterrupt();
blink_I2C_ENC6_RGB();
//DPRINTLN(F("End Encoder #6 Setup"));
break;
}
}
#endif
// Create fake i2c objects to help gpio to work with teh i2c lib functions. All we need is the .ID value.
#if (GPIO_ENC2_ENABLE > 0)
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == GPIO_ENC2_ENABLE && encoder_list[slot].type == GPIO_ENC)
{
DPRINT(F("GPIO_ENC2 Encoder Setup Slot "));DPRINTLN(slot);
GPIO_ENC2.reset();
delay(1);
GPIO_ENC2.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_DISABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
GPIO_ENC2.id = encoder_list[slot].id;
}
}
#endif
#if (GPIO_ENC3_ENABLE > 0)
for (slot = 1; slot < NUM_AUX_ENCODERS; slot++)
{
if (encoder_list[slot].enabled == GPIO_ENC3_ENABLE && encoder_list[slot].type == GPIO_ENC)
{
DPRINT(F("GPIO_ENC3 Encoder Setup Slot "));DPRINTLN(slot);
GPIO_ENC3.reset();
delay(20);
GPIO_ENC3.begin(
i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::REL_MODE_ENABLE
| i2cEncoderLibV2::DIRE_RIGHT | i2cEncoderLibV2::IPUP_DISABLE // Pullup is on the Teensy IO pin
| i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER);
// Encoder.begin(i2cEncoderLibV2::INT_DATA | i2cEncoderLibV2::WRAP_DISABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::STD_ENCODER); // try also this!
// Encoder.begin(i2cEncoderLibV2::INT_DATA |i2cEncoderLibV2::WRAP_ENABLE | i2cEncoderLibV2::DIRE_LEFT | i2cEncoderLibV2::IPUP_ENABLE | i2cEncoderLibV2::RMOD_X1 | i2cEncoderLibV2::RGB_ENCODER); // try also this!
GPIO_ENC3.id = encoder_list[slot].id;
}
}
#endif
}
#ifdef I2C_ENC1_ADDR
COLD void blink_I2C_ENC1_RGB(void)
{
/* blink the RGB LED */
I2C_ENC1.writeRGBCode(0xFF0000);
delay(250);
I2C_ENC1.writeRGBCode(0x00FF00);
delay(250);
I2C_ENC1.writeRGBCode(0x0000FF);
delay(250);
I2C_ENC1.writeRGBCode(0x000000);
DPRINTLN(F("Blink I2C_ENC1 RGB"));
I2C_ENC1.writeFadeRGB(2); //Fade enabled with 2ms step
}
#endif
#ifdef I2C_ENC2_ADDR
COLD void blink_I2C_ENC2_RGB(void)
{
/* blink the RGB LED */
I2C_ENC2.writeRGBCode(0xFF0000);
delay(250);
I2C_ENC2.writeRGBCode(0x00FF00);
delay(250);
I2C_ENC2.writeRGBCode(0x0000FF);
delay(250);
I2C_ENC2.writeRGBCode(0x000000);
DPRINTLN(F("Blink I2C_ENC2 RGB"));
I2C_ENC2.writeFadeRGB(3); //Fade enabled with 3ms step
}
#endif
#ifdef I2C_ENC3_ADDR
COLD void blink_I2C_ENC3_RGB(void)
{
/* blink the RGB LED */
I2C_ENC3.writeRGBCode(0xFF0000);
delay(250);
I2C_ENC3.writeRGBCode(0x00FF00);
delay(250);
I2C_ENC3.writeRGBCode(0x0000FF);
delay(250);
I2C_ENC3.writeRGBCode(0x000000);
DPRINTLN(F("Blink I2C_ENC3 RGB"));
I2C_ENC3.writeFadeRGB(3); //Fade enabled with 3ms step
}
#endif
#ifdef I2C_ENC4_ADDR
COLD void blink_I2C_ENC4_RGB(void)
{
/* blink the RGB LED */
I2C_ENC4.writeRGBCode(0xFF0000);
delay(250);
I2C_ENC4.writeRGBCode(0x00FF00);
delay(250);
I2C_ENC4.writeRGBCode(0x0000FF);
delay(250);
I2C_ENC4.writeRGBCode(0x000000);
DPRINTLN(F("Blink I2C_ENC4 RGB"));
I2C_ENC4.writeFadeRGB(3); //Fade enabled with 3ms step
}
#endif
#ifdef I2C_ENC5_ADDR
COLD void blink_I2C_ENC5_RGB(void)
{
/* blink the RGB LED */
I2C_ENC5.writeRGBCode(0xFF0000);
delay(250);
I2C_ENC5.writeRGBCode(0x00FF00);
delay(250);
I2C_ENC5.writeRGBCode(0x0000FF);
delay(250);
I2C_ENC5.writeRGBCode(0x000000);
DPRINTLN(F("Blink I2C_ENC5 RGB"));
I2C_ENC5.writeFadeRGB(3); //Fade enabled with 3ms step
}
#endif
#ifdef I2C_ENC6_ADDR
COLD void blink_I2C_ENC6_RGB(void)
{
/* blink the RGB LED */
I2C_ENC6.writeRGBCode(0xFF0000);
delay(250);
I2C_ENC6.writeRGBCode(0x00FF00);
delay(250);
I2C_ENC6.writeRGBCode(0x0000FF);
delay(250);
I2C_ENC6.writeRGBCode(0x000000);
DPRINTLN(F("Blink I2C_ENC6 RGB"));
I2C_ENC6.writeFadeRGB(3); //Fade enabled with 3ms step
}
#endif