-
Notifications
You must be signed in to change notification settings - Fork 0
/
FlatCW.ino
898 lines (710 loc) · 19.8 KB
/
FlatCW.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
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
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
#include <Wire.h>
#include "Adafruit_MPR121.h"
#include "TM1637.h"
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
#define TOUCH_LINES 36
#define TOUCH_TOOCLOSE 2
#define TOUCH_TOONARROW 2
#define DELTA_TOUCH 2 // 0 = disable
#define POS_NONE -1
#define TOUCH_FORGET_MS 5000
#define TOUCH_RENEW_DELTA 3 // 0 = disable
// Pins
#define BUZZ_OUT 2
#define BUZZ_OUT_I 3
#define KEY_OUT 4
boolean buzzPol = false;
volatile boolean buzzOn = false;
// Display TM1637
#define CLK 9//pins definitions for the module and can be changed to other ports
#define DIO 8
TM1637 disp(CLK,DIO);
#define DISP_SPACE 17
// Settings
#define INIT_WPM 20
#define MIN_WPM 5
#define MAX_WPM 50
uint16_t speedWpm = INIT_WPM;
boolean reversePaddles = false;
int getDitTime()
{
return 1200/speedWpm;
}
int getDahTime()
{
return 3*1200/speedWpm;
}
int getPauseTime()
{
return 1200/speedWpm;
}
// Sound
void outputSetup()
{
pinMode(BUZZ_OUT, OUTPUT);
pinMode(BUZZ_OUT_I, OUTPUT);
pinMode(KEY_OUT, OUTPUT);
digitalWrite(KEY_OUT, LOW);
}
void outputOn()
{
buzzOn = true;
digitalWrite(KEY_OUT, HIGH);
}
void outputOff()
{
buzzOn = false;
digitalWrite(KEY_OUT, LOW);
}
// Touch sensors
// You can have up to 4 on one i2c bus but one is enough for testing!
Adafruit_MPR121 cap5A = Adafruit_MPR121();
Adafruit_MPR121 cap5B = Adafruit_MPR121();
Adafruit_MPR121 cap5C = Adafruit_MPR121();
/*
// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
*/
// CW machine
volatile bool ditPressed = false, dahPressed = false, ditPriority = false;
bool ditPressedOld = false, dahPressedOld = false;
enum CWSTATES {CW_NONE, CW_SENDING_DIT, CW_SENDING_DAH, CW_PAUSE_AFTER_DIT, CW_PAUSE_AFTER_DAH };
CWSTATES cwState = CWSTATES::CW_NONE;
volatile boolean memDit = false, memDah = false;
int endTimer = 0;
void readEeprom()
{
uint16_t signature = eeprom_read_word(0);
if (signature == 0x4321) // Read if signature OK
{
speedWpm = eeprom_read_word(2);
reversePaddles = eeprom_read_byte(4);
}
else // Set defaults
{
eeprom_write_word(0, 0x4321); // Write signature
speedWpm = INIT_WPM;
reversePaddles = false;
writeEeprom();
}
}
void writeEeprom()
{
eeprom_update_word(2, speedWpm);
eeprom_update_byte(4, reversePaddles);
}
void setup()
{
// EEPROM
readEeprom();
// Serial
Serial.begin(115200);
while (!Serial) { // needed to keep leonardo/micro from starting too fast!
delay(10);
}
Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
// Default address is 0x5A, if tied to 3.3V its 0x5B
// If tied to SDA its 0x5C and if SCL then 0x5D
if (!cap5A.begin(0x5A)) {
Serial.println("0x5A - MPR121 not found, check wiring?");
while (1);
}
if (!cap5B.begin(0x5B)) {
Serial.println("0x5A - MPR121 not found, check wiring?");
while (1);
}
if (!cap5C.begin(0x5C)) {
Serial.println("0x5A - MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
#define MPR121_TOUCH_THRESHOLD 6 // Defalut: 12
#define MPR121_RELEASE_THRESHOLD 3 // Defalut: 6
cap5A.setThresholds(MPR121_TOUCH_THRESHOLD,MPR121_RELEASE_THRESHOLD);
cap5B.setThresholds(MPR121_TOUCH_THRESHOLD,MPR121_RELEASE_THRESHOLD);
cap5C.setThresholds(MPR121_TOUCH_THRESHOLD,MPR121_RELEASE_THRESHOLD);
// Output
outputSetup();
// Display
disp.set(BRIGHT_TYPICAL);//BRIGHT_TYPICAL = 2,BRIGHT_DARKEST = 0,BRIGHTEST = 7;
disp.init(D4036B);
//return;
// Set up 1 kHz timer
cli();//stop interrupts
// //set timer0 interrupt at 1kHz
// TCCR0A = 0;// set entire TCCR2A register to 0
// TCCR0B = 0;// same for TCCR2B
// TCNT0 = 0;//initialize counter value to 0
// // set compare match register for 2khz increments
//// OCR0A = 124;// = (16*10^6) / (2000*64) - 1 (must be <256)
// OCR0A = 249;// = (16*10^6) / (1000*64) - 1 (must be <256)
// // turn on CTC mode
// TCCR0A |= (1 << WGM01);
// // Set CS01 and CS00 bits for 64 prescaler
// TCCR0B |= (1 << CS01) | (1 << CS00);
// // enable timer compare interrupt
// TIMSK0 |= (1 << OCIE0A);
//set timer2 interrupt at 1kHz
TCCR2A = 0;// set entire TCCR2A register to 0
TCCR2B = 0;// same for TCCR2B
TCNT2 = 0;//initialize counter value to 0
// set compare match register for 8khz increments
// OCR2A = 249;// = (16*10^6) / (8000*8) - 1 (must be <256)
OCR2A = 249;// = (16*10^6) / (1000*64) - 1 (must be <256)
// turn on CTC mode
TCCR2A |= (1 << WGM21);
// Set CS22 bit for 64 prescaler
TCCR2B |= (1 << CS22);
// enable timer compare interrupt
TIMSK2 |= (1 << OCIE2A);
sei();//allow interrupts
}
//int leftPosFirst = POS_NONE, leftPosSecond = POS_NONE, rightPosFirst = POS_NONE, rightPosSecond = POS_NONE;
int grLprev = POS_NONE, grRprev = POS_NONE, grCprev = POS_NONE;
int leftPos = POS_NONE, rightPos = POS_NONE, leftPosPrev = POS_NONE, rightPosPrev = POS_NONE;
//unsigned long lastPaddleMs = 0;
volatile unsigned int pauseTimer = 0;
void loop()
{
// Get current time
// unsigned long curMs = millis();
// Get the currently touched pads
uint64_t currTouched = ((uint64_t)cap5A.touched()) | (((uint64_t)cap5B.touched())<<12) | (((uint64_t)cap5C.touched())<<24);
if (currTouched & 1) // Setup
{
// Reset all states
pauseTimer = TOUCH_FORGET_MS; // Forget
leftPosPrev = POS_NONE;
rightPosPrev = POS_NONE;
int8_t dispData[] = {DISP_SPACE, DISP_SPACE, DISP_SPACE, DISP_SPACE,};
if ( (currTouched & (1UL<<5)) || (currTouched & (1UL<<10)) ) // WPM
{
if (currTouched & (1UL<<5)) // Minus
{
speedWpm --;
if (speedWpm < MIN_WPM)
speedWpm = MIN_WPM;
}
else
if (currTouched & (1UL<<10)) // Plus
{
speedWpm ++;
if (speedWpm > MAX_WPM)
speedWpm = MAX_WPM;
}
// Display WPM
dispData[0] = 5; // S
dispData[1] = 25; // P
dispData[2] = speedWpm / 10;
dispData[3] = speedWpm%10;
if (dispData[2] == 0)
dispData[2] = DISP_SPACE;
disp.point(true);
disp.display(dispData);
ditPressed = true; // Test
writeEeprom();
delay(200);
}
else
if ( currTouched & (1UL<<20) ) // Reverse paddle
{
reversePaddles = !reversePaddles;
// Display REV
dispData[0] = 19; // R
dispData[1] = 0x0E; // E
dispData[2] = 0; // O
if (reversePaddles)
{
dispData[3] = 21; // n
}
else
{
dispData[3] = 0x0F; // f
}
disp.point(true);
disp.display(dispData);
writeEeprom();
delay(1000);
}
// else
// {
// // Display SET
//
// dispData[0] = 5; // S
// dispData[1] = 0x0E; // E
// dispData[2] = 22; // t
// dispData[2] = DISP_SPACE;
//
// disp.point(false);
// disp.display(dispData);
//
// }
return;
}
// Clear some lines
currTouched &= ~(1ULL << (TOUCH_LINES-1) );
currTouched &= ~(1ULL << (TOUCH_LINES-2) );
currTouched &= ~(1ULL << (TOUCH_LINES-3) );
currTouched &= ~(1ULL << 0 );
currTouched &= ~(1ULL << 1 );
currTouched &= ~(1ULL << 2 );
// Calculate begin and end positions of left and right touches
int grLbeg = POS_NONE, grLend = POS_NONE;
for (int i=0; i<TOUCH_LINES; i++)
{
if (currTouched & (1ULL << i) )
{
if (grLbeg == POS_NONE)
grLbeg = i;
grLend = i;
}
else
{
if (grLbeg != POS_NONE)
break;
}
}
int grRbeg = POS_NONE, grRend = POS_NONE;
for (int i=TOUCH_LINES-1; i>=0; i--)
{
if (currTouched & (1ULL << i) )
{
if (grRbeg == POS_NONE)
grRbeg = i;
grRend = i;
}
else
{
if (grRbeg != POS_NONE)
break;
}
}
// Calculated middle positions of left and right touches
int grL = (grLbeg+grLend)/2;
int grR = (grRbeg+grRend)/2;
/*
if ( abs(grLend - grLbeg) <= TOUCH_TOONARROW) // Too narrow?
grL = POS_NONE;
if ( abs(grRend - grRbeg) <= TOUCH_TOONARROW) // Too narrow?
grR = POS_NONE;
*/
if ( abs (grL-grR) <= TOUCH_TOOCLOSE) // Are the touches too close?
{
grL = grR = (grL+grR)/2;
}
// Serial.println(-grLbeg+grLend);
// Serial.print("grL: ");
// Serial.print(grL);
// Serial.print(" grR: ");
// Serial.print(grR);
//
// Serial.println("");
bool leftPriority = false;
// Analyze touches grL and grR, decide if dit or dah is pressed
if ( (grL == POS_NONE) && (grR == POS_NONE) ) // No touch
{
leftPos = POS_NONE;
rightPos = POS_NONE;
grCprev = POS_NONE;
}
else
if ( grL == grR ) // One single touch
{
if ( (leftPos == POS_NONE) && (rightPos == POS_NONE) ) // If left and righ touches are not already defined
{
if (grCprev==POS_NONE) // We need to fix the first touch
{
grCprev = grL; // = grR
}
else
{
if (DELTA_TOUCH>0) // Need to swipe to start
{
if ( (TOUCH_RENEW_DELTA>0) && (pauseTimer<TOUCH_FORGET_MS) ) // Try to use the renew timer to remember last pos
{
if (abs(grL-leftPosPrev) < TOUCH_RENEW_DELTA)
leftPos = grL;
else
if (abs(grR-rightPosPrev) < TOUCH_RENEW_DELTA)
rightPos = grR;
else
{
pauseTimer = TOUCH_FORGET_MS; // Forget
leftPosPrev = POS_NONE;
rightPosPrev = POS_NONE;
}
}
if ( (grL - grCprev) >= DELTA_TOUCH )
{
leftPos = grL;
}
else
if ( (grCprev - grR) >= DELTA_TOUCH )
{
rightPos = grR;
}
// if ( (leftPos==POS_NONE) && (rightPos==POS_NONE) )
// {
// pauseTimer = TOUCH_FORGET_MS; // Forget
// }
}
else // Do not need to swipe, just make choise depending on a position
{
if ( grL >= TOUCH_LINES/2 )
rightPos = grR;
else
leftPos = grL;
}
}
}
else
if ( (leftPos != POS_NONE) && (rightPos != POS_NONE) ) // If left and righ touches are both defined
{
if ( abs (grL - leftPos) < abs (grR - rightPos) ) // Decide which direction was realeased
{
leftPos = grL; // Update
rightPos = POS_NONE; // Delete
}
else
{
rightPos = grR; // Update
leftPos = POS_NONE; // Delete
}
}
else // One of touches defined, update positions
{
if (leftPos != POS_NONE)
leftPos = grL;
else
if (rightPos != POS_NONE)
rightPos = grR;
}
}
else
// if ( grlL != grR ) // Two different touches
{
// Update positions
if ( (leftPos == POS_NONE) && (rightPos == POS_NONE) && (grCprev != POS_NONE) ) // If left and righ touches are not already defined
{
if ( abs (grL - grCprev) < abs (grR - grCprev) ) // Decide which direction was touched first
leftPriority = true;
else
leftPriority = false;
}
leftPos = grL;
rightPos = grR;
}
if (leftPos != POS_NONE)
leftPosPrev = leftPos;
if (rightPos != POS_NONE)
rightPosPrev = rightPos;
// Serial.print("leftPos: ");
// Serial.print(leftPos);
//
// Serial.print(" rightPos: ");
// Serial.print(rightPos);
//
// Serial.println("");
ditPressed = reversePaddles ? (rightPos != POS_NONE) : (leftPos != POS_NONE);
dahPressed = reversePaddles ? (leftPos != POS_NONE) : (rightPos != POS_NONE);
ditPriority = leftPriority ^ reversePaddles;
if (ditPressed && (!ditPressedOld) )
memDit = true;
if (dahPressed && (!dahPressedOld) )
memDah = true;
// if ( ditPressed || dahPressed ) // Update millisecond timestamp since last touch
// lastPaddleMs = curMs;
// Serial.println(lastPaddleMs);
ditPressedOld = ditPressed;
dahPressedOld = dahPressed;
if (ditPressed || dahPressed)
pauseTimer = 0;
delay(1);
#if 0
// Calculate persistent positions of left and right touches
int leftPos = POS_NONE, rightPos = POS_NONE;
if (grL != POS_NONE)
{
if (leftPos == -1)
{
if (grL < TOUCH_LINES/2)
leftPos = grL;
}
else
{
if (abs (leftPos-grL) <= DELTA_TOUCH )
leftPos = grL;
else
leftPos = POS_NONE;
}
}
else
leftPos = POS_NONE;
if (grR != POS_NONE)
{
if (rightPos == -1)
{
if (grR >= TOUCH_LINES/2)
rightPos = grR;
}
else
{
if (abs (rightPos-grR) <= DELTA_TOUCH )
rightPos = grR;
else
rightPos = POS_NONE;
}
}
else
rightPos = POS_NONE;
Serial.print("leftPos: ");
Serial.print(leftPos);
Serial.print(" rightPos: ");
Serial.print(rightPos);
Serial.println("");
delay(1);
ditPressed = reversePaddles ? (rightPos != POS_NONE) : (leftPos != POS_NONE);
dahPressed = reversePaddles ? (leftPos != POS_NONE) : (rightPos != POS_NONE);
#endif
#if 0
// Analyze movements
if (grL != POS_NONE)
{
if (leftPosFirst == -1)
{
leftPosFirst = grL;
leftPosSecond = grL;
}
else
{
if (grL > leftPosSecond)
{
leftPosSecond = grL;
// if (grL == grR)
// {
// rightPosFirst = POS_NONE;
// rightPosSecond = POS_NONE;
// }
}
}
}
else
{
leftPosFirst = POS_NONE;
leftPosSecond = POS_NONE;
}
if (grR != POS_NONE)
{
if (rightPosFirst == -1)
// if ( (rightPosFirst == -1) || (grL != grR) )
{
rightPosFirst = grR;
rightPosSecond = grR;
}
else
{
if (grR < rightPosSecond)
{
rightPosSecond = grR;
// if (grL == grR)
// {
// leftPosFirst = POS_NONE;
// leftPosSecond = POS_NONE;
// }
}
}
}
else
{
rightPosFirst = POS_NONE;
rightPosSecond = POS_NONE;
}
Serial.print("leftPosFirst: ");
Serial.print(leftPosFirst);
Serial.print(" leftPosSecond: ");
Serial.print(leftPosSecond);
Serial.print(" rightPosFirst: ");
Serial.print(rightPosFirst);
Serial.print(" rightPosSecond: ");
Serial.print(rightPosSecond);
Serial.println("");
ditPressed = (leftPosSecond - leftPosFirst) >= DELTA_TOUCH;
dahPressed = (rightPosFirst - rightPosSecond) >= DELTA_TOUCH;
#endif
//
// if ( ditPressed && (grL==grR) )
// {
// if (!dahPressed)
// {
// rightPosFirst = POS_NONE;
// rightPosSecond = POS_NONE;
// }
// }
//
// if ( dahPressed && (grL==grR) )
// {
// if (!ditPressed)
// {
// leftPosFirst = POS_NONE;
// leftPosSecond = POS_NONE;
// }
// }
/*
return;
for (uint8_t i = 0; i < 12; i++) {
// it if *is* touched and *wasnt* touched before, alert!
if ((currTouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" touched");
}
// if it *was* touched and now *isnt*, alert!
if (!(currTouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" released");
}
}
// reset our state
lasttouched = currTouched;
// comment out this line for detailed data from the sensor!
return;
// debugging info, what
Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
Serial.print("Filt: ");
for (uint8_t i = 0; i < 12; i++) {
Serial.print(cap.filteredData(i)); Serial.print("\t");
}
Serial.println();
Serial.print("Base: ");
for (uint8_t i = 0; i < 12; i++) {
Serial.print(cap.baselineData(i)); Serial.print("\t");
}
Serial.println();
// put a delay so it isn't overwhelming
delay(100);
*/
}
//storage variables
//boolean toggle0 = 0;
// 1 kHz timer
ISR(TIMER2_COMPA_vect)
//ISR(TIMER0_COMPA_vect)
{
// return;
////generates pulse wave of frequency 2kHz/2 = 1kHz (takes two cycles for full wave- toggle high then toggle low)
// if (toggle0){
// digitalWrite(BUZZ,HIGH);
// toggle0 = 0;
// }
// else{
// digitalWrite(BUZZ,LOW);
// toggle0 = 1;
// }
// currTime++;
// Buzzer
if ( buzzOn )
{
if (buzzPol)
{
digitalWrite(BUZZ_OUT, HIGH);
digitalWrite(BUZZ_OUT_I, LOW);
}
else
{
digitalWrite(BUZZ_OUT_I, HIGH);
digitalWrite(BUZZ_OUT, LOW);
}
buzzPol = !buzzPol;
}
// Timers
pauseTimer++;
if (endTimer)
endTimer--;
// State machine
switch (cwState) {
case CWSTATES::CW_NONE:
if (ditPriority)
{
if (ditPressed) {
endTimer = getDitTime();
outputOn();
memDit = false;
cwState = CWSTATES::CW_SENDING_DIT;
}
else
if (dahPressed) {
endTimer = getDahTime();
outputOn();
memDah = false;
cwState = CWSTATES::CW_SENDING_DAH;
}
}
else
{
if (dahPressed) {
endTimer = getDahTime();
outputOn();
memDah = false;
cwState = CWSTATES::CW_SENDING_DAH;
}
else
if (ditPressed) {
endTimer = getDitTime();
outputOn();
memDit = false;
cwState = CWSTATES::CW_SENDING_DIT;
}
}
break;
case CWSTATES::CW_SENDING_DIT:
if (endTimer == 0) {
endTimer = getPauseTime();
outputOff();
cwState = CWSTATES::CW_PAUSE_AFTER_DIT;
}
break;
case CWSTATES::CW_SENDING_DAH:
if (endTimer == 0) {
endTimer = getPauseTime();
outputOff();
cwState = CWSTATES::CW_PAUSE_AFTER_DAH;
}
break;
case CWSTATES::CW_PAUSE_AFTER_DIT:
if (endTimer == 0) {
if (dahPressed || memDah) {
endTimer = getDahTime();
outputOn();
memDah = false;
cwState = CWSTATES::CW_SENDING_DAH;
}
else if (ditPressed || memDit) {
endTimer = getDitTime();
outputOn();
memDit = false;
cwState = CWSTATES::CW_SENDING_DIT;
}
else
cwState = CWSTATES::CW_NONE;
}
break;
case CWSTATES::CW_PAUSE_AFTER_DAH:
if (endTimer == 0) {
if (ditPressed || memDit) {
endTimer = getDitTime();
outputOn();
memDit = false;
cwState = CWSTATES::CW_SENDING_DIT;
}
else if (dahPressed || memDah) {
endTimer = getDahTime();
outputOn();
memDah = false;
cwState = CWSTATES::CW_SENDING_DAH;
}
else
cwState = CWSTATES::CW_NONE;
}
break;
}
}