work in progress

Dependencies:   FastAnalogIn FastIO USBDevice mbed FastPWM SimpleDMA

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Wed Aug 06 23:08:07 2014 +0000
Revision:
6:cc35eb643e8f
Parent:
5:a70c0bce770d
Child:
9:fd65b0a94720
Various testing setups for plunger firing - debouncing, fixed returns, etc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 3:3514575d4f86 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
mjr 3:3514575d4f86 2 * Modified Mouse code for Joystick - WH 2012
mjr 3:3514575d4f86 3 *
mjr 3:3514575d4f86 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mjr 3:3514575d4f86 5 * and associated documentation files (the "Software"), to deal in the Software without
mjr 3:3514575d4f86 6 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mjr 3:3514575d4f86 7 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mjr 3:3514575d4f86 8 * Software is furnished to do so, subject to the following conditions:
mjr 3:3514575d4f86 9 *
mjr 3:3514575d4f86 10 * The above copyright notice and this permission notice shall be included in all copies or
mjr 3:3514575d4f86 11 * substantial portions of the Software.
mjr 3:3514575d4f86 12 *
mjr 3:3514575d4f86 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mjr 3:3514575d4f86 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mjr 3:3514575d4f86 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mjr 3:3514575d4f86 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mjr 3:3514575d4f86 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mjr 3:3514575d4f86 18 */
mjr 3:3514575d4f86 19
mjr 3:3514575d4f86 20 #include "stdint.h"
mjr 3:3514575d4f86 21 #include "USBJoystick.h"
mjr 3:3514575d4f86 22
mjr 3:3514575d4f86 23 bool USBJoystick::update(int16_t x, int16_t y, int16_t z, int16_t rx, int16_t ry, uint16_t buttons)
mjr 3:3514575d4f86 24 {
mjr 3:3514575d4f86 25 _x = x;
mjr 3:3514575d4f86 26 _y = y;
mjr 3:3514575d4f86 27 _z = z;
mjr 3:3514575d4f86 28 _rx = rx;
mjr 3:3514575d4f86 29 _ry = ry;
mjr 3:3514575d4f86 30 _buttons = buttons;
mjr 3:3514575d4f86 31
mjr 3:3514575d4f86 32 // send the report
mjr 3:3514575d4f86 33 return update();
mjr 3:3514575d4f86 34 }
mjr 3:3514575d4f86 35
mjr 3:3514575d4f86 36 bool USBJoystick::update() {
mjr 3:3514575d4f86 37 HID_REPORT report;
mjr 3:3514575d4f86 38
mjr 3:3514575d4f86 39 // Fill the report according to the Joystick Descriptor
mjr 3:3514575d4f86 40 report.data[0] = _buttons & 0xff;
mjr 3:3514575d4f86 41 report.data[1] = (_buttons >> 8) & 0xff;
mjr 6:cc35eb643e8f 42 #if 0 // 8-bit coordinate reports
mjr 3:3514575d4f86 43 report.data[2] = _x & 0xff;
mjr 3:3514575d4f86 44 report.data[3] = _y & 0xff;
mjr 3:3514575d4f86 45 report.data[4] = _z & 0xff;
mjr 3:3514575d4f86 46 report.data[5] = _rx & 0xff;
mjr 3:3514575d4f86 47 report.data[6] = _ry & 0xff;
mjr 3:3514575d4f86 48 report.length = 7;
mjr 6:cc35eb643e8f 49 #else // 16-bit reports
mjr 6:cc35eb643e8f 50 #define put(idx, val) (report.data[idx] = (val) & 0xff, report.data[(idx)+1] = ((val) >> 8) & 0xff)
mjr 6:cc35eb643e8f 51 put(2, _x);
mjr 6:cc35eb643e8f 52 put(4, _y);
mjr 6:cc35eb643e8f 53 put(6, _z);
mjr 6:cc35eb643e8f 54 put(8, _rx);
mjr 6:cc35eb643e8f 55 put(10, _ry);
mjr 6:cc35eb643e8f 56 report.length = 12;
mjr 6:cc35eb643e8f 57 #endif
mjr 3:3514575d4f86 58
mjr 5:a70c0bce770d 59 // send the report
mjr 3:3514575d4f86 60 return sendNB(&report);
mjr 3:3514575d4f86 61 }
mjr 3:3514575d4f86 62
mjr 3:3514575d4f86 63 bool USBJoystick::move(int16_t x, int16_t y) {
mjr 3:3514575d4f86 64 _x = x;
mjr 3:3514575d4f86 65 _y = y;
mjr 3:3514575d4f86 66 return update();
mjr 3:3514575d4f86 67 }
mjr 3:3514575d4f86 68
mjr 3:3514575d4f86 69 bool USBJoystick::setZ(int16_t z) {
mjr 3:3514575d4f86 70 _z = z;
mjr 3:3514575d4f86 71 return update();
mjr 3:3514575d4f86 72 }
mjr 3:3514575d4f86 73
mjr 3:3514575d4f86 74 bool USBJoystick::buttons(uint16_t buttons) {
mjr 3:3514575d4f86 75 _buttons = buttons;
mjr 3:3514575d4f86 76 return update();
mjr 3:3514575d4f86 77 }
mjr 3:3514575d4f86 78
mjr 3:3514575d4f86 79
mjr 3:3514575d4f86 80 void USBJoystick::_init() {
mjr 3:3514575d4f86 81
mjr 3:3514575d4f86 82 _x = 0;
mjr 3:3514575d4f86 83 _y = 0;
mjr 3:3514575d4f86 84 _z = 0;
mjr 3:3514575d4f86 85 _buttons = 0x0000;
mjr 3:3514575d4f86 86 }
mjr 3:3514575d4f86 87
mjr 3:3514575d4f86 88
mjr 3:3514575d4f86 89 uint8_t * USBJoystick::reportDesc()
mjr 3:3514575d4f86 90 {
mjr 3:3514575d4f86 91 static uint8_t reportDescriptor[] =
mjr 3:3514575d4f86 92 {
mjr 3:3514575d4f86 93 USAGE_PAGE(1), 0x01, // Generic desktop
mjr 3:3514575d4f86 94 USAGE(1), 0x04, // Joystick
mjr 3:3514575d4f86 95
mjr 3:3514575d4f86 96 COLLECTION(1), 0x01, // Application
mjr 6:cc35eb643e8f 97 // COLLECTION(1), 0x00, // Physical
mjr 3:3514575d4f86 98
mjr 3:3514575d4f86 99 USAGE_PAGE(1), 0x09, // Buttons
mjr 3:3514575d4f86 100 USAGE_MINIMUM(1), 0x01, // { buttons }
mjr 3:3514575d4f86 101 USAGE_MAXIMUM(1), 0x10, // { 1-16 }
mjr 3:3514575d4f86 102 LOGICAL_MINIMUM(1), 0x00, // 1-bit buttons - 0...
mjr 3:3514575d4f86 103 LOGICAL_MAXIMUM(1), 0x01, // ...to 1
mjr 3:3514575d4f86 104 REPORT_SIZE(1), 0x01, // 1 bit per report
mjr 3:3514575d4f86 105 REPORT_COUNT(1), 0x10, // 16 reports
mjr 3:3514575d4f86 106 UNIT_EXPONENT(1), 0x00, // Unit_Exponent (0)
mjr 3:3514575d4f86 107 UNIT(1), 0x00, // Unit (None)
mjr 3:3514575d4f86 108 INPUT(1), 0x02, // Data, Variable, Absolute
mjr 3:3514575d4f86 109
mjr 3:3514575d4f86 110 USAGE_PAGE(1), 0x01, // Generic desktop
mjr 3:3514575d4f86 111 USAGE(1), 0x30, // X
mjr 3:3514575d4f86 112 USAGE(1), 0x31, // Y
mjr 3:3514575d4f86 113 USAGE(1), 0x32, // Z
mjr 3:3514575d4f86 114 USAGE(1), 0x33, // Rx
mjr 3:3514575d4f86 115 USAGE(1), 0x34, // Ry
mjr 6:cc35eb643e8f 116 LOGICAL_MINIMUM(2), 0x00,0xF0, // each value ranges -4096
mjr 6:cc35eb643e8f 117 LOGICAL_MAXIMUM(2), 0x00,0x10, // ...to +4096
mjr 6:cc35eb643e8f 118 REPORT_SIZE(1), 0x10, // 16 bits per report
mjr 3:3514575d4f86 119 REPORT_COUNT(1), 0x05, // 5 reports (X, Y, Z, Rx, Ry)
mjr 3:3514575d4f86 120 INPUT(1), 0x02, // Data, Variable, Absolute
mjr 3:3514575d4f86 121
mjr 3:3514575d4f86 122 REPORT_COUNT(1), 0x08, // input report count (LEDWiz messages)
mjr 3:3514575d4f86 123 0x09, 0x01, // usage
mjr 3:3514575d4f86 124 0x91, 0x01, // Output (array)
mjr 3:3514575d4f86 125
mjr 6:cc35eb643e8f 126 // END_COLLECTION(0),
mjr 3:3514575d4f86 127 END_COLLECTION(0)
mjr 3:3514575d4f86 128 };
mjr 3:3514575d4f86 129
mjr 3:3514575d4f86 130 reportLength = sizeof(reportDescriptor);
mjr 3:3514575d4f86 131 return reportDescriptor;
mjr 3:3514575d4f86 132 }
mjr 3:3514575d4f86 133
mjr 3:3514575d4f86 134 uint8_t * USBJoystick::stringImanufacturerDesc() {
mjr 3:3514575d4f86 135 static uint8_t stringImanufacturerDescriptor[] = {
mjr 3:3514575d4f86 136 0x10, /*bLength*/
mjr 3:3514575d4f86 137 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
mjr 3:3514575d4f86 138 'm',0,'j',0,'r',0,'c',0,'o',0,'r',0,'p',0 /*bString iManufacturer - mjrcorp*/
mjr 3:3514575d4f86 139 };
mjr 3:3514575d4f86 140 return stringImanufacturerDescriptor;
mjr 3:3514575d4f86 141 }
mjr 3:3514575d4f86 142
mjr 3:3514575d4f86 143 uint8_t * USBJoystick::stringIserialDesc() {
mjr 3:3514575d4f86 144 static uint8_t stringIserialDescriptor[] = {
mjr 3:3514575d4f86 145 0x16, /*bLength*/
mjr 3:3514575d4f86 146 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
mjr 3:3514575d4f86 147 '0',0,'1',0,'2',0,'3',0,'4',0,'5',0,'6',0,'7',0,'8',0,'9',0, /*bString iSerial - 0123456789*/
mjr 3:3514575d4f86 148 };
mjr 3:3514575d4f86 149 return stringIserialDescriptor;
mjr 3:3514575d4f86 150 }
mjr 3:3514575d4f86 151
mjr 3:3514575d4f86 152 uint8_t * USBJoystick::stringIproductDesc() {
mjr 3:3514575d4f86 153 static uint8_t stringIproductDescriptor[] = {
mjr 3:3514575d4f86 154 0x2E, /*bLength*/
mjr 3:3514575d4f86 155 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
mjr 3:3514575d4f86 156 'P',0,'i',0,'n',0,'s',0,'c',0,'a',0,'p',0,'e',0,
mjr 3:3514575d4f86 157 ' ',0,'C',0,'o',0,'n',0,'t',0,'r',0,'o',0,'l',0,
mjr 3:3514575d4f86 158 'l',0,'e',0,'r',0 /*String iProduct */
mjr 3:3514575d4f86 159 };
mjr 3:3514575d4f86 160 return stringIproductDescriptor;
mjr 3:3514575d4f86 161 }