Digital Joystick
Embed:
(wiki syntax)
Show/hide line numbers
Joystick.cpp
00001 #include "Joystick.h" 00002 00003 /** Create a Joystick HID for using regular mbed pins 00004 * 00005 * @param up Joystick Up 00006 * @param down Joystick Down 00007 * @param left Joystick Left 00008 * @param right Joystick Right 00009 * @param press Joystick Press 00010 */ 00011 Joystick::Joystick(PinName up, PinName down, PinName left, PinName right, PinName press) : 00012 _up(up), _down(down), _left(left), _right(right), _press(press) { 00013 00014 } 00015 00016 void Joystick::functions(FunctionPointer *functionNone, FunctionPointer *functionUp, FunctionPointer *functionDown, 00017 FunctionPointer *functionLeft, FunctionPointer *functionRight, FunctionPointer *functionPress) { 00018 _functionNone = functionNone; 00019 _functionUp = functionUp; 00020 _functionDown = functionDown; 00021 _functionLeft = functionLeft; 00022 _functionRight = functionRight; 00023 _functionPress = functionPress; 00024 } 00025 00026 /** Get status 00027 * Read the joystick status 00028 * 00029 * @returns Status of joystick 00030 */ 00031 Joystick::Status Joystick::getStatus() { 00032 if (!_up) { 00033 return up; 00034 } 00035 if (!_down) { 00036 return down; 00037 } 00038 if (!_left) { 00039 return left; 00040 } 00041 if (!_right) { 00042 return right; 00043 } 00044 if (!_press) { 00045 return press; 00046 } 00047 return none; 00048 } 00049 00050 void Joystick::poll() { 00051 switch (getStatus()) { 00052 case none: 00053 _functionNone->call(); 00054 break; 00055 case up: 00056 _functionUp->call(); 00057 break; 00058 case down: 00059 _functionDown->call(); 00060 break; 00061 case left: 00062 _functionLeft->call(); 00063 break; 00064 case right: 00065 _functionRight->call(); 00066 break; 00067 case press: 00068 _functionPress->call(); 00069 break; 00070 default: 00071 break; 00072 } 00073 }
Generated on Wed Jul 13 2022 17:58:21 by
1.7.2