Witek Ewert
/
frdmk22f-usbhid-4axis
4-axis USB controller for FPV sims, based on NXP FRDM-K22F
USBJoystick/USBJoystick.h@0:9f5a70453c7c, 2020-03-05 (annotated)
- Committer:
- wue
- Date:
- Thu Mar 05 20:57:25 2020 +0000
- Revision:
- 0:9f5a70453c7c
???
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wue | 0:9f5a70453c7c | 1 | /* mbed USBJoystick Library |
wue | 0:9f5a70453c7c | 2 | * Copyright (c) 2012, v01: Initial version, WH, |
wue | 0:9f5a70453c7c | 3 | * Modified USBMouse code ARM Limited. |
wue | 0:9f5a70453c7c | 4 | * (c) 2010-2011 mbed.org, MIT License |
wue | 0:9f5a70453c7c | 5 | * 2016, v02: Updated USBDevice Lib, Added waitForConnect, Updated 32 bits button |
wue | 0:9f5a70453c7c | 6 | * |
wue | 0:9f5a70453c7c | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wue | 0:9f5a70453c7c | 8 | * of this software and associated documentation files (the "Software"), to deal |
wue | 0:9f5a70453c7c | 9 | * in the Software without restriction, inclumosig without limitation the rights |
wue | 0:9f5a70453c7c | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wue | 0:9f5a70453c7c | 11 | * copies of the Software, and to permit persons to whom the Software is |
wue | 0:9f5a70453c7c | 12 | * furnished to do so, subject to the following conditions: |
wue | 0:9f5a70453c7c | 13 | * |
wue | 0:9f5a70453c7c | 14 | * The above copyright notice and this permission notice shall be included in |
wue | 0:9f5a70453c7c | 15 | * all copies or substantial portions of the Software. |
wue | 0:9f5a70453c7c | 16 | * |
wue | 0:9f5a70453c7c | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wue | 0:9f5a70453c7c | 18 | * IMPLIED, INCLUmosiG BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wue | 0:9f5a70453c7c | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wue | 0:9f5a70453c7c | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wue | 0:9f5a70453c7c | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wue | 0:9f5a70453c7c | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wue | 0:9f5a70453c7c | 23 | * THE SOFTWARE. |
wue | 0:9f5a70453c7c | 24 | */ |
wue | 0:9f5a70453c7c | 25 | |
wue | 0:9f5a70453c7c | 26 | #ifndef USBJOYSTICK_H |
wue | 0:9f5a70453c7c | 27 | #define USBJOYSTICK_H |
wue | 0:9f5a70453c7c | 28 | |
wue | 0:9f5a70453c7c | 29 | #include "USBHID.h" |
wue | 0:9f5a70453c7c | 30 | |
wue | 0:9f5a70453c7c | 31 | #define REPORT_ID_JOYSTICK 4 |
wue | 0:9f5a70453c7c | 32 | |
wue | 0:9f5a70453c7c | 33 | |
wue | 0:9f5a70453c7c | 34 | |
wue | 0:9f5a70453c7c | 35 | /* X, Y and T limits */ |
wue | 0:9f5a70453c7c | 36 | /* These values do not directly map to screen pixels */ |
wue | 0:9f5a70453c7c | 37 | /* Zero may be interpreted as meaning 'no movement' */ |
wue | 0:9f5a70453c7c | 38 | #define JX_MIN_ABS (-32768) /*!< The maximum value that we can move to the left on the x-axis */ |
wue | 0:9f5a70453c7c | 39 | #define JY_MIN_ABS (-32768) /*!< The maximum value that we can move up on the y-axis */ |
wue | 0:9f5a70453c7c | 40 | #define JT_MIN_ABS (-32768) /*!< The minimum value for the throttle */ |
wue | 0:9f5a70453c7c | 41 | #define JX_MAX_ABS (32767) /*!< The maximum value that we can move to the right on the x-axis */ |
wue | 0:9f5a70453c7c | 42 | #define JY_MAX_ABS (32767) /*!< The maximum value that we can move down on the y-axis */ |
wue | 0:9f5a70453c7c | 43 | #define JT_MAX_ABS (32767) /*!< The maximum value for the throttle */ |
wue | 0:9f5a70453c7c | 44 | |
wue | 0:9f5a70453c7c | 45 | class USBJoystick: public USBHID { |
wue | 0:9f5a70453c7c | 46 | public: |
wue | 0:9f5a70453c7c | 47 | |
wue | 0:9f5a70453c7c | 48 | /** |
wue | 0:9f5a70453c7c | 49 | * Constructor |
wue | 0:9f5a70453c7c | 50 | * |
wue | 0:9f5a70453c7c | 51 | * @param vendor_id Your vendor_id (default: 0x1234) |
wue | 0:9f5a70453c7c | 52 | * @param product_id Your product_id (default: 0x0002) |
wue | 0:9f5a70453c7c | 53 | * @param product_release Your product_release (default: 0x0001) |
wue | 0:9f5a70453c7c | 54 | */ |
wue | 0:9f5a70453c7c | 55 | // USBJoystick(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0100, uint16_t product_release = 0x0001, int waitForConnect = true): // 4 buttons, no padding on buttons |
wue | 0:9f5a70453c7c | 56 | // USBJoystick(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0500, uint16_t product_release = 0x0001, int waitForConnect = true): // 8 buttons, no padding on buttons |
wue | 0:9f5a70453c7c | 57 | USBJoystick(uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0702, uint16_t product_release = 0x0001, int waitForConnect = true): // 32 buttons, no padding on buttons |
wue | 0:9f5a70453c7c | 58 | USBHID(0, 0, vendor_id, product_id, product_release, false) { |
wue | 0:9f5a70453c7c | 59 | _init(); |
wue | 0:9f5a70453c7c | 60 | connect(waitForConnect); |
wue | 0:9f5a70453c7c | 61 | }; |
wue | 0:9f5a70453c7c | 62 | |
wue | 0:9f5a70453c7c | 63 | /** |
wue | 0:9f5a70453c7c | 64 | * Write state of the joystick |
wue | 0:9f5a70453c7c | 65 | * |
wue | 0:9f5a70453c7c | 66 | * @param t throttle position |
wue | 0:9f5a70453c7c | 67 | * @param r rudder position |
wue | 0:9f5a70453c7c | 68 | * @param x x-axis position |
wue | 0:9f5a70453c7c | 69 | * @param y y-axis position |
wue | 0:9f5a70453c7c | 70 | * @param buttons buttons state |
wue | 0:9f5a70453c7c | 71 | * @param hat hat state 0 (up), 1 (right, 2 (down), 3 (left) or 4 (neutral) |
wue | 0:9f5a70453c7c | 72 | * @returns true if there is no error, false otherwise |
wue | 0:9f5a70453c7c | 73 | */ |
wue | 0:9f5a70453c7c | 74 | bool update(int16_t x, int16_t y, int16_t rx, int16_t ry); |
wue | 0:9f5a70453c7c | 75 | |
wue | 0:9f5a70453c7c | 76 | /** |
wue | 0:9f5a70453c7c | 77 | * Write state of the joystick |
wue | 0:9f5a70453c7c | 78 | * |
wue | 0:9f5a70453c7c | 79 | * @returns true if there is no error, false otherwise |
wue | 0:9f5a70453c7c | 80 | */ |
wue | 0:9f5a70453c7c | 81 | bool update(); |
wue | 0:9f5a70453c7c | 82 | |
wue | 0:9f5a70453c7c | 83 | /** |
wue | 0:9f5a70453c7c | 84 | * Move the cursor to (x, y) |
wue | 0:9f5a70453c7c | 85 | * |
wue | 0:9f5a70453c7c | 86 | * @param x-axis position |
wue | 0:9f5a70453c7c | 87 | * @param y-axis position |
wue | 0:9f5a70453c7c | 88 | * @returns true if there is no error, false otherwise |
wue | 0:9f5a70453c7c | 89 | */ |
wue | 0:9f5a70453c7c | 90 | bool move(int16_t x, int16_t y, int16_t rx, int16_t ry); |
wue | 0:9f5a70453c7c | 91 | |
wue | 0:9f5a70453c7c | 92 | |
wue | 0:9f5a70453c7c | 93 | virtual uint8_t * reportDesc(); |
wue | 0:9f5a70453c7c | 94 | |
wue | 0:9f5a70453c7c | 95 | private: |
wue | 0:9f5a70453c7c | 96 | int16_t _x; |
wue | 0:9f5a70453c7c | 97 | int16_t _y; |
wue | 0:9f5a70453c7c | 98 | int16_t _rx; |
wue | 0:9f5a70453c7c | 99 | int16_t _ry; |
wue | 0:9f5a70453c7c | 100 | |
wue | 0:9f5a70453c7c | 101 | void _init(); |
wue | 0:9f5a70453c7c | 102 | }; |
wue | 0:9f5a70453c7c | 103 | |
wue | 0:9f5a70453c7c | 104 | #endif |