Mike R / Mbed 2 deprecated Pinscape_Controller_v1

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Revision:
37:ed52738445fc
Parent:
36:b9747461331e
Child:
38:091e511ce8a0
--- a/main.cpp	Sat Dec 19 06:50:23 2015 +0000
+++ b/main.cpp	Thu Dec 24 01:37:40 2015 +0000
@@ -886,7 +886,7 @@
                     
                     // start a new sticky period for debouncing this
                     // state change
-                    bs->t = 0.005;
+                    bs->t = 0.075;
                 }
             }
 
@@ -2819,6 +2819,20 @@
 
         // update the buttons
         bool buttonsChanged = readButtons(cfg);
+        
+        // send a keyboard report if we have new data to report
+        if (kbState.changed)
+        {
+            js.kbUpdate(kbState.data);
+            kbState.changed = false;
+        }
+
+        // send the media control report, if applicable
+        if (mediaState.changed)
+        {
+            js.mediaUpdate(mediaState.data);
+            mediaState.changed = false;
+        }
 
         // If it's been long enough since our last USB status report,
         // send the new report.  We throttle the report rate because
@@ -2826,8 +2840,7 @@
         // VP only wants to sync with the real world in 10ms intervals,
         // so reporting more frequently creates I/O overhead without 
         // doing anything to improve the simulation.
-        if (cfg.joystickEnabled 
-            && (reportTimer.read_ms() > 15 || buttonsChanged))
+        if (cfg.joystickEnabled && reportTimer.read_ms() > 10)
         {
             // read the accelerometer
             int xa, ya;
@@ -2856,26 +2869,6 @@
             // send the joystick report
             js.update(x, y, zrep, jsButtons | simButtons, statusFlags);
             
-            // send the keyboard report(s), if applicable
-            bool waitBeforeMedia = false;
-            if (kbState.changed)
-            {
-                js.kbUpdate(kbState.data);
-                kbState.changed = false;
-                waitBeforeMedia = true;
-            }
-            if (mediaState.changed)
-            {
-                // just sent a key report - give the channel a moment to clear before 
-                // sending another report on its heels, to avoid clogging the pipe
-                if (waitBeforeMedia)
-                    wait_us(1);
-                    
-                // send the media key report
-                js.mediaUpdate(mediaState.data);
-                mediaState.changed = false;
-            }
-            
             // we've just started a new report interval, so reset the timer
             reportTimer.reset();
         }