|
| 1 | +#include <M5Core2.h> |
| 2 | +#include "Goals.h" |
| 3 | + |
| 4 | +extern Button A; |
| 5 | +extern Button B; |
| 6 | + |
| 7 | +Goal::Goal() { name = ""; success = false; } |
| 8 | +bool Goal::passed() { return success; } |
| 9 | +const char* Goal::getName(){ return name.c_str(); } |
| 10 | +bool Goal::test() { |
| 11 | + M5.Lcd.fillRect(0, TEXT_TOP, 320, TEXT_HEIGHT, NAVY); |
| 12 | + M5.Lcd.drawCentreString(name, TEXT_CENTER, TEXT_TOP, TEXT_FONT); |
| 13 | + start_time = millis(); |
| 14 | + while(start_time + TEST_DURRATION > millis()) { |
| 15 | + M5.update(); |
| 16 | + delay(1); |
| 17 | + if(success) { |
| 18 | + return true; |
| 19 | + } |
| 20 | + } |
| 21 | + return false; |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +// Tap the A button |
| 26 | +// |
| 27 | +TapAGoal::TapAGoal() { name = "Tap the A Button"; } |
| 28 | +// Set success to true if all the conditions of the goal are met |
| 29 | +void TapAGoal::event_handler(Event& e) { |
| 30 | + if((E_TAP == e) && (0 == strcmp("A", e.button->name()))) success = true; |
| 31 | +} |
| 32 | + |
| 33 | + |
| 34 | +// Tap the B button |
| 35 | +// |
| 36 | +TapBGoal::TapBGoal() { name = "Tap the B Button"; } |
| 37 | +void TapBGoal::event_handler(Event& e) { |
| 38 | + if((E_TAP == e) && (0 == strcmp("B", e.button->name()))) success = true; |
| 39 | +} |
| 40 | + |
| 41 | +// Long Press (LONG_PRESS_TIME mS) on the A Button |
| 42 | +// |
| 43 | +LongPressAGoal::LongPressAGoal() { name = "Long Press the A Button"; } |
| 44 | +void LongPressAGoal::event_handler(Event& e) { |
| 45 | + if((E_LONGPRESSED == e) && (0 == strcmp("A", e.button->name()))) success = true; |
| 46 | +} |
| 47 | + |
| 48 | + |
| 49 | +// Long Press (LONG_PRESS_TIME mS) on the B Button |
| 50 | +// |
| 51 | +LongPressBGoal::LongPressBGoal() { name = "Long Press the B Button"; } |
| 52 | +void LongPressBGoal::event_handler(Event& e) { |
| 53 | + if((E_LONGPRESSED == e) && (0 == strcmp("B", e.button->name()))) success = true; |
| 54 | +} |
| 55 | + |
| 56 | + |
| 57 | +// Long Press (LONG_PRESS_TIME mS) on the Background |
| 58 | +// |
| 59 | +LongPressBackgroundGoal::LongPressBackgroundGoal() { name = "Long Press the Background"; } |
| 60 | +void LongPressBackgroundGoal::event_handler(Event& e) { |
| 61 | + if((E_LONGPRESSED == e) && (0 == strcmp("background", e.button->name()))) success = true; |
| 62 | +} |
| 63 | + |
| 64 | + |
| 65 | +// Double Tap the A button |
| 66 | +// |
| 67 | +DoubleTapAGoal::DoubleTapAGoal() { name = "Double Tap the A Button"; } |
| 68 | +// Set success to true if all the conditions of the goal are met |
| 69 | +void DoubleTapAGoal::event_handler(Event& e) { |
| 70 | + if((E_DBLTAP == e) && (0 == strcmp("A", e.button->name()))) success = true; |
| 71 | +} |
| 72 | + |
| 73 | + |
| 74 | +// Double Tap the B button |
| 75 | +// |
| 76 | +DoubleTapBGoal::DoubleTapBGoal() { name = "Double Tap the B Button"; } |
| 77 | +void DoubleTapBGoal::event_handler(Event& e) { |
| 78 | + if((E_DBLTAP == e) && (0 == strcmp("B", e.button->name()))) success = true; |
| 79 | +} |
| 80 | + |
| 81 | + |
| 82 | +// Tap the Background |
| 83 | +// |
| 84 | +TapBackgroundGoal::TapBackgroundGoal() { name = "Tap the Background"; } |
| 85 | +// Set success to true if all the conditions of the goal are met |
| 86 | +void TapBackgroundGoal::event_handler(Event& e) { |
| 87 | + if((E_TAP == e) && (0 == strcmp("background", e.button->name()))) success = true; |
| 88 | +} |
| 89 | + |
| 90 | + |
| 91 | +// Double Tap the Background |
| 92 | +// |
| 93 | +DoubleTapBackgroundGoal::DoubleTapBackgroundGoal() { name = "Double Tap the Background"; } |
| 94 | +void DoubleTapBackgroundGoal::event_handler(Event& e) { |
| 95 | + if((E_DBLTAP == e) && (0 == strcmp("background", e.button->name()))) success = true; |
| 96 | +} |
| 97 | + |
| 98 | + |
| 99 | +// Drag from A to B |
| 100 | +// |
| 101 | +DragFromAtoBGoal::DragFromAtoBGoal() { name = "Drag From A to B"; } |
| 102 | +// The series of events I see is: E_TOUCH(A), E_MOVE(A)..., E_PRESSING(a), E_MOVE(A)..., E_RELEASE(A), E_DRAGGED(A) |
| 103 | +// Button never reflects another object; get position and test location. |
| 104 | +void DragFromAtoBGoal::event_handler(Event& e) { |
| 105 | + if(E_DRAGGED == e) { |
| 106 | + if(A.contains(e.from) && B.contains(e.to)) success = true; |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | + |
| 111 | +// Drag from B to A |
| 112 | +// |
| 113 | +DragFromBtoAGoal::DragFromBtoAGoal() { name = "Drag From B to A"; } |
| 114 | +void DragFromBtoAGoal::event_handler(Event& e) { |
| 115 | + if(E_DRAGGED == e) { |
| 116 | + if(B.contains(e.from) && A.contains(e.to)) success = true; |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | + |
| 121 | +// Drag from A to Background |
| 122 | +// |
| 123 | +DragFromAtoBackgroundGoal::DragFromAtoBackgroundGoal() { name = "Drag From A to Background"; } |
| 124 | +void DragFromAtoBackgroundGoal::event_handler(Event& e) { |
| 125 | + if(E_DRAGGED == e) { |
| 126 | + if(A.contains(e.from) && M5.background.contains(e.to) && !A.contains(e.to) && !B.contains(e.to)) success = true; |
| 127 | + } |
| 128 | +} |
| 129 | + |
| 130 | + |
| 131 | +// Drag from B to Background |
| 132 | +// |
| 133 | +DragFromBtoBackgroundGoal::DragFromBtoBackgroundGoal() { name = "Drag From B to Background"; } |
| 134 | +void DragFromBtoBackgroundGoal::event_handler(Event& e) { |
| 135 | + if(E_DRAGGED == e) { |
| 136 | + if(B.contains(e.from) && M5.background.contains(e.to) && !A.contains(e.to) && !B.contains(e.to)) success = true; |
| 137 | + } |
| 138 | +} |
| 139 | + |
| 140 | + |
| 141 | +// Drag from Background to A |
| 142 | +// |
| 143 | +DragFromBackgroundtoAGoal::DragFromBackgroundtoAGoal() { |
| 144 | + name = "Drag From Background to A"; |
| 145 | + can_succeed = true; |
| 146 | +} |
| 147 | +// You don't get an E_DRAGGED event if you start in the background, so return an error if one comes in. |
| 148 | +void DragFromBackgroundtoAGoal::event_handler(Event& e) { |
| 149 | + if(E_DRAGGED == e) can_succeed = false; |
| 150 | + if(E_RELEASE == e) { |
| 151 | + if(M5.background.contains(e.from) && !A.contains(e.from) && !B.contains(e.from) && A.contains(e.to)) success = can_succeed; |
| 152 | + } |
| 153 | +} |
| 154 | + |
| 155 | + |
| 156 | +// Drag from Background to B |
| 157 | +// |
| 158 | +DragFromBackgroundtoBGoal::DragFromBackgroundtoBGoal() { |
| 159 | + name = "Drag From Background to B"; |
| 160 | + can_succeed = true; |
| 161 | +} |
| 162 | +// You don't get an E_DRAGGED event if you start in the background, so return an error if one comes in. |
| 163 | +void DragFromBackgroundtoBGoal::event_handler(Event& e) { |
| 164 | + if(E_DRAGGED == e) can_succeed = false; |
| 165 | + if(E_RELEASE == e) { |
| 166 | + if(M5.background.contains(e.from) && !A.contains(e.from) && !B.contains(e.from) && B.contains(e.to)) success = can_succeed; |
| 167 | + } |
| 168 | +} |
| 169 | + |
| 170 | + |
| 171 | +// Swipe up detection |
| 172 | +// |
| 173 | +SwipeUpGoal::SwipeUpGoal() { name = "Swipe Up"; } |
| 174 | +void SwipeUpGoal::event_handler(Event& e) { |
| 175 | + if((E_GESTURE == e) && (0 == strcmp("swipe up", e.gesture->name()))) success = true; |
| 176 | +} |
| 177 | + |
| 178 | +// Swipe down detection |
| 179 | +// |
| 180 | +SwipeDownGoal::SwipeDownGoal() { name = "Swipe Down"; } |
| 181 | +void SwipeDownGoal::event_handler(Event& e) { |
| 182 | + if((E_GESTURE == e) && (0 == strcmp("swipe down", e.gesture->name()))) success = true; |
| 183 | +} |
| 184 | + |
| 185 | +// Swipe left detection |
| 186 | +// |
| 187 | +SwipeLeftGoal::SwipeLeftGoal() { name = "Swipe Left"; } |
| 188 | +void SwipeLeftGoal::event_handler(Event& e) { |
| 189 | + if((E_GESTURE == e) && (0 == strcmp("swipe left", e.gesture->name()))) success = true; |
| 190 | +} |
| 191 | + |
| 192 | +// Swipe right detection |
| 193 | +// |
| 194 | +SwipeRightGoal::SwipeRightGoal() { name = "Swipe Right"; } |
| 195 | +void SwipeRightGoal::event_handler(Event& e) { |
| 196 | + if((E_GESTURE == e) && (0 == strcmp("swipe right", e.gesture->name()))) success = true; |
| 197 | +} |
0 commit comments