Skip to content

Instantly share code, notes, and snippets.

@BenJuan26
Created April 17, 2020 03:07
Show Gist options
  • Save BenJuan26/5cf692e6ef1739dfeac2fec18a033cee to your computer and use it in GitHub Desktop.
Save BenJuan26/5cf692e6ef1739dfeac2fec18a033cee to your computer and use it in GitHub Desktop.
// Get the states of the physical switches and write them to the Toggleswitch objects.
// Assuming for now that all global variables referenced here are declared and initialized.
void updateKeys() {
if (!kpd.getKeys()) {
return;
}
for (int i = 0; i < LIST_MAX; i++) {
if (kpd.key[i].kchar == NO_KEY) {
continue;
}
// Turn the key code (e.g. 'F') into a zero-based array index.
int keyIndex = (int)kpd.key[i].kchar - keyOffset;
KeyState state = kpd.key[i].kstate;
if (state == PRESSED) {
switches[keyIndex].currState = BUTTON_PRESSED;
} else if (state == RELEASED) {
switches[keyIndex].currState = BUTTON_RELEASED;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment