Code for the space evader game.
Dependencies: N5110 PowerControl mbed
joystick.h@0:dd6685f1343e, 2015-05-10 (annotated)
- Committer:
- domplatypus
- Date:
- Sun May 10 16:48:46 2015 +0000
- Revision:
- 0:dd6685f1343e
- Child:
- 1:225522d0dd77
version 1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
domplatypus | 0:dd6685f1343e | 1 | /** |
domplatypus | 0:dd6685f1343e | 2 | @file joystick.h |
domplatypus | 0:dd6685f1343e | 3 | @brief Header file containing functions prototypes, defines and global variables. |
domplatypus | 0:dd6685f1343e | 4 | @brief Joystick header file, with modification from original file |
domplatypus | 0:dd6685f1343e | 5 | @brief CHANGEME_H_ and endif added to prevent header file error https://developer.mbed.org/cookbook/Compiler-Error-256 |
domplatypus | 0:dd6685f1343e | 6 | @author Craig A. Evans (Original author) |
domplatypus | 0:dd6685f1343e | 7 | @author Dominic J. Platt (Modifications labelled) |
domplatypus | 0:dd6685f1343e | 8 | @date April 2015 |
domplatypus | 0:dd6685f1343e | 9 | */ |
domplatypus | 0:dd6685f1343e | 10 | #ifndef CHANGEME_H_ |
domplatypus | 0:dd6685f1343e | 11 | #define CHANGEME_H_ |
domplatypus | 0:dd6685f1343e | 12 | #include "mbed.h" |
domplatypus | 0:dd6685f1343e | 13 | |
domplatypus | 0:dd6685f1343e | 14 | #define DIRECTION_TOLERANCE 0.05 |
domplatypus | 0:dd6685f1343e | 15 | |
domplatypus | 0:dd6685f1343e | 16 | /** |
domplatypus | 0:dd6685f1343e | 17 | @namespace joystickButton |
domplatypus | 0:dd6685f1343e | 18 | @brief joystick button output when user presses joystick |
domplatypus | 0:dd6685f1343e | 19 | */ |
domplatypus | 0:dd6685f1343e | 20 | extern InterruptIn joystickButton; |
domplatypus | 0:dd6685f1343e | 21 | |
domplatypus | 0:dd6685f1343e | 22 | /** |
domplatypus | 0:dd6685f1343e | 23 | @namespace serial |
domplatypus | 0:dd6685f1343e | 24 | @brief serial used for code debug checking with coolterm software |
domplatypus | 0:dd6685f1343e | 25 | */ |
domplatypus | 0:dd6685f1343e | 26 | extern Serial serial; |
domplatypus | 0:dd6685f1343e | 27 | |
domplatypus | 0:dd6685f1343e | 28 | /** |
domplatypus | 0:dd6685f1343e | 29 | @namespace pollJoystick |
domplatypus | 0:dd6685f1343e | 30 | @brief Ticker type variable to set how often the joystick is read |
domplatypus | 0:dd6685f1343e | 31 | */ |
domplatypus | 0:dd6685f1343e | 32 | extern Ticker pollJoystick; |
domplatypus | 0:dd6685f1343e | 33 | |
domplatypus | 0:dd6685f1343e | 34 | typedef struct JoyStick Joystick; |
domplatypus | 0:dd6685f1343e | 35 | |
domplatypus | 0:dd6685f1343e | 36 | /** |
domplatypus | 0:dd6685f1343e | 37 | Used to define to hold the properties of our joystick |
domplatypus | 0:dd6685f1343e | 38 | */ |
domplatypus | 0:dd6685f1343e | 39 | struct JoyStick { |
domplatypus | 0:dd6685f1343e | 40 | /** |
domplatypus | 0:dd6685f1343e | 41 | * the x coordinate */ |
domplatypus | 0:dd6685f1343e | 42 | float x; |
domplatypus | 0:dd6685f1343e | 43 | //! 'centred' x value |
domplatypus | 0:dd6685f1343e | 44 | float x0; |
domplatypus | 0:dd6685f1343e | 45 | //! current y value |
domplatypus | 0:dd6685f1343e | 46 | /*! |
domplatypus | 0:dd6685f1343e | 47 | read from y direction potentiometer |
domplatypus | 0:dd6685f1343e | 48 | */ |
domplatypus | 0:dd6685f1343e | 49 | float y; |
domplatypus | 0:dd6685f1343e | 50 | //! 'centred' y value |
domplatypus | 0:dd6685f1343e | 51 | float y0; |
domplatypus | 0:dd6685f1343e | 52 | //! button state |
domplatypus | 0:dd6685f1343e | 53 | /*! |
domplatypus | 0:dd6685f1343e | 54 | (assume pull-down used, so 1 = pressed, 0 = unpressed) |
domplatypus | 0:dd6685f1343e | 55 | */ |
domplatypus | 0:dd6685f1343e | 56 | int button; // button state |
domplatypus | 0:dd6685f1343e | 57 | //! direction in two dimensions |
domplatypus | 0:dd6685f1343e | 58 | /*! |
domplatypus | 0:dd6685f1343e | 59 | values of 1,0,-1 for each element |
domplatypus | 0:dd6685f1343e | 60 | e.g. the matrix of {-1,0} will mean direction is -1 in x directions and 0 in the y direction |
domplatypus | 0:dd6685f1343e | 61 | */ |
domplatypus | 0:dd6685f1343e | 62 | int direction[2]; // current direction x,y used |
domplatypus | 0:dd6685f1343e | 63 | /*@}*/ |
domplatypus | 0:dd6685f1343e | 64 | }; |
domplatypus | 0:dd6685f1343e | 65 | /** |
domplatypus | 0:dd6685f1343e | 66 | @brief create joystick instance |
domplatypus | 0:dd6685f1343e | 67 | */ |
domplatypus | 0:dd6685f1343e | 68 | extern Joystick joystick; |
domplatypus | 0:dd6685f1343e | 69 | |
domplatypus | 0:dd6685f1343e | 70 | /** |
domplatypus | 0:dd6685f1343e | 71 | @brief calibrating joystick, joystick must not move during this |
domplatypus | 0:dd6685f1343e | 72 | */ |
domplatypus | 0:dd6685f1343e | 73 | void calibrateJoystick(); |
domplatypus | 0:dd6685f1343e | 74 | /** |
domplatypus | 0:dd6685f1343e | 75 | @brief read current joystick values relative to calibrated values |
domplatypus | 0:dd6685f1343e | 76 | */ |
domplatypus | 0:dd6685f1343e | 77 | void updateJoystick(); |
domplatypus | 0:dd6685f1343e | 78 | //! printFlag used to print the joystick directions for bebugging |
domplatypus | 0:dd6685f1343e | 79 | extern int printFlag; |
domplatypus | 0:dd6685f1343e | 80 | |
domplatypus | 0:dd6685f1343e | 81 | #endif |