]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Fixing USB send rate.
authorJacob Alexander <haata@kiibohd.com>
Sat, 20 Sep 2014 02:11:37 +0000 (19:11 -0700)
committerJacob Alexander <haata@kiibohd.com>
Sat, 20 Sep 2014 02:11:37 +0000 (19:11 -0700)
- Only send USB events when something changes (rather than every ms)

Macro/PartialMap/kll.h
Output/pjrcUSB/output_com.c
Output/pjrcUSB/output_com.h

index 6db5219611df1eac0da86b24e0f6a073e6beb2f0..0df2cd40c62ccfaff32085294611030ecbb7e5a9 100644 (file)
@@ -64,7 +64,7 @@ typedef uint16_t nat_ptr_t;
 // Default Args (always sent): key state/analog of last key
 // Combo Length of 0 signifies end of sequence
 //
-// ResultMacro.guide     -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
+// ResultMacro.guide -> [<combo length>|<capability index>|<arg1>|<argn>|<capability index>|...|<combo length>|...|0]
 //
 // ResultMacroRecord.pos       -> <current combo position>
 // ResultMacroRecord.state     -> <last key state>
index 305b6360eb4db8a41673821bc18bc575790cc344..e110a01f711c4a13c8033407faf1b6a63ce0198b 100644 (file)
@@ -89,6 +89,10 @@ volatile uint8_t USBKeys_LEDs = 0;
 // 1 - NKRO Mode
 volatile uint8_t USBKeys_Protocol = 1;
 
+// Indicate if USB should send update
+// OS only needs update if there has been a change in state
+         uint8_t USBKeys_Changed = 0;
+
 // the idle configuration, how often we send the report to the
 // host (ms * 4) even when it hasn't changed
          uint8_t USBKeys_Idle_Config = 125;
@@ -111,6 +115,10 @@ void Output_usbCodeSend_capability( uint8_t state, uint8_t stateType, uint8_t *a
        }
 
        // TODO Analog inputs
+       // Only indicate USB has changed if either a press or release has occured
+       if ( state == 0x01 || state == 0x03 )
+               USBKeys_Changed = 1;
+
        // Only send keypresses if press or hold state
        if ( stateType == 0x00 && state == 0x03 ) // Release state
                return;
@@ -164,6 +172,17 @@ inline void Output_setup()
 // USB Data Send
 inline void Output_send(void)
 {
+       // Don't send update if USB has not changed
+       if ( !USBKeys_Changed )
+       {
+               // Clear modifiers and keys
+               USBKeys_Modifiers = 0;
+               USBKeys_Sent      = 0;
+
+               return;
+       }
+       USBKeys_Changed = 0;
+
        // TODO undo potentially old keys
        for ( uint8_t c = USBKeys_Sent; c < USBKeys_MaxSize; c++ )
                USBKeys_Array[c] = 0;
index 7257ed4b95dbe173816e596125ae3b5d06e80930..43cb0371981e8bd7c233b55bc54a3d51a07b6fea 100644 (file)
@@ -47,6 +47,7 @@ extern                       uint8_t USBKeys_Modifiers;
 extern                       uint8_t USBKeys_Array[USB_MAX_KEY_SEND];
 extern                       uint8_t USBKeys_Sent;
 extern volatile              uint8_t USBKeys_LEDs;
+extern                       uint8_t USBKeys_Changed;
 
                 static const uint8_t USBKeys_MaxSize = USB_MAX_KEY_SEND;
 extern volatile              uint8_t USBKeys_Protocol; // 0 - Boot Mode, 1 - NKRO Mode