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