Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.
Dependencies: FastIO FastPWM SimpleDMA mbed
Fork of Pinscape_Controller by
Revision 36:b9747461331e, committed 2015-12-19
- Comitter:
- mjr
- Date:
- Sat Dec 19 06:50:23 2015 +0000
- Parent:
- 35:e959ffba78fd
- Child:
- 37:ed52738445fc
- Commit message:
- Report joystick/keyboard updates immediately on change (don't wait for 15ms joystick cycle to elapse)
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sat Dec 19 06:37:19 2015 +0000 +++ b/main.cpp Sat Dec 19 06:50:23 2015 +0000 @@ -830,16 +830,20 @@ uint8_t data; // key state byte for USB reports } mediaState = { false, 0 }; -// read the button input state -void readButtons(Config &cfg) +// read the button input state; returns true if there are any button +// state changes to report, false if not +bool readButtons(Config &cfg) { + // no changes detected yet + bool changes = false; + // start with an empty list of USB key codes uint8_t modkeys = 0; uint8_t keys[7] = { 0, 0, 0, 0, 0, 0, 0 }; int nkeys = 0; // clear the joystick buttons - jsButtons = 0; + uint32_t newjs = 0; // start with no media keys pressed uint8_t mediakeys = 0; @@ -890,7 +894,7 @@ if (bs->pressed) { // OR in the joystick button bit, mod key bits, and media key bits - jsButtons |= bs->js; + newjs |= bs->js; modkeys |= bs->keymod; mediakeys |= bs->mediakey; @@ -900,6 +904,13 @@ } } } + + // check for joystick button changes + if (jsButtons != newjs) + { + changes = true; + jsButtons = newjs; + } // Check for changes to the keyboard keys if (kbState.data[0] != modkeys @@ -908,6 +919,7 @@ { // we have changes - set the change flag and store the new key data kbState.changed = true; + changes = true; kbState.data[0] = modkeys; if (nkeys <= 6) { // 6 or fewer simultaneous keys - report the key codes @@ -926,7 +938,11 @@ { mediaState.changed = true; mediaState.data = mediakeys; + changes = true; } + + // return the change indicator + return changes; } // --------------------------------------------------------------------------- @@ -2802,7 +2818,7 @@ } // update the buttons - readButtons(cfg); + bool buttonsChanged = readButtons(cfg); // If it's been long enough since our last USB status report, // send the new report. We throttle the report rate because @@ -2810,7 +2826,8 @@ // 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) + if (cfg.joystickEnabled + && (reportTimer.read_ms() > 15 || buttonsChanged)) { // read the accelerometer int xa, ya;