ArduinoDumbDisplay v0.9.9-r34
DumbDisplay Arduino Library -- https://github.com/trevorwslee/Arduino-DumbDisplay
 
Loading...
Searching...
No Matches
ddjoystick.h
1
2
3#ifndef ddjoystick_h
4#define ddjoystick_h
5
6
9{
10 int xPressed; // -1, 0 or 1
11 int yPressed; // -1, 0 or 1
12};
13
16{
17 bool aPressed;
18 bool bPressed;
19 bool cPressed;
20 bool dPressed;
21};
22
23
26{
27 int xPressed;
28 int yPressed;
29 bool swPressed;
30};
31
34{
35public:
36 static const long BlackOutMillis = 50;
37
38protected:
39 JoystickInterface(bool buttonsOnly)
40 {
41 this->buttonsOnly = buttonsOnly;
42 // this->lastCheckJoystickPress.xPressed = 0;
43 // this->lastCheckJoystickPress.yPressed = 0;
44 this->lastCheckMillis = 0;
45 // this->lastCheckABCDPressed.aPressed = false;
46 // this->lastCheckABCDPressed.bPressed = false;
47 // this->lastCheckABCDPressed.dPressed = false;
48 // this->lastCheckABCDPressed.cPressed = false;
49 }
50
51public:
52 const JoystickPress *checkJoystickPress(int repeat = 0)
53 {
54 int xPressed = _checkPressedX(repeat, false);
55 int yPressed = _checkPressedY(repeat, false);
56 if (xPressed != 0 || yPressed != 0)
57 {
58 // Serial.print(xPressed);
59 // Serial.print("/");
60 // Serial.println(yPressed);
61 long nowMillis = millis();
62 long diffMillis = nowMillis - this->lastCheckMillis;
63 // Serial.println(diffMillis);
64 // delay(200);
65 if (diffMillis >= BlackOutMillis)
66 {
67 lastCheckJoystickPress.xPressed = 0;
68 lastCheckJoystickPress.yPressed = 0;
69 bool pressedA = _checkPressedBypass('A') || yPressed == -1;
70 bool pressedB = _checkPressedBypass('B') || xPressed == 1;
71 bool pressedC = _checkPressedBypass('C') || yPressed == 1;
72 bool pressedD = _checkPressedBypass('D') || xPressed == -1;
73 if (pressedB)
74 {
75 // Serial.println("B");
76 lastCheckJoystickPress.xPressed = 1;
77 }
78 else if (pressedD)
79 {
80 // Serial.println("D");
81 lastCheckJoystickPress.xPressed = -1;
82 }
83 if (pressedA)
84 {
85 // Serial.println("A");
86 lastCheckJoystickPress.yPressed = -1;
87 }
88 else if (pressedC)
89 {
90 // Serial.println("C");
91 lastCheckJoystickPress.yPressed = 1;
92 }
93 lastCheckMillis = nowMillis;
94 return &lastCheckJoystickPress;
95 }
96 }
97 return NULL;
98 }
99 inline bool checkSWPressed(int repeat = 0)
100 {
101 return _checkPressed('E', repeat);
102 }
103 inline bool forButtonsOnly() const {
104 return this->buttonsOnly;
105 }
106 const ABCDPressed *checkABCDPressed(int repeat = 0)
107 {
108 int aPressed = _checkPressed('A', repeat);
109 int bPressed = _checkPressed('B', repeat);
110 int cPressed = _checkPressed('C', repeat);
111 int dPressed = _checkPressed('D', repeat);
112 if (aPressed || bPressed || cPressed || dPressed)
113 {
114 long nowMillis = millis();
115 long diffMillis = nowMillis - this->lastCheckMillis;
116 if (diffMillis >= BlackOutMillis)
117 {
118 //delay(200); // delay a bit
119 this->lastCheckABCDPressed.aPressed = _checkPressedBypass('A') || aPressed;
120 this->lastCheckABCDPressed.bPressed = _checkPressedBypass('B') || bPressed;
121 this->lastCheckABCDPressed.cPressed = _checkPressedBypass('C') || cPressed;
122 this->lastCheckABCDPressed.dPressed = _checkPressedBypass('D') || dPressed;
123 lastCheckMillis = nowMillis;
124 return &lastCheckABCDPressed;
125 }
126 }
127 return NULL;
128 }
129 inline bool checkAPressed(int repeat = 0)
130 {
131 return _checkPressed('A', repeat);
132 }
133 inline bool checkBPressed(int repeat = 0)
134 {
135 return _checkPressed('B', repeat);
136 }
137 inline bool checkCPressed(int repeat = 0)
138 {
139 return _checkPressed('C', repeat);
140 }
141 inline bool checkDPressed(int repeat = 0)
142 {
143 return _checkPressed('D', repeat);
144 }
145
146public:
147 bool checkJoystickPressCode(JoystickPressCode &joystickPressCode, int repeat = 0)
148 {
149 joystickPressCode.xPressed = _checkPressedX(repeat, true);
150 joystickPressCode.yPressed = _checkPressedY(repeat, true);
151 joystickPressCode.swPressed = _checkPressed('E', repeat);
152 return joystickPressCode.xPressed != 0 || joystickPressCode.yPressed != 0 || joystickPressCode.swPressed;
153 // joystickPressCode.xPressed = 0;
154 // joystickPressCode.yPressed = 0;
155 // joystickPressCode.swPressed = false;
156 // const JoystickPress *joystickPress = checkJoystickPress(repeat);
157 // bool swPressed = checkSWPressed(repeat);
158 // if (joystickPress != NULL || swPressed)
159 // {
160 // if (joystickPress != NULL)
161 // {
162 // joystickPressCode.xPressed = joystickPress->xPressed;
163 // joystickPressCode.yPressed = joystickPress->yPressed;
164 // }
165 // joystickPressCode.swPressed = swPressed;
166 // return true;
167 // }
168 // else
169 // {
170 // return false;
171 // }
172 }
173
174protected:
178 inline bool _checkPressed(char button, int repeat)
179 {
180 return _checkPressed(button, repeat, false);
181 }
182 inline bool _checkPressedBypass(char button) {
183 return _checkPressed(button, 0, true);
184 }
185
186protected:
187 virtual int _checkPressedX(int repeat, bool raw);
188 virtual int _checkPressedY(int repeat, bool raw);
189 virtual bool _checkPressed(char button, int repeat, bool bypass);
190
191private:
192 bool buttonsOnly;
193 JoystickPress lastCheckJoystickPress;
194 ABCDPressed lastCheckABCDPressed;
195 long lastCheckMillis;
196};
197
200{
201public:
202 ButtonPressTracker(uint8_t pin)
203 {
204 this->pin = pin;
205 this->pressed = false;
206 this->blackOutMillis = 0;
207 this->nextRepeatMillis = 0;
208 }
209 bool checkPressed(int repeat = 0)
210 {
211 int reading = digitalRead(this->pin);
212 return setPressed(reading == 0, repeat);
213 }
214 bool checkPressedBypass()
215 {
216 int reading = digitalRead(this->pin);
217 if (true) {
218 } else {
219 setPressed(reading == 0);
220 }
221 return pressed;
222 }
223 inline bool checkPressed(int repeat, bool bypass) {
224 if (bypass) {
225 return checkPressedBypass();
226 } else {
227 return checkPressed(repeat);
228 }
229 }
230// inline bool debug_checkPressed(int repeat, bool bypass, char button) {
231// if (bypass) {
232// //Serial.println("BYPASS");
233// return checkPressedBypass();
234// } else {
235// // Serial.print(button);
236// // Serial.print(">");
237// // Serial.println(repeat);
238// return checkPressed(repeat);
239// }
240// //delay(50);
241// }
242
243
244private:
245 bool setPressed(bool pressed, int repeat = 0)
246 {
247 if (repeat == 0)
248 {
249 this->nextRepeatMillis = 0;
250 }
251 long nowMillis = millis();
252 if (this->blackOutMillis != 0)
253 {
254 long diff = this->blackOutMillis - nowMillis;
255 if (diff < 0)
256 {
257 this->blackOutMillis = 0;
258 }
259 }
260 if (this->blackOutMillis == 0)
261 {
262 if (pressed != this->pressed)
263 {
264 this->pressed = pressed;
265 this->blackOutMillis = nowMillis + JoystickInterface::BlackOutMillis /*50*/;
266 if (repeat != 0 && this->pressed)
267 {
268 this->nextRepeatMillis = nowMillis + repeat;
269 }
270 else
271 {
272 this->nextRepeatMillis = 0;
273 }
274 return this->pressed;
275 }
276 }
277 if (this->nextRepeatMillis != 0)
278 {
279 long diff = this->nextRepeatMillis - nowMillis;
280 if (diff < 0)
281 {
282 this->nextRepeatMillis = nowMillis + repeat;
283 return true;
284 }
285 }
286 return false;
287 }
288
289private:
290 uint8_t pin;
291 bool pressed;
292 long blackOutMillis;
293 long nextRepeatMillis;
294};
295
296
299{
300public:
301 static const int DefAutoTuneThreshold = 50;
302 static const int DefMinReading = DefAutoTuneThreshold;
303 static const int DefMaxReading = 1023 - DefAutoTuneThreshold;
304
305public:
306 JoystickPressTracker(uint8_t pin, int minReading = DefMinReading, int maxReading = DefMaxReading)
307 {
308 this->pin = pin;
309 this->autoTuneThreshold = -1;
310 resetMinMax(minReading, maxReading, true);
311 }
315 JoystickPressTracker(uint8_t pin, bool reverseDir, int autoTuneThreshold = DefAutoTuneThreshold)
316 {
317 // int autoThreshold = autoTune ? 200 : -1;
318 // int autoThreshold = autoTune ? 50 : -1;
319 this->pin = pin;
320 this->autoTuneThreshold = autoTuneThreshold;
321 this->autoMin = 10000;
322 this->autoMax = -1;
323 int minReading = reverseDir ? DefMaxReading : DefMinReading;
324 int maxReading = reverseDir ? DefMinReading : DefMaxReading;
325 resetMinMax(minReading, maxReading, true);
326 }
327
328public:
329 int8_t checkPressed(int repeat = 0)
330 {
331 int reading = analogRead(this->pin);
332 if (this->autoTuneThreshold != -1)
333 {
334 if (reading < this->autoMin)
335 {
336 this->autoMin = reading;
337 }
338 if (reading > this->autoMax)
339 {
340 this->autoMax = reading;
341 }
342 if ((this->autoMax - this->autoMin) >= 800)
343 {
344 resetMinMax(this->autoMin + this->autoTuneThreshold, this->autoMax - this->autoTuneThreshold, false);
345 }
346 }
347 return setReading(reading, repeat);
348 }
349 int checkPressedBypass()
350 {
351 int reading = analogRead(this->pin);
352 if (true) {
353 } else {
354 setReading(reading);
355 }
356 int pressed = readingToPressedDir(reading);
357 // Serial.print(reading);
358 // Serial.print(">>");
359 // Serial.println(pressed);
360 return pressed;
361 }
362 int8_t checkPressed(int repeat, bool bypass) {
363 if (bypass) {
364 return checkPressedBypass();
365 } else {
366 return checkPressed(repeat);
367 }
368 }
369 inline int one() {
370 return this->reverseDir ? -1 : 1;
371 }
372 inline int minusOne() {
373 return this->reverseDir ? 1 : -1;
374 }
375 int readBypass()
376 {
377 int reading = analogRead(this->pin);
378 setReading(reading);
379 return reading;
380 }
381
382private:
383 int readingToPressedDir(int reading)
384 {
385 if (reading <= this->minReading)
386 {
387 if (this->reverseDir)
388 {
389 return 1;
390 }
391 else
392 {
393 return -1;
394 }
395 }
396 if (reading >= this->maxReading)
397 {
398 if (this->reverseDir)
399 {
400 return -1;
401 }
402 else
403 {
404 return 1;
405 }
406 }
407 return 0;
408 }
409 int8_t setReading(int reading, int repeat = 0)
410 {
411 if (repeat == 0)
412 {
413 this->nextRepeatMillis = 0;
414 this->autoRepeatDir = 0;
415 }
416 long nowMillis = millis();
417 int8_t oriPressedDir = this->pressedDir;
418 int pressedDir = readingToPressedDir(reading);
419 if (pressedDir != 0)
420 {
421 this->pressedDir = pressedDir;
422 }
423 else
424 {
425 this->pressedDir = 0;
426 this->nextRepeatMillis = 0;
427 this->autoRepeatDir = 0;
428 }
429 if (!this->needReset && this->pressedMillis != 0 && (this->pressedDir == oriPressedDir))
430 {
431// Serial.println(reading);
432// delay(100);
433 long diffMillis = nowMillis - this->pressedMillis;
434 if (diffMillis >= JoystickInterface::BlackOutMillis)
435 {
436 this->pressedDir = 0;
437 this->pressedMillis = 0;
438 this->needReset = true;
439 if (repeat != 0 && oriPressedDir != 0)
440 {
441 this->nextRepeatMillis = nowMillis + repeat;
442 this->autoRepeatDir = oriPressedDir;
443 }
444 else
445 {
446 this->nextRepeatMillis = 0;
447 this->autoRepeatDir = 0;
448 }
449 // Serial.print(repeat);
450 // Serial.print(":");
451 // Serial.print(reading);
452 // Serial.print("=>");
453 // Serial.println(oriPressedDir);
454 return oriPressedDir;
455 }
456 }
457 else
458 {
459 if (this->pressedDir != 0)
460 {
461 if (this->pressedMillis == 0)
462 {
463 this->pressedMillis = millis();
464 }
465 }
466 else
467 {
468 this->pressedMillis = 0;
469 this->needReset = false;
470 }
471 }
472 if (this->nextRepeatMillis != 0)
473 {
474 long diff = this->nextRepeatMillis - nowMillis;
475 if (diff < 0)
476 {
477 this->nextRepeatMillis = nowMillis + repeat;
478 return this->autoRepeatDir;
479 }
480 }
481 return 0;
482 }
483 void resetMinMax(int minReading, int maxReading, bool forceReset)
484 {
485 if (forceReset || this->minReading != minReading || this->maxReading != maxReading)
486 {
487 if (forceReset)
488 {
489 if (maxReading < minReading)
490 {
491 int temp = maxReading;
492 maxReading = minReading;
493 minReading = temp;
494 this->reverseDir = true;
495 }
496 else
497 {
498 this->reverseDir = false;
499 }
500 }
501 this->maxReading = maxReading;
502 this->minReading = minReading;
503 this->pressedDir = 0;
504 this->pressedMillis = 0;
505 this->needReset = false;
506 this->nextRepeatMillis = 0;
507 this->autoRepeatDir = 0;
508 // Serial.print(this->minReading);
509 // Serial.print("-");
510 // Serial.println(this->maxReading);
511 // delay(100);
512 }
513 }
514
515private:
516 int maxReading;
517 int minReading;
518 bool reverseDir;
519 int autoTuneThreshold; // -1 if not auto tune
520 int autoMin;
521 int autoMax;
522
523private:
524 uint8_t pin;
525 int pressedDir;
526 long pressedMillis;
527 bool needReset;
528 long nextRepeatMillis;
529 int autoRepeatDir;
530};
531
534{
535public:
537 {
538 this->xTracker = xTracker;
539 this->yTracker = yTracker;
540 this->swTracker = swTracker;
541 }
542
543protected:
544 virtual int _checkPressedX(int repeat, bool raw)
545 {
546 // Serial.println(repeat);
547 // delay(100);
548 int pressed = xTracker != NULL ? xTracker->checkPressed(repeat) : 0;
549 if (pressed != 0) {
550 // Serial.print("%X=");
551 // Serial.println(pressed);
552 }
553 return pressed;
554 }
555 virtual int _checkPressedY(int repeat, bool raw)
556 {
557 return yTracker != NULL ? yTracker->checkPressed(repeat) : 0;
558 }
559 virtual bool _checkPressed(char button, int repeat, bool bypass)
560 {
561 if (button == 'A')
562 {
563 return yTracker != NULL && (yTracker->checkPressed(repeat, bypass) == -1);
564 }
565 else if (button == 'B')
566 {
567 return xTracker != NULL && (xTracker->checkPressed(repeat, bypass) == 1);
568 }
569 else if (button == 'C')
570 {
571 return yTracker != NULL && (yTracker->checkPressed(repeat, bypass) == 1);
572 }
573 else if (button == 'D')
574 {
575 return xTracker != NULL && (xTracker->checkPressed(repeat, bypass) == -1);
576 }
577 else if (button == 'E')
578 {
579 bool pressed = swTracker != NULL && swTracker->checkPressed(repeat, bypass);
580//if (pressed && repeat != 0 && !bypass) { Serial.print(repeat); Serial.println(" <SW>"); }
581 return pressed;
582 }
583 else
584 {
585 return false;
586 }
587 }
588 // virtual bool _checkPressedBypass(char button)
589 // {
590 // if (button == 'A')
591 // {
592 // // Serial.println(yTracker->checkPressedBypass());
593 // // delay(200);
594 // return yTracker != NULL && (yTracker->checkPressedBypass() == -1);
595 // }
596 // else if (button == 'B')
597 // {
598 // return xTracker != NULL && (xTracker->checkPressedBypass() == 1);
599 // }
600 // else if (button == 'C')
601 // {
602 // return yTracker != NULL && (yTracker->checkPressedBypass() == 1);
603 // }
604 // else if (button == 'D')
605 // {
606 // return xTracker != NULL && (xTracker->checkPressedBypass() == -1);
607 // }
608 // else if (button == 'E')
609 // {
610 // return swTracker != NULL && swTracker->checkPressedBypass();
611 // }
612 // else
613 // {
614 // return false;
615 // }
616 // }
617
618private:
619 JoystickPressTracker *xTracker;
620 JoystickPressTracker *yTracker;
621 ButtonPressTracker *swTracker;
622};
623
626{
627protected:
628 ButtonJoystickBasic(bool buttonsOnly) : JoystickInterface(buttonsOnly)
629 {
630 }
631
632protected:
633 virtual int _checkPressedX(int repeat, bool raw)
634 {
635//if (!raw) { Serial.print(repeat); Serial.println(); delay(100); }
636 bool pressedB = _checkPressed('B', repeat);
637 bool pressedD = _checkPressed('D', repeat);
638 if (pressedB)
639 {
640//Serial.println("*B");
641 return raw && pressedD ? 2 : 1;
642 }
643 else if (pressedD)
644 {
645//Serial.println("*D");
646 return -1;
647 }
648 else
649 {
650 return 0;
651 }
652 }
653 virtual int _checkPressedY(int repeat, bool raw)
654 {
655 bool pressedA = _checkPressed('A', repeat);
656 bool pressedC = _checkPressed('C', repeat);
657 if (pressedA)
658 {
659//Serial.println("*A");
660 return raw && pressedC ? 2 : -1;
661 }
662 else if (pressedC)
663 {
664 // Serial.println("*C");
665 return 1;
666 }
667 else
668 {
669 return 0;
670 }
671 }
672 // virtual bool _checkPressed(char button, int repeat)
673 // {
674 // if (button == 'A')
675 // {
676 // return upTracker != NULL && upTracker->checkPressed(repeat);
677 // }
678 // else if (button == 'B')
679 // {
680 // return rightTracker != NULL && rightTracker->checkPressed(repeat);
681 // }
682 // else if (button == 'C')
683 // {
684 // return downTracker != NULL && downTracker->checkPressed(repeat);
685 // }
686 // else if (button == 'D')
687 // {
688 // return leftTracker != NULL && leftTracker->checkPressed(repeat);
689 // }
690 // else if (button == 'E')
691 // {
692 // return midTracker != NULL && midTracker->checkPressed(repeat);
693 // }
694 // else
695 // {
696 // return false;
697 // }
698 // }
699 // virtual bool _checkPressedBypass(char button)
700 // {
701 // if (button == 'A')
702 // {
703 // return upTracker != NULL && upTracker->checkPressedBypass();
704 // }
705 // else if (button == 'B')
706 // {
707 // return rightTracker != NULL && rightTracker->checkPressedBypass();
708 // }
709 // else if (button == 'C')
710 // {
711 // return downTracker != NULL && downTracker->checkPressedBypass();
712 // }
713 // else if (button == 'D')
714 // {
715 // return leftTracker != NULL && leftTracker->checkPressedBypass();
716 // }
717 // else if (button == 'E')
718 // {
719 // return midTracker != NULL && midTracker->checkPressedBypass();
720 // }
721 // else
722 // {
723 // return false;
724 // }
725 // }
726
727};
728
729
732{
733public:
734 DecodedJoystick(bool buttonsOnly) : ButtonJoystickBasic(buttonsOnly)
735 {
736 aValid = false;
737 bValid = false;
738 cValid = false;
739 dValid = false;
740 eValid = false;
741 }
742
743public:
744 void decode(JoystickPressCode &joystickPressCode)
745 {
746 this->joystickPressCode.xPressed = joystickPressCode.xPressed;
747 this->joystickPressCode.yPressed = joystickPressCode.yPressed;
748 this->joystickPressCode.swPressed = joystickPressCode.swPressed;
749 this->aValid = true;
750 this->bValid = true;
751 this->cValid = true;
752 this->dValid = true;
753 this->eValid = true;
754 }
755
756protected:
757 virtual bool _checkPressed(char button, int repeat, bool bypass)
758 {
759 bool res = false;
760 if (button == 'A')
761 {
762 if (aValid || bypass)
763 {
764 res = joystickPressCode.yPressed == -1 || joystickPressCode.yPressed == 2;
765 aValid = false;
766 }
767 }
768 else if (button == 'B')
769 {
770 if (bValid || bypass)
771 {
772 res = joystickPressCode.xPressed == 1 || joystickPressCode.xPressed == 2;
773 bValid = false;
774 }
775 }
776 else if (button == 'C')
777 {
778 if (cValid || bypass)
779 {
780 res = joystickPressCode.yPressed == 1 || joystickPressCode.yPressed == 2;
781 cValid = false;
782 }
783 }
784 else if (button == 'D')
785 {
786 if (dValid || bypass)
787 {
788 res = joystickPressCode.xPressed == -1 || joystickPressCode.xPressed == 2;
789 dValid = false;
790 }
791 }
792 else if (button == 'E')
793 {
794 if (eValid || bypass)
795 {
796 res = joystickPressCode.swPressed;
797 eValid = false;
798 }
799 }
800 return res;
801 }
802
803private:
804 JoystickPressCode joystickPressCode;
805 bool aValid;
806 bool bValid;
807 bool cValid;
808 bool dValid;
809 bool eValid;
810};
811
812
815{
816public:
817 ButtonJoystick(ButtonPressTracker *upTracker, ButtonPressTracker *rightTracker, ButtonPressTracker *downTracker, ButtonPressTracker *leftTracker, ButtonPressTracker *midTracker) : ButtonJoystick(upTracker, rightTracker, downTracker, leftTracker, midTracker, false)
818 {
819 }
820
821protected:
822 ButtonJoystick(ButtonPressTracker *upTracker, ButtonPressTracker *rightTracker, ButtonPressTracker *downTracker, ButtonPressTracker *leftTracker, ButtonPressTracker *midTracker, bool buttonsOnly) : ButtonJoystickBasic(buttonsOnly)
823 {
824 this->leftTracker = leftTracker;
825 this->rightTracker = rightTracker;
826 this->upTracker = upTracker;
827 this->downTracker = downTracker;
828 this->midTracker = midTracker;
829 //this->buttonsOnly = buttonsOnly;
830 }
831
832protected:
833 // virtual int _checkPressedX(int repeat, bool raw)
834 // {
835 // // Serial.print("?");
836 // bool pressedB = _checkPressed('B', repeat);
837 // bool pressedD = _checkPressed('D', repeat);
838 // if (pressedB)
839 // {
840 // // Serial.println("*B");
841 // return raw && pressedD ? 2 : -1;
842 // }
843 // else if (pressedD)
844 // {
845 // // Serial.println("*D");
846 // return 1;
847 // }
848 // else
849 // {
850 // return 0;
851 // }
852 // }
853 // virtual int _checkPressedY(int repeat, bool raw)
854 // {
855 // bool pressedA = _checkPressed('A', repeat);
856 // bool pressedC = _checkPressed('C', repeat);
857 // if (pressedA)
858 // {
859 // // Serial.println("*A");
860 // return raw && pressedC ? 2 : -1;
861 // }
862 // else if (pressedC)
863 // {
864 // // Serial.println("*C");
865 // return 1;
866 // }
867 // else
868 // {
869 // return 0;
870 // }
871 // }
872 virtual bool _checkPressed(char button, int repeat, bool bypass)
873 {
874 if (button == 'A')
875 {
876 bool pressed = upTracker != NULL && upTracker->checkPressed(repeat, bypass);
877//if (pressed && repeat != 0 && !bypass) { Serial.print(repeat); Serial.println(" <A>"); }
878 return pressed;
879 }
880 else if (button == 'B')
881 {
882 return rightTracker != NULL && rightTracker->checkPressed(repeat, bypass);
883 }
884 else if (button == 'C')
885 {
886 return downTracker != NULL && downTracker->checkPressed(repeat, bypass);
887 }
888 else if (button == 'D')
889 {
890 return leftTracker != NULL && leftTracker->checkPressed(repeat, bypass);
891 }
892 else if (button == 'E')
893 {
894 bool pressed = midTracker != NULL && midTracker->checkPressed(repeat, bypass);
895//if (pressed && !bypass) { Serial.print(repeat); Serial.println(" <E>"); }
896 return pressed;
897 }
898 else
899 {
900 return false;
901 }
902 }
903 // virtual bool _checkPressedBypass(char button)
904 // {
905 // if (button == 'A')
906 // {
907 // return upTracker != NULL && upTracker->checkPressedBypass();
908 // }
909 // else if (button == 'B')
910 // {
911 // return rightTracker != NULL && rightTracker->checkPressedBypass();
912 // }
913 // else if (button == 'C')
914 // {
915 // return downTracker != NULL && downTracker->checkPressedBypass();
916 // }
917 // else if (button == 'D')
918 // {
919 // return leftTracker != NULL && leftTracker->checkPressedBypass();
920 // }
921 // else if (button == 'E')
922 // {
923 // return midTracker != NULL && midTracker->checkPressedBypass();
924 // }
925 // else
926 // {
927 // return false;
928 // }
929 // }
930
931private:
932 ButtonPressTracker *leftTracker;
933 ButtonPressTracker *rightTracker;
934 ButtonPressTracker *upTracker;
935 ButtonPressTracker *downTracker;
936 ButtonPressTracker *midTracker;
937 //bool buttonsOnly;
938};
939
942{
943public:
944 ButtonsOnly(ButtonPressTracker *aTracker, ButtonPressTracker *bTracker, ButtonPressTracker *cTracker, ButtonPressTracker *dTracker) : ButtonJoystick(aTracker, bTracker, cTracker, dTracker, NULL, true)
945 {
946 }
947 // public:
948 // inline bool checkButtonAPressed(int repeat) {
949 // return checkButtonPressed('A', repeat);
950 // }
951 // inline bool checkButtonBPressed(int repeat) {
952 // return checkButtonPressed('B', repeat);
953 // }
954 // inline bool checkButtonCPressed(int repeat) {
955 // return checkButtonPressed('C', repeat);
956 // }
957 // inline bool checkButtonDPressed(int repeat) {
958 // return checkButtonPressed('D', repeat);
959 // }
960};
961
962
963JoystickPressTracker *SetupNewJoystickPressTracker(uint8_t pin, bool reverseDir, int autoTuneThreshold = JoystickPressTracker::DefAutoTuneThreshold)
964{
965 pinMode(pin, INPUT);
966 return new JoystickPressTracker(pin, reverseDir, autoTuneThreshold);
967}
968ButtonPressTracker *SetupNewButtonPressTracker(uint8_t pin)
969{
970 pinMode(pin, INPUT_PULLUP);
971 return new ButtonPressTracker(pin);
972}
973
974
975#endif
Helper class for joystick input tracking. See JoystickInterface.
Definition: ddjoystick.h:626
Helper class for joystick input tracking. See JoystickInterface.
Definition: ddjoystick.h:815
Helper class for joystick input tracking. See JoystickInterface.
Definition: ddjoystick.h:200
Helper class for joystick input tracking. See JoystickInterface.
Definition: ddjoystick.h:942
Helper class for joystick input tracking. See JoystickInterface.
Definition: ddjoystick.h:732
Base Helper class for joystick input tracking. For an example use, you may want to refer to Wireless ...
Definition: ddjoystick.h:34
bool _checkPressed(char button, int repeat)
Definition: ddjoystick.h:178
Helper class for joystick input tracking. See JoystickInterface.
Definition: ddjoystick.h:534
Helper class for joystick input tracking. See JoystickInterface.
Definition: ddjoystick.h:299
JoystickPressTracker(uint8_t pin, bool reverseDir, int autoTuneThreshold=DefAutoTuneThreshold)
Definition: ddjoystick.h:315
Struct used by the helper class like JoystickInterface.
Definition: ddjoystick.h:16
Struct used by the helper class like JoystickInterface.
Definition: ddjoystick.h:26
Struct used by the helper class like JoystickInterface.
Definition: ddjoystick.h:9