Arnaud VALLEY / Mbed 2 deprecated Pinscape_Controller_V2_arnoz

Dependencies:   mbed FastIO FastPWM USBDevice

Committer:
mjr
Date:
Wed Jul 23 17:53:28 2014 +0000
Revision:
3:3514575d4f86
Child:
5:a70c0bce770d
Conversion to interrupt-based sampling of the accelerometer working

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 3:3514575d4f86 42 report.data[2] = _x & 0xff;
mjr 3:3514575d4f86 43 report.data[3] = _y & 0xff;
mjr 3:3514575d4f86 44 report.data[4] = _z & 0xff;
mjr 3:3514575d4f86 45 report.data[5] = _rx & 0xff;
mjr 3:3514575d4f86 46 report.data[6] = _ry & 0xff;
mjr 3:3514575d4f86 47 report.length = 7;
mjr 3:3514575d4f86 48
mjr 3:3514575d4f86 49 return sendNB(&report);
mjr 3:3514575d4f86 50 }
mjr 3:3514575d4f86 51
mjr 3:3514575d4f86 52 bool USBJoystick::move(int16_t x, int16_t y) {
mjr 3:3514575d4f86 53 _x = x;
mjr 3:3514575d4f86 54 _y = y;
mjr 3:3514575d4f86 55 return update();
mjr 3:3514575d4f86 56 }
mjr 3:3514575d4f86 57
mjr 3:3514575d4f86 58 bool USBJoystick::setZ(int16_t z) {
mjr 3:3514575d4f86 59 _z = z;
mjr 3:3514575d4f86 60 return update();
mjr 3:3514575d4f86 61 }
mjr 3:3514575d4f86 62
mjr 3:3514575d4f86 63 bool USBJoystick::buttons(uint16_t buttons) {
mjr 3:3514575d4f86 64 _buttons = buttons;
mjr 3:3514575d4f86 65 return update();
mjr 3:3514575d4f86 66 }
mjr 3:3514575d4f86 67
mjr 3:3514575d4f86 68
mjr 3:3514575d4f86 69 void USBJoystick::_init() {
mjr 3:3514575d4f86 70
mjr 3:3514575d4f86 71 _x = 0;
mjr 3:3514575d4f86 72 _y = 0;
mjr 3:3514575d4f86 73 _z = 0;
mjr 3:3514575d4f86 74 _buttons = 0x0000;
mjr 3:3514575d4f86 75 }
mjr 3:3514575d4f86 76
mjr 3:3514575d4f86 77
mjr 3:3514575d4f86 78 uint8_t * USBJoystick::reportDesc()
mjr 3:3514575d4f86 79 {
mjr 3:3514575d4f86 80 static uint8_t reportDescriptor[] =
mjr 3:3514575d4f86 81 {
mjr 3:3514575d4f86 82 USAGE_PAGE(1), 0x01, // Generic desktop
mjr 3:3514575d4f86 83 USAGE(1), 0x04, // Joystick
mjr 3:3514575d4f86 84
mjr 3:3514575d4f86 85 COLLECTION(1), 0x01, // Application
mjr 3:3514575d4f86 86 // COLLECTION(1), 0x00, // Physical
mjr 3:3514575d4f86 87
mjr 3:3514575d4f86 88 USAGE_PAGE(1), 0x09, // Buttons
mjr 3:3514575d4f86 89 USAGE_MINIMUM(1), 0x01, // { buttons }
mjr 3:3514575d4f86 90 USAGE_MAXIMUM(1), 0x10, // { 1-16 }
mjr 3:3514575d4f86 91 LOGICAL_MINIMUM(1), 0x00, // 1-bit buttons - 0...
mjr 3:3514575d4f86 92 LOGICAL_MAXIMUM(1), 0x01, // ...to 1
mjr 3:3514575d4f86 93 REPORT_SIZE(1), 0x01, // 1 bit per report
mjr 3:3514575d4f86 94 REPORT_COUNT(1), 0x10, // 16 reports
mjr 3:3514575d4f86 95 UNIT_EXPONENT(1), 0x00, // Unit_Exponent (0)
mjr 3:3514575d4f86 96 UNIT(1), 0x00, // Unit (None)
mjr 3:3514575d4f86 97 INPUT(1), 0x02, // Data, Variable, Absolute
mjr 3:3514575d4f86 98
mjr 3:3514575d4f86 99 USAGE_PAGE(1), 0x01, // Generic desktop
mjr 3:3514575d4f86 100 USAGE(1), 0x30, // X
mjr 3:3514575d4f86 101 USAGE(1), 0x31, // Y
mjr 3:3514575d4f86 102 USAGE(1), 0x32, // Z
mjr 3:3514575d4f86 103 USAGE(1), 0x33, // Rx
mjr 3:3514575d4f86 104 USAGE(1), 0x34, // Ry
mjr 3:3514575d4f86 105 LOGICAL_MINIMUM(1), 0x81, // each value ranges -127...
mjr 3:3514575d4f86 106 LOGICAL_MAXIMUM(1), 0x7f, // ...to 127
mjr 3:3514575d4f86 107 REPORT_SIZE(1), 0x08, // 8 bits per report
mjr 3:3514575d4f86 108 REPORT_COUNT(1), 0x05, // 5 reports (X, Y, Z, Rx, Ry)
mjr 3:3514575d4f86 109 INPUT(1), 0x02, // Data, Variable, Absolute
mjr 3:3514575d4f86 110
mjr 3:3514575d4f86 111 REPORT_COUNT(1), 0x08, // input report count (LEDWiz messages)
mjr 3:3514575d4f86 112 0x09, 0x01, // usage
mjr 3:3514575d4f86 113 0x91, 0x01, // Output (array)
mjr 3:3514575d4f86 114
mjr 3:3514575d4f86 115 // END_COLLECTION(0),
mjr 3:3514575d4f86 116 END_COLLECTION(0)
mjr 3:3514575d4f86 117 };
mjr 3:3514575d4f86 118
mjr 3:3514575d4f86 119 reportLength = sizeof(reportDescriptor);
mjr 3:3514575d4f86 120 return reportDescriptor;
mjr 3:3514575d4f86 121 }
mjr 3:3514575d4f86 122
mjr 3:3514575d4f86 123 uint8_t * USBJoystick::stringImanufacturerDesc() {
mjr 3:3514575d4f86 124 static uint8_t stringImanufacturerDescriptor[] = {
mjr 3:3514575d4f86 125 0x10, /*bLength*/
mjr 3:3514575d4f86 126 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
mjr 3:3514575d4f86 127 'm',0,'j',0,'r',0,'c',0,'o',0,'r',0,'p',0 /*bString iManufacturer - mjrcorp*/
mjr 3:3514575d4f86 128 };
mjr 3:3514575d4f86 129 return stringImanufacturerDescriptor;
mjr 3:3514575d4f86 130 }
mjr 3:3514575d4f86 131
mjr 3:3514575d4f86 132 uint8_t * USBJoystick::stringIserialDesc() {
mjr 3:3514575d4f86 133 static uint8_t stringIserialDescriptor[] = {
mjr 3:3514575d4f86 134 0x16, /*bLength*/
mjr 3:3514575d4f86 135 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
mjr 3:3514575d4f86 136 '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 137 };
mjr 3:3514575d4f86 138 return stringIserialDescriptor;
mjr 3:3514575d4f86 139 }
mjr 3:3514575d4f86 140
mjr 3:3514575d4f86 141 uint8_t * USBJoystick::stringIproductDesc() {
mjr 3:3514575d4f86 142 static uint8_t stringIproductDescriptor[] = {
mjr 3:3514575d4f86 143 0x2E, /*bLength*/
mjr 3:3514575d4f86 144 STRING_DESCRIPTOR, /*bDescriptorType 0x03*/
mjr 3:3514575d4f86 145 'P',0,'i',0,'n',0,'s',0,'c',0,'a',0,'p',0,'e',0,
mjr 3:3514575d4f86 146 ' ',0,'C',0,'o',0,'n',0,'t',0,'r',0,'o',0,'l',0,
mjr 3:3514575d4f86 147 'l',0,'e',0,'r',0 /*String iProduct */
mjr 3:3514575d4f86 148 };
mjr 3:3514575d4f86 149 return stringIproductDescriptor;
mjr 3:3514575d4f86 150 }