Mirror with some correction

Dependencies:   mbed FastIO FastPWM USBDevice

Committer:
mjr
Date:
Wed Feb 03 22:57:25 2016 +0000
Revision:
40:cc0d9814522b
Child:
51:57eb311faafa
Gamma correction option for outputs; work in progress on new config program

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 40:cc0d9814522b 1 // Define the configuration variable USB get/set mapper. We use
mjr 40:cc0d9814522b 2 // macros for the get/set operations to allow for common source
mjr 40:cc0d9814522b 3 // code for the two operations. main.cpp #includes this file twice:
mjr 40:cc0d9814522b 4 // once for the SET function and once for the GET function. main.cpp
mjr 40:cc0d9814522b 5 // redefines the v_xxx macros according to the current inclusion mode.
mjr 40:cc0d9814522b 6 //
mjr 40:cc0d9814522b 7 // This is a little tricky to follow because of the macros, but the
mjr 40:cc0d9814522b 8 // benefit is that the get and set functions automatically stay in
mjr 40:cc0d9814522b 9 // sync in terms of the variable types and byte mappings in the USB
mjr 40:cc0d9814522b 10 // messages, since they're both generated automatically from the
mjr 40:cc0d9814522b 11 // same code.
mjr 40:cc0d9814522b 12 //
mjr 40:cc0d9814522b 13 // The SET function is called directly from the corresponding USB
mjr 40:cc0d9814522b 14 // protocol message to set one variable. The data buffer is simply
mjr 40:cc0d9814522b 15 // the data passed in from the USB message.
mjr 40:cc0d9814522b 16 //
mjr 40:cc0d9814522b 17 // The GET function is called in a loop from our configuration
mjr 40:cc0d9814522b 18 // variable reporting function. The report function loops through
mjr 40:cc0d9814522b 19 // each variable in turn to generate a series of reports. The
mjr 40:cc0d9814522b 20 // caller in this case fills in data[1] with the variable ID, and
mjr 40:cc0d9814522b 21 // it also fills in data[2] with the current index being queried
mjr 40:cc0d9814522b 22 // for the array variables (buttons, outputs). We fill in the
mjr 40:cc0d9814522b 23 // rest of the data[] bytes with the current variable value(s),
mjr 40:cc0d9814522b 24 // encoded for the USB protocol message.
mjr 40:cc0d9814522b 25
mjr 40:cc0d9814522b 26
mjr 40:cc0d9814522b 27 void v_func(uint8_t *data)
mjr 40:cc0d9814522b 28 {
mjr 40:cc0d9814522b 29 switch (data[1])
mjr 40:cc0d9814522b 30 {
mjr 40:cc0d9814522b 31 case 1:
mjr 40:cc0d9814522b 32 // USB identification (Vendor ID, Product ID)
mjr 40:cc0d9814522b 33 v_ui16(usbVendorID, 2);
mjr 40:cc0d9814522b 34 v_ui16(usbProductID, 4);
mjr 40:cc0d9814522b 35 break;
mjr 40:cc0d9814522b 36
mjr 40:cc0d9814522b 37 case 2:
mjr 40:cc0d9814522b 38 // Pinscape Controller unit number (nominal unit number, 1-16)
mjr 40:cc0d9814522b 39 if_msg_valid(data[2] >= 1 && data[2] <= 16)
mjr 40:cc0d9814522b 40 v_byte(psUnitNo, 2);
mjr 40:cc0d9814522b 41 break;
mjr 40:cc0d9814522b 42
mjr 40:cc0d9814522b 43 case 3:
mjr 40:cc0d9814522b 44 // Enable/disable joystick
mjr 40:cc0d9814522b 45 v_byte(joystickEnabled, 2);
mjr 40:cc0d9814522b 46 break;
mjr 40:cc0d9814522b 47
mjr 40:cc0d9814522b 48 case 4:
mjr 40:cc0d9814522b 49 // Accelerometer orientation
mjr 40:cc0d9814522b 50 v_byte(orientation, 2);
mjr 40:cc0d9814522b 51 break;
mjr 40:cc0d9814522b 52
mjr 40:cc0d9814522b 53 case 5:
mjr 40:cc0d9814522b 54 // Plunger sensor type
mjr 40:cc0d9814522b 55 v_byte(plunger.sensorType, 2);
mjr 40:cc0d9814522b 56 break;
mjr 40:cc0d9814522b 57
mjr 40:cc0d9814522b 58 case 6:
mjr 40:cc0d9814522b 59 // Plunger sensor pin assignments
mjr 40:cc0d9814522b 60 v_pin(plunger.sensorPin[0], 2);
mjr 40:cc0d9814522b 61 v_pin(plunger.sensorPin[1], 3);
mjr 40:cc0d9814522b 62 v_pin(plunger.sensorPin[2], 4);
mjr 40:cc0d9814522b 63 v_pin(plunger.sensorPin[3], 5);
mjr 40:cc0d9814522b 64 break;
mjr 40:cc0d9814522b 65
mjr 40:cc0d9814522b 66 case 7:
mjr 40:cc0d9814522b 67 // Plunger calibration button and indicator light pin assignments
mjr 40:cc0d9814522b 68 v_pin(plunger.cal.btn, 2);
mjr 40:cc0d9814522b 69 v_pin(plunger.cal.led, 3);
mjr 40:cc0d9814522b 70 break;
mjr 40:cc0d9814522b 71
mjr 40:cc0d9814522b 72 case 8:
mjr 40:cc0d9814522b 73 // ZB Launch Ball setup
mjr 40:cc0d9814522b 74 v_byte(plunger.zbLaunchBall.port, 2);
mjr 40:cc0d9814522b 75 v_byte(plunger.zbLaunchBall.btn, 3);
mjr 40:cc0d9814522b 76 v_ui16(plunger.zbLaunchBall.pushDistance, 4);
mjr 40:cc0d9814522b 77 break;
mjr 40:cc0d9814522b 78
mjr 40:cc0d9814522b 79 case 9:
mjr 40:cc0d9814522b 80 // TV ON setup
mjr 40:cc0d9814522b 81 v_pin(TVON.statusPin, 2);
mjr 40:cc0d9814522b 82 v_pin(TVON.latchPin, 3);
mjr 40:cc0d9814522b 83 v_pin(TVON.relayPin, 4);
mjr 40:cc0d9814522b 84 v_ui16(TVON.delayTime, 5);
mjr 40:cc0d9814522b 85 break;
mjr 40:cc0d9814522b 86
mjr 40:cc0d9814522b 87 case 10:
mjr 40:cc0d9814522b 88 // TLC5940NT PWM controller chip setup
mjr 40:cc0d9814522b 89 v_byte(tlc5940.nchips, 2);
mjr 40:cc0d9814522b 90 v_pin(tlc5940.sin, 3);
mjr 40:cc0d9814522b 91 v_pin(tlc5940.sclk, 4);
mjr 40:cc0d9814522b 92 v_pin(tlc5940.xlat, 5);
mjr 40:cc0d9814522b 93 v_pin(tlc5940.blank, 6);
mjr 40:cc0d9814522b 94 v_pin(tlc5940.gsclk, 7);
mjr 40:cc0d9814522b 95 break;
mjr 40:cc0d9814522b 96
mjr 40:cc0d9814522b 97 case 11:
mjr 40:cc0d9814522b 98 // 74HC595 shift register chip setup
mjr 40:cc0d9814522b 99 v_byte(hc595.nchips, 2);
mjr 40:cc0d9814522b 100 v_pin(hc595.sin, 3);
mjr 40:cc0d9814522b 101 v_pin(hc595.sclk, 4);
mjr 40:cc0d9814522b 102 v_pin(hc595.latch, 5);
mjr 40:cc0d9814522b 103 v_pin(hc595.ena, 6);
mjr 40:cc0d9814522b 104 break;
mjr 40:cc0d9814522b 105
mjr 40:cc0d9814522b 106 case 12:
mjr 40:cc0d9814522b 107 // button setup
mjr 40:cc0d9814522b 108 {
mjr 40:cc0d9814522b 109 // get the button number
mjr 40:cc0d9814522b 110 int idx = data[2];
mjr 40:cc0d9814522b 111
mjr 40:cc0d9814522b 112 // if it's in range, set the button data
mjr 40:cc0d9814522b 113 if (idx > 0 && idx <= MAX_BUTTONS)
mjr 40:cc0d9814522b 114 {
mjr 40:cc0d9814522b 115 // adjust to an array index
mjr 40:cc0d9814522b 116 --idx;
mjr 40:cc0d9814522b 117
mjr 40:cc0d9814522b 118 // set the values
mjr 40:cc0d9814522b 119 v_byte(button[idx].pin, 3);
mjr 40:cc0d9814522b 120 v_byte(button[idx].typ, 4);
mjr 40:cc0d9814522b 121 v_byte(button[idx].val, 5);
mjr 40:cc0d9814522b 122 v_byte(button[idx].flags, 6);
mjr 40:cc0d9814522b 123 }
mjr 40:cc0d9814522b 124 }
mjr 40:cc0d9814522b 125 break;
mjr 40:cc0d9814522b 126
mjr 40:cc0d9814522b 127 case 13:
mjr 40:cc0d9814522b 128 // LedWiz output port setup
mjr 40:cc0d9814522b 129 {
mjr 40:cc0d9814522b 130 // get the port number
mjr 40:cc0d9814522b 131 int idx = data[2];
mjr 40:cc0d9814522b 132
mjr 40:cc0d9814522b 133 // if it's in range, set the port data
mjr 40:cc0d9814522b 134 if (idx > 0 && idx <= MAX_OUT_PORTS)
mjr 40:cc0d9814522b 135 {
mjr 40:cc0d9814522b 136 // adjust to an array index
mjr 40:cc0d9814522b 137 --idx;
mjr 40:cc0d9814522b 138
mjr 40:cc0d9814522b 139 // set the values
mjr 40:cc0d9814522b 140 v_byte(outPort[idx].typ, 3);
mjr 40:cc0d9814522b 141 v_byte(outPort[idx].pin, 4);
mjr 40:cc0d9814522b 142 v_byte(outPort[idx].flags, 5);
mjr 40:cc0d9814522b 143 }
mjr 40:cc0d9814522b 144 else if (idx == 254)
mjr 40:cc0d9814522b 145 {
mjr 40:cc0d9814522b 146 // special ports
mjr 40:cc0d9814522b 147 idx -= 254;
mjr 40:cc0d9814522b 148 v_byte(specialPort[idx].typ, 3);
mjr 40:cc0d9814522b 149 v_byte(specialPort[idx].pin, 4);
mjr 40:cc0d9814522b 150 v_byte(specialPort[idx].flags, 5);
mjr 40:cc0d9814522b 151 }
mjr 40:cc0d9814522b 152 }
mjr 40:cc0d9814522b 153 break;
mjr 40:cc0d9814522b 154 }
mjr 40:cc0d9814522b 155 }
mjr 40:cc0d9814522b 156