Input library for the STMstation P.1. Facilitates button state checking and battery voltage checking.
Library to check button states and battery voltage for the STMstation P.1.
See API documentation for detailed information.
STMstation_input.cpp@0:6951d1eef6ad, 2017-06-22 (annotated)
- Committer:
- kkado
- Date:
- Thu Jun 22 09:06:57 2017 +0000
- Revision:
- 0:6951d1eef6ad
- Child:
- 1:8c73c4795f92
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kkado | 0:6951d1eef6ad | 1 | #include "STMstation_input.h" |
kkado | 0:6951d1eef6ad | 2 | #include "mbed.h" |
kkado | 0:6951d1eef6ad | 3 | |
kkado | 0:6951d1eef6ad | 4 | STMstation_input::STMstation_input(): D_UP(UP_PIN), D_DOWN(DOWN_PIN), D_LEFT(LEFT_PIN), D_RIGHT(RIGHT_PIN), |
kkado | 0:6951d1eef6ad | 5 | D_A(A_PIN), D_B(B_PIN), D_X(X_PIN), D_Y(Y_PIN), |
kkado | 0:6951d1eef6ad | 6 | D_START(START_PIN), D_SELECT(SELECT_PIN) |
kkado | 0:6951d1eef6ad | 7 | { |
kkado | 0:6951d1eef6ad | 8 | } |
kkado | 0:6951d1eef6ad | 9 | |
kkado | 0:6951d1eef6ad | 10 | void STMstation_input::updateButtons(){ |
kkado | 0:6951d1eef6ad | 11 | bool oldState[10]; |
kkado | 0:6951d1eef6ad | 12 | |
kkado | 0:6951d1eef6ad | 13 | for(int i=0; i<10; i++){ |
kkado | 0:6951d1eef6ad | 14 | oldState[i] = buttonPress[i]; |
kkado | 0:6951d1eef6ad | 15 | } |
kkado | 0:6951d1eef6ad | 16 | buttonPress[0] = D_UP; |
kkado | 0:6951d1eef6ad | 17 | buttonPress[1] = D_DOWN; |
kkado | 0:6951d1eef6ad | 18 | buttonPress[2] = D_LEFT; |
kkado | 0:6951d1eef6ad | 19 | buttonPress[3] = D_RIGHT; |
kkado | 0:6951d1eef6ad | 20 | buttonPress[4] = D_A; |
kkado | 0:6951d1eef6ad | 21 | buttonPress[5] = D_B; |
kkado | 0:6951d1eef6ad | 22 | buttonPress[6] = D_X; |
kkado | 0:6951d1eef6ad | 23 | buttonPress[7] = D_Y; |
kkado | 0:6951d1eef6ad | 24 | buttonPress[8] = D_START; |
kkado | 0:6951d1eef6ad | 25 | buttonPress[9] = D_SELECT; |
kkado | 0:6951d1eef6ad | 26 | for(int i=0; i<10; i++){ |
kkado | 0:6951d1eef6ad | 27 | if(oldState[i] == 0 & buttonPress[i] == 1){ |
kkado | 0:6951d1eef6ad | 28 | buttonDown[i] = 1; |
kkado | 0:6951d1eef6ad | 29 | buttonUp[i] = 0; |
kkado | 0:6951d1eef6ad | 30 | } |
kkado | 0:6951d1eef6ad | 31 | else if(oldState[i] == 1 & buttonPress[i] == 0){ |
kkado | 0:6951d1eef6ad | 32 | buttonDown[i] = 0; |
kkado | 0:6951d1eef6ad | 33 | buttonUp[i] = 1; |
kkado | 0:6951d1eef6ad | 34 | } |
kkado | 0:6951d1eef6ad | 35 | else{ |
kkado | 0:6951d1eef6ad | 36 | buttonDown[i] = 0; |
kkado | 0:6951d1eef6ad | 37 | buttonUp[i] = 0; |
kkado | 0:6951d1eef6ad | 38 | } |
kkado | 0:6951d1eef6ad | 39 | } |
kkado | 0:6951d1eef6ad | 40 | } |
kkado | 0:6951d1eef6ad | 41 | |
kkado | 0:6951d1eef6ad | 42 | bool STMstation_input::keyDown(Button b){ |
kkado | 0:6951d1eef6ad | 43 | if(buttonDown[b] == 0){ |
kkado | 0:6951d1eef6ad | 44 | return 0; |
kkado | 0:6951d1eef6ad | 45 | } |
kkado | 0:6951d1eef6ad | 46 | else{ |
kkado | 0:6951d1eef6ad | 47 | return 1; |
kkado | 0:6951d1eef6ad | 48 | } |
kkado | 0:6951d1eef6ad | 49 | } |
kkado | 0:6951d1eef6ad | 50 | |
kkado | 0:6951d1eef6ad | 51 | bool STMstation_input::keyUp(Button b){ |
kkado | 0:6951d1eef6ad | 52 | if(buttonUp[b] == 0){ |
kkado | 0:6951d1eef6ad | 53 | return 0; |
kkado | 0:6951d1eef6ad | 54 | } |
kkado | 0:6951d1eef6ad | 55 | else{ |
kkado | 0:6951d1eef6ad | 56 | return 1; |
kkado | 0:6951d1eef6ad | 57 | } |
kkado | 0:6951d1eef6ad | 58 | } |
kkado | 0:6951d1eef6ad | 59 | |
kkado | 0:6951d1eef6ad | 60 | bool STMstation_input::keyPress(Button b){ |
kkado | 0:6951d1eef6ad | 61 | if(buttonPress[b] == 0){ |
kkado | 0:6951d1eef6ad | 62 | return 0; |
kkado | 0:6951d1eef6ad | 63 | } |
kkado | 0:6951d1eef6ad | 64 | else{ |
kkado | 0:6951d1eef6ad | 65 | return 1; |
kkado | 0:6951d1eef6ad | 66 | } |
kkado | 0:6951d1eef6ad | 67 | } |