Use a macro for checking pressed state

To make the code in the keyswitch state checking functions clearer, use
a macro instead of repeating the same constant everywhere.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/56/head
Gergely Nagy 8 years ago
parent 3a2665aed4
commit 61e3697d40

@ -1,6 +1,7 @@
#include "keyswitch_state.h" #include "keyswitch_state.h"
// switch debouncing and status // switch debouncing and status
#define PRESSED B00000001
boolean key_was_pressed (byte keyState) { boolean key_was_pressed (byte keyState) {
if ( keyState & B00001000 || keyState & B00000100) { if ( keyState & B00001000 || keyState & B00000100) {
@ -11,7 +12,7 @@ boolean key_was_pressed (byte keyState) {
} }
boolean key_was_pressed (uint8_t currentState, uint8_t previousState) { boolean key_was_pressed (uint8_t currentState, uint8_t previousState) {
if (previousState & B00000001) { if (previousState & PRESSED) {
return true; return true;
} else { } else {
return false; return false;
@ -27,7 +28,7 @@ boolean key_is_pressed (byte keyState) {
} }
boolean key_is_pressed (uint8_t currentState, uint8_t previousState) { boolean key_is_pressed (uint8_t currentState, uint8_t previousState) {
if (currentState & B00000001) { if (currentState & PRESSED) {
return true; return true;
} else { } else {
return false; return false;
@ -43,7 +44,7 @@ boolean key_toggled_on(byte keyState) {
} }
boolean key_toggled_on (uint8_t currentState, uint8_t previousState) { boolean key_toggled_on (uint8_t currentState, uint8_t previousState) {
if ((currentState & B00000001) && ! (previousState & B00000001) ) { if ((currentState & PRESSED) && ! (previousState & PRESSED) ) {
return true; return true;
} else { } else {
return false; return false;
@ -60,7 +61,7 @@ boolean key_toggled_off(byte keyState) {
} }
boolean key_toggled_off (uint8_t currentState, uint8_t previousState) { boolean key_toggled_off (uint8_t currentState, uint8_t previousState) {
if ((previousState & B00000001) && ! (currentState & B00000001) ) { if ((previousState & PRESSED) && ! (currentState & PRESSED) ) {
return true; return true;
} else { } else {
return false; return false;

Loading…
Cancel
Save