Mike R / Mbed 2 deprecated Pinscape_Controller_V2

Dependencies:   mbed FastIO FastPWM USBDevice

Fork of Pinscape_Controller by Mike R

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers cfgVarMsgMap.h Source File

cfgVarMsgMap.h

00001 // Define the configuration variable USB get/set mapper.  We use
00002 // macros for the get/set operations to allow for common source
00003 // code for the two operations.  main.cpp #includes this file twice:
00004 // once for the SET function and once for the GET function.  main.cpp
00005 // redefines the v_xxx macros according to the current inclusion mode.
00006 //
00007 // This is a little tricky to follow because of the macros, but the
00008 // benefit is that the get and set functions automatically stay in
00009 // sync in terms of the variable types and byte mappings in the USB
00010 // messages, since they're both generated automatically from the
00011 // same code.
00012 //
00013 // The SET function is called directly from the corresponding USB
00014 // protocol message to set one variable.  The data buffer is simply
00015 // the data passed in from the USB message.
00016 //
00017 // The GET function is called in a loop from our configuration
00018 // variable reporting function.  The report function loops through
00019 // each variable in turn to generate a series of reports.  The
00020 // caller in this case fills in data[1] with the variable ID, and
00021 // it also fills in data[2] with the current index being queried
00022 // for the array variables (buttons, outputs).  We fill in the
00023 // rest of the data[] bytes with the current variable value(s),
00024 // encoded for the USB protocol message.
00025 
00026 
00027 void v_func
00028 {
00029     switch (data[1])
00030     {
00031         // ********** UNRECOGNIZED VARIABLE IDs **********
00032         // For any variable ID we don't recognize, we'll ignore SET
00033         // requests and return all zeroes on QUERY requests.  This
00034         // provides sensible default behavior if a newer version of 
00035         // the config tool is used with an older version of the 
00036         // firwmare.  Because of the default all-zero query response,
00037         // new variable added over time should use zero values as
00038         // the standard defaults whenever possible.  Note that the
00039         // config tool can also use QUERY VARIABLE 0 to determine
00040         // the number of variables supported by the firmware it's
00041         // talking to, if it needs to know whether or not a 
00042         // particular variable exists (a variable exists if its ID
00043         // is within the range returned by the QUERY 0 call).
00044         // 
00045     default:
00046         break;
00047         
00048         
00049         // ********** DESCRIBE CONFIGURATION VARIABLES **********
00050     case 0:
00051         v_byte_ro(22, 2);       // number of SCALAR variables
00052         v_byte_ro(6, 3);        // number of ARRAY variables
00053         break;
00054         
00055         // ********** SCALAR VARIABLES **********
00056         
00057     case 1:
00058         // USB identification (Vendor ID, Product ID)
00059         v_ui16(usbVendorID, 2);
00060         v_ui16(usbProductID, 4);
00061         break;
00062         
00063     case 2:
00064         // Pinscape Controller unit number (nominal unit number, 1-16)
00065         if_msg_valid(data[2] >= 1 && data[2] <= 16)
00066             v_byte(psUnitNo, 2);
00067         break;
00068         
00069     case 3:
00070         // Joystick report settings
00071         v_byte(joystickEnabled, 2);
00072         v_byte(joystickAxisFormat, 3);
00073         v_ui32(jsReportInterval_us, 4);
00074         
00075 #if VAR_MODE_SET
00076         // apply a default if the report interval is zero
00077         if (cfg.jsReportInterval_us == 0)
00078             cfg.jsReportInterval_us = 8333;
00079 #endif
00080         break;
00081         
00082     case 4:
00083         // Accelerometer options
00084         v_byte(accel.orientation, 2);
00085         v_byte(accel.range, 3);
00086         v_byte(accel.autoCenterTime, 4);
00087         v_byte(accel.stutter, 5);
00088         break;
00089 
00090     case 5:
00091         // Plunger sensor type
00092         v_byte(plunger.sensorType, 2);
00093         v_byte(plunger.param1, 3);
00094         break;
00095         
00096     case 6:
00097         // Plunger sensor pin assignments
00098         v_byte(plunger.sensorPin[0], 2);
00099         v_byte(plunger.sensorPin[1], 3);
00100         v_byte(plunger.sensorPin[2], 4);
00101         v_byte(plunger.sensorPin[3], 5);
00102         break;
00103         
00104     case 7:
00105         // Plunger calibration button and indicator light pin assignments
00106         v_byte(plunger.cal.features, 2);
00107         v_byte(plunger.cal.btn, 3);
00108         v_byte(plunger.cal.led, 4);
00109         break;
00110         
00111     case 8:
00112         // ZB Launch Ball setup
00113         v_byte(plunger.zbLaunchBall.port, 2);
00114         v_byte(plunger.zbLaunchBall.keytype, 3);
00115         v_byte(plunger.zbLaunchBall.keycode, 4);
00116         v_ui16(plunger.zbLaunchBall.pushDistance, 5);
00117         break;
00118         
00119     case 9:
00120         // TV ON setup
00121         v_byte(TVON.statusPin, 2);
00122         v_byte(TVON.latchPin, 3);
00123         v_byte(TVON.relayPin, 4);
00124         v_ui16(TVON.delayTime, 5);
00125         break;
00126         
00127     case 10:
00128         // TLC5940NT PWM controller chip setup
00129         v_byte(tlc5940.nchips, 2);
00130         v_byte(tlc5940.sin, 3);
00131         v_byte(tlc5940.sclk, 4);
00132         v_byte(tlc5940.xlat, 5);
00133         v_byte(tlc5940.blank, 6);
00134         v_byte(tlc5940.gsclk, 7);
00135         break;
00136         
00137     case 11:
00138         // 74HC595 shift register chip setup
00139         v_byte(hc595.nchips, 2);
00140         v_byte(hc595.sin, 3);
00141         v_byte(hc595.sclk, 4);
00142         v_byte(hc595.latch, 5);
00143         v_byte(hc595.ena, 6);
00144         break;
00145         
00146     case 12:
00147         // Disconnect reboot timeout
00148         v_byte(disconnectRebootTimeout, 2);
00149         break;
00150         
00151     case 13:
00152         // plunger calibration
00153         v_ui16(plunger.cal.zero, 2);
00154         v_ui16(plunger.cal.max, 4);
00155         v_byte(plunger.cal.tRelease, 6);
00156         v_byte(plunger.cal.calibrated, 7);
00157         break;
00158         
00159     case 14:
00160         // expansion board configuration
00161         v_byte(expan.typ, 2);
00162         v_byte(expan.vsn, 3);
00163         v_byte(expan.ext[0], 4);
00164         v_byte(expan.ext[1], 5);
00165         v_byte(expan.ext[2], 6);
00166         v_byte(expan.ext[3], 7);
00167         break;
00168         
00169     case 15:
00170         // night mode configuration
00171         v_byte(nightMode.btn, 2);
00172         v_byte(nightMode.flags, 3);
00173         v_byte(nightMode.port, 4);
00174         break;
00175         
00176     case 16:
00177         // shift button configuration
00178         v_byte(shiftButton.idx, 2);
00179         v_byte(shiftButton.mode, 3);
00180         break;
00181         
00182     case 17:
00183         // IR sensor and emitter setup
00184         v_byte(IR.sensor, 2);
00185         v_byte(IR.emitter, 3);
00186         break;
00187         
00188     case 18:
00189         // plunger auto-zeroing time
00190         v_byte(plunger.autoZero.flags, 2);
00191         v_byte(plunger.autoZero.t, 3);
00192         break;
00193         
00194     case 19:
00195         // Plunger filters - jitter window size, reversed orientation.
00196         // The reversed orientation byte always has bit 0x80 set to indicate
00197         // that the feature is supported in this version.
00198         v_ui16(plunger.jitterWindow, 2);
00199         v_byte_ro(cfg.plunger.reverseOrientation | 0x80, 4);
00200         v_byte_wo(plunger.reverseOrientation, 4);
00201         break;
00202         
00203     case 20:
00204         // bar-code plunger setup
00205         v_ui16(plunger.barCode.startPix, 2);
00206         break;
00207         
00208     case 21:
00209         // TLC59116 PWM controller setup
00210         v_ui16(tlc59116.chipMask, 2);
00211         v_byte(tlc59116.sda, 4);
00212         v_byte(tlc59116.scl, 5);
00213         v_byte(tlc59116.reset, 6);
00214         break;
00215         
00216     case 22:
00217         // plunger raw configuration
00218         v_ui16(plunger.cal.raw0, 2);
00219         v_ui16(plunger.cal.raw1, 4);
00220         v_ui16(plunger.cal.raw2, 6);
00221         break;
00222         
00223     // case N: // new scalar variable
00224     //
00225     // !!! ATTENTION !!!
00226     // UPDATE CASE 0 ABOVE WHEN ADDING A NEW VARIABLE!!!
00227 
00228     
00229     // ********** SPECIAL DIAGNOSTIC VARIBLES **********
00230     //
00231     // This is a set of variables that act like the array variables
00232     // below.  However, these are generally read-only, and since they
00233     // don't contain restorable configuration data, they're not 
00234     // included in the variable counts reported by a "variable 0"
00235     // query above.
00236     case 220:
00237 #if !VAR_MODE_SET && ENABLE_DIAGNOSTICS
00238         {
00239             uint32_t a;
00240             switch (data[2])
00241             {
00242                 case 1:
00243                     // main loop, average iteration time in us
00244                     a = uint32_t(mainLoopIterTime/mainLoopIterCount);
00245                     v_ui32_ro(a, 3);
00246                     break;
00247                     
00248                 case 2:
00249                     // incoming message average processing time in us
00250                     a = uint32_t(mainLoopMsgTime/mainLoopMsgCount);
00251                     v_ui32_ro(a, 3);
00252                     break;
00253                 
00254                 case 3:
00255                     // PWM update polling routine, average time per call in us
00256                     a = uint32_t(polledPwmTotalTime/polledPwmRunCount);
00257                     v_ui32_ro(a, 3);
00258                     break;
00259                 
00260                 case 4:
00261                     // LedWiz flash update routine, average time per call in us
00262                     a = uint32_t(wizPulseTotalTime/wizPulseRunCount);
00263                     v_ui32_ro(a, 3);
00264                     break;
00265                     
00266                 case 5:
00267                 case 6:
00268                 case 7:
00269                 case 8:
00270                 case 9:
00271                 case 10:
00272                 case 11:
00273                 case 12:
00274                 case 13:
00275                 case 14:
00276                 case 15:
00277                 case 16:
00278                     // main loop checkpoint N, time in us
00279                     a = uint32_t(mainLoopIterCheckpt[data[2]-5]/mainLoopIterCount);
00280                     v_ui32_ro(a, 3);
00281                     break;
00282                     
00283                 case 30:
00284                     a = (plungerSensor != 0 ? plungerSensor->getAvgScanTime() : 0);
00285                     v_ui32_ro(a, 3);
00286                     break;                    
00287             }
00288         }
00289 #endif
00290         break;
00291         
00292     // ********** ARRAY VARIABLES **********
00293 
00294 
00295     // case N: // new array variable
00296     //
00297     // !!! ATTENTION !!!
00298     // UPDATE CASE 0 ABOVE WHEN ADDING A NEW ARRAY VARIABLE!!!
00299     
00300     case 250:
00301         // IR command code - high 32 bits
00302         {
00303             int idx = data[2];
00304             if (idx == 0)
00305             {
00306                 v_byte_ro(MAX_IR_CODES, 3);
00307             }
00308             else if (idx > 0 && idx <= MAX_IR_CODES)
00309             {
00310                 --idx;
00311                 v_ui32(IRCommand[idx].code.hi, 3);
00312             }
00313         }
00314         break;
00315     
00316     case 251:
00317         // IR command code - protocol and low 32 bits
00318         {
00319             int idx = data[2];
00320             if (idx == 0)
00321             {
00322                 v_byte_ro(MAX_IR_CODES, 3);
00323             }
00324             else if (idx > 0 && idx <= MAX_IR_CODES)
00325             {
00326                 --idx;
00327                 v_byte(IRCommand[idx].protocol, 3);
00328                 v_ui32(IRCommand[idx].code.lo, 4);
00329             }
00330         }
00331         break;
00332     
00333     case 252:
00334         // IR command descriptor
00335         {
00336             int idx = data[2];
00337             if (idx == 0)
00338             {
00339                 v_byte_ro(MAX_IR_CODES, 3);
00340             }
00341             else if (idx > 0 && idx <= MAX_IR_CODES)
00342             {
00343                 --idx;
00344                 v_byte(IRCommand[idx].flags, 3);
00345                 v_byte(IRCommand[idx].keytype, 4);
00346                 v_byte(IRCommand[idx].keycode, 5);
00347             }
00348         }
00349         break;
00350     
00351     case 253:
00352         // extended button setup
00353         {
00354             // get the index and check if it's in range
00355             int idx = data[2];
00356             if (idx == 0)
00357             {
00358                 // index 0 on query retrieves number of slots
00359                 v_byte_ro(MAX_BUTTONS, 3);
00360             }
00361             else if (idx > 0 && idx <= MAX_BUTTONS)
00362             {
00363                 // adjust to an array index
00364                 --idx;
00365                 
00366                 // transfer the values
00367                 v_byte(button[idx].typ2, 3);
00368                 v_byte(button[idx].val2, 4);
00369                 v_byte(button[idx].IRCommand2, 5);
00370             }                
00371         }
00372         break;
00373 
00374     case 254:
00375         // button setup
00376         {
00377             // get the button number
00378             int idx = data[2];
00379             
00380             // if it's in range, set the button data
00381             if (idx == 0)
00382             {
00383                 // index 0 on query retrieves number of slots
00384                 v_byte_ro(MAX_BUTTONS, 3);
00385             }
00386             else if (idx > 0 && idx <= MAX_BUTTONS)
00387             {
00388                 // adjust to an array index
00389                 --idx;
00390                 
00391                 // transfer the values
00392                 v_byte(button[idx].pin, 3);
00393                 v_byte(button[idx].typ, 4);
00394                 v_byte(button[idx].val, 5);
00395                 v_byte(button[idx].flags, 6);
00396                 v_byte(button[idx].IRCommand, 7);
00397             }
00398         }
00399         break;
00400         
00401     case 255:
00402         // LedWiz output port setup
00403         {
00404             // get the port number
00405             int idx = data[2];
00406             
00407             // if it's in range, set the port data
00408             if (idx == 0)
00409             {
00410                 // index 0 on query retrieves number of slots
00411                 v_byte_ro(MAX_OUT_PORTS, 3);
00412             }
00413             else if (idx > 0 && idx <= MAX_OUT_PORTS)
00414             {
00415                 // adjust to an array index
00416                 --idx;
00417                 
00418                 // set the values
00419                 v_byte(outPort[idx].typ, 3);
00420                 v_byte(outPort[idx].pin, 4);
00421                 v_byte(outPort[idx].flags, 5);
00422                 v_byte(outPort[idx].flipperLogic, 6);
00423             }
00424         }
00425         break;
00426     }
00427 }
00428