Adjusts the great pinscape controller to work with a cheap linear potentiometer instead of the expensive CCD array

Dependencies:   USBDevice mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Sun Jul 27 18:24:51 2014 +0000
Revision:
5:a70c0bce770d
Parent:
3:3514575d4f86
Child:
6:cc35eb643e8f
Somewhat working with ball-model damping. About to change to cabinet model.

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