Mirror with some correction

Dependencies:   mbed FastIO FastPWM USBDevice

Revision:
96:68d5621ff49f
Parent:
95:8eca8acbb82c
Child:
98:4df3c0f7e707
--- a/main.cpp	Sun Jan 28 20:59:59 2018 +0000
+++ b/main.cpp	Wed Jan 31 21:35:49 2018 +0000
@@ -6284,7 +6284,7 @@
     {
         // start the main loop timer for diagnostic data collection
         IF_DIAG(mainLoopTimer.reset(); mainLoopTimer.start();)
-            
+        
         // Process incoming reports on the joystick interface.  The joystick
         // "out" (receive) endpoint is used for LedWiz commands and our 
         // extended protocol commands.  Limit processing time to 5ms to
@@ -6326,6 +6326,14 @@
         // poll the accelerometer
         accel.poll();
             
+        // Note the "effective" plunger enabled status.  This has two
+        // components: the explicit "enabled" bit, and the plunger sensor
+        // type setting.  For most purposes, a plunger type of NONE is
+        // equivalent to disabled.  Set this to explicit 0x01 or 0x00
+        // so that we can OR the bit into status reports.
+        uint8_t effectivePlungerEnabled = (cfg.plunger.enabled
+            && cfg.plunger.sensorType != PlungerType_None) ? 0x01 : 0x00;
+            
         // collect diagnostic statistics, checkpoint 0
         IF_DIAG(mainLoopIterCheckpt[0] += mainLoopTimer.read_us();)
 
@@ -6488,7 +6496,7 @@
         
         // figure the current status flags for joystick reports
         uint16_t statusFlags = 
-            cfg.plunger.enabled             // 0x01
+            effectivePlungerEnabled         // 0x01
             | nightMode                     // 0x02
             | ((psu2_state & 0x07) << 2)    // 0x04 0x08 0x10
             | saveConfigSucceededFlag;      // 0x40
@@ -6535,7 +6543,7 @@
             // a traditional plunger, so we don't want to confuse VP with
             // regular plunger inputs.
             int zActual = plungerReader.getPosition();
-            int zReported = (!cfg.plunger.enabled || zbLaunchOn ? 0 : zActual);
+            int zReported = (!effectivePlungerEnabled || zbLaunchOn ? 0 : zActual);
             
             // send the joystick report
             jsOK = js.update(x, y, zReported, jsButtons, statusFlags);
@@ -6786,7 +6794,7 @@
                 // flashes and show the TV timer flashes instead.
                 diagLED(0, 0, 0);
             }
-            else if (cfg.plunger.enabled && !cfg.plunger.cal.calibrated)
+            else if (effectivePlungerEnabled && !cfg.plunger.cal.calibrated)
             {
                 // connected, plunger calibration needed - flash yellow/green
                 hb = !hb;