forked from UltimateHackingKeyboard/firmware
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make postponing mechanism more robust
- Loading branch information
1 parent
87b6ffd
commit 91a90d0
Showing
8 changed files
with
79 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "postponer.h" | ||
#include "usb_report_updater.h" | ||
|
||
postponer_buffer_record_type_t buffer[POSTPONER_BUFFER_SIZE]; | ||
uint8_t buffer_size = 0; | ||
uint8_t buffer_position = 0; | ||
|
||
void Postponer_RunPostponed(void) { | ||
if(buffer_size == 0) { | ||
return; | ||
} | ||
|
||
if(DEACTIVATED_EARLIER(buffer[buffer_position].key)) { | ||
ActivateKey(buffer[buffer_position].key, true); | ||
buffer_position = (buffer_position + 1) % POSTPONER_BUFFER_SIZE; | ||
buffer_size--; | ||
} else if(ACTIVATED_EARLIER(buffer[buffer_position].key) && !buffer[buffer_position].key->debouncing) { | ||
/*if the user taps a key twice and holds, we need to "end" the first tap even if the | ||
* key is physically being held | ||
*/ | ||
buffer[buffer_position].key->current &= ~KeyState_Sw; | ||
} | ||
|
||
//try prevent loss of keys if some mechanism postpones more keys than we can properly let through | ||
while(buffer_size > POSTPONER_MAX_FILL) { | ||
ActivateKey(buffer[buffer_position].key, true); | ||
buffer_position = (buffer_position + 1) % POSTPONER_BUFFER_SIZE; | ||
buffer_size--; | ||
} | ||
} | ||
|
||
void Postponer_TrackKey(key_state_t *keyState) { | ||
uint8_t pos = (buffer_position + buffer_size) % POSTPONER_BUFFER_SIZE; | ||
buffer[pos].key = keyState; | ||
buffer_size = buffer_size < POSTPONER_BUFFER_SIZE ? buffer_size + 1 : buffer_size; | ||
} | ||
|
||
uint8_t Postponer_PendingCount() { | ||
return buffer_size; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#ifndef SRC_POSTPONER_H_ | ||
#define SRC_POSTPONER_H_ | ||
|
||
// Includes: | ||
|
||
#include "key_states.h" | ||
|
||
// Macros: | ||
|
||
#define POSTPONER_BUFFER_SIZE 20 | ||
#define POSTPONER_MAX_FILL 15 | ||
|
||
// Typedefs: | ||
typedef struct { | ||
key_state_t * key; | ||
} postponer_buffer_record_type_t; | ||
|
||
// Functions: | ||
void Postponer_RunPostponed(void); | ||
void Postponer_TrackKey(key_state_t *keyState); | ||
uint8_t Postponer_PendingCount(); | ||
|
||
#endif /* SRC_POSTPONER_H_ */ |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters