Skip to content

Commit

Permalink
add: reordered code
Browse files Browse the repository at this point in the history
  • Loading branch information
blahlicus committed Sep 11, 2018
1 parent 78d325e commit 615df66
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions src/HID-APIs/DefaultKeyboardAPI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,11 @@ size_t DefaultKeyboardAPI::set(KeyboardKeycode k, bool s)
}
// Its a normal key
else{
// my code starts

// get size of keycodes during compile time
const uint8_t keycodesSize = sizeof(_keyReport.keycodes);


// if we are removing keys
if (!s) {
// iterate through the keycodes
for (uint8_t i = 0; i < keycodesSize; i++)
{
auto key = _keyReport.keycodes[i];
// if target key is found
if (key == k) {
// remove target and exit
_keyReport.keycodes[i] = KEY_RESERVED;
return 1;
}
}
} // if we are adding an element to keycodes
else {
// if we are adding an element to keycodes
if (s){
// iterate through the keycodes
for (uint8_t i = 0; i < keycodesSize; i++)
{
Expand All @@ -85,11 +69,19 @@ size_t DefaultKeyboardAPI::set(KeyboardKeycode k, bool s)
return 1;
}
}
} else { // we are removing k from keycodes
// iterate through the keycodes
for (uint8_t i = 0; i < keycodesSize; i++)
{
auto key = _keyReport.keycodes[i];
// if target key is found
if (key == k) {
// remove target and exit
_keyReport.keycodes[i] = KEY_RESERVED;
return 1;
}
}
}



// my code ends
}

// No empty/pressed key was found
Expand Down

0 comments on commit 615df66

Please sign in to comment.