Digital Joystick
Embed:
(wiki syntax)
Show/hide line numbers
Joystick.h
00001 //remove repetition 00002 #ifndef MBED_JOYSTICK_H 00003 #define MBED_JOYSTICK_H 00004 00005 //required to use mbed functions 00006 #include "mbed.h" 00007 #include "FunctionPointer.h" 00008 00009 #define JOYSTICK_NONE 0x00 00010 #define JOYSTICK_UP 0x01 00011 #define JOYSTICK_DOWN 0x02 00012 #define JOYSTICK_LEFT 0x04 00013 #define JOYSTICK_RIGHT 0x08 00014 #define JOYSTICK_PRESS 0x10 00015 00016 /** Digital Joystick class 00017 * 00018 * Used for an digital joystick. 00019 * 00020 * Example: 00021 * @code 00022 * #include "mbed.h" 00023 * #include "Joystick.h" 00024 * 00025 * Joystick joystick(P2_3, P0_15, P2_4, P0_16, P0_17); 00026 * 00027 * int main() { 00028 * joystick.getStatus(); 00029 * } 00030 * 00031 * @endcode 00032 */ 00033 00034 class Joystick { 00035 public: 00036 typedef enum { 00037 none = JOYSTICK_NONE, 00038 up = JOYSTICK_UP, 00039 down = JOYSTICK_DOWN, 00040 left = JOYSTICK_LEFT, 00041 right = JOYSTICK_RIGHT, 00042 press = JOYSTICK_PRESS 00043 } Status; 00044 00045 /** Create a Joystick HID for using regular mbed pins 00046 * 00047 * @param up Joystick Up 00048 * @param down Joystick Down 00049 * @param left Joystick Left 00050 * @param right Joystick Right 00051 * @param press Joystick Press 00052 */ 00053 Joystick(PinName up, PinName down, PinName left, PinName right, PinName press); 00054 00055 void functions(FunctionPointer *functionNone, FunctionPointer *functionUp, FunctionPointer *functionDown, 00056 FunctionPointer *functionLeft, FunctionPointer *functionRight, FunctionPointer *functionPress); 00057 00058 /** Get status 00059 * Read the joystick status 00060 * 00061 * @code 00062 * switch (joystick.getStatus()) { 00063 * case Joystick::none: 00064 * break; 00065 * case Joystick::up: 00066 * break; 00067 * case Joystick::down: 00068 * break; 00069 * case Joystick::left: 00070 * break; 00071 * case Joystick::right: 00072 * break; 00073 * case Joystick::press: 00074 * break; 00075 * default: 00076 * break; 00077 * } 00078 * @endcode 00079 * 00080 * @returns A uint8_t values representing the bits 00081 */ 00082 Status getStatus(); 00083 00084 void poll(); 00085 00086 private: 00087 00088 /** Regular mbed pins bus 00089 */ 00090 DigitalIn _up, _down, _left, _right, _press; 00091 00092 FunctionPointer *_functionNone, *_functionUp, *_functionDown, *_functionLeft, *_functionRight, *_functionPress; 00093 }; 00094 00095 #endif
Generated on Wed Jul 13 2022 17:58:21 by
1.7.2