From eeeff4ec1adda6c3b856cb0421518a8378e8e8bc Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Tue, 25 Jul 2017 17:46:24 -0700 Subject: [PATCH 1/2] Fix parseKeyStrokeAction --- right/src/config/parse_keymap.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/right/src/config/parse_keymap.c b/right/src/config/parse_keymap.c index 6d038a2..5d1ea7a 100644 --- a/right/src/config/parse_keymap.c +++ b/right/src/config/parse_keymap.c @@ -30,12 +30,18 @@ static parser_error_t parseKeyStrokeAction(key_action_t *keyAction, uint8_t keyS } if (keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE) { keyAction->keystroke.scancode = keystrokeType == SerializedKeystrokeType_LongMedia ? readUInt16(buffer) : readUInt8(buffer); + } else { + keyAction->keystroke.scancode = 0; } if (keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_MODIFIERS) { keyAction->keystroke.modifiers = readUInt8(buffer); + } else { + keyAction->keystroke.modifiers = 0; } if (keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_LONGPRESS) { keyAction->keystroke.longPressAction = readUInt8(buffer); + } else { + keyAction->keystroke.longPressAction = 0; } return ParserError_Success; } From 1709227a28de6f20a351b79d5de5bf09c08d7216 Mon Sep 17 00:00:00 2001 From: Eric Tang Date: Tue, 25 Jul 2017 18:17:41 -0700 Subject: [PATCH 2/2] Use ternary operators instead of if-else statements --- right/src/config/parse_keymap.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/right/src/config/parse_keymap.c b/right/src/config/parse_keymap.c index 5d1ea7a..b2a4898 100644 --- a/right/src/config/parse_keymap.c +++ b/right/src/config/parse_keymap.c @@ -28,21 +28,15 @@ static parser_error_t parseKeyStrokeAction(key_action_t *keyAction, uint8_t keyS default: return ParserError_InvalidSerializedKeystrokeType; } - if (keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE) { - keyAction->keystroke.scancode = keystrokeType == SerializedKeystrokeType_LongMedia ? readUInt16(buffer) : readUInt8(buffer); - } else { - keyAction->keystroke.scancode = 0; - } - if (keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_MODIFIERS) { - keyAction->keystroke.modifiers = readUInt8(buffer); - } else { - keyAction->keystroke.modifiers = 0; - } - if (keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_LONGPRESS) { - keyAction->keystroke.longPressAction = readUInt8(buffer); - } else { - keyAction->keystroke.longPressAction = 0; - } + keyAction->keystroke.scancode = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_SCANCODE + ? keystrokeType == SerializedKeystrokeType_LongMedia ? readUInt16(buffer) : readUInt8(buffer) + : 0; + keyAction->keystroke.modifiers = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_MODIFIERS + ? readUInt8(buffer) + : 0; + keyAction->keystroke.longPressAction = keyStrokeAction & SERIALIZED_KEYSTROKE_TYPE_MASK_HAS_LONGPRESS + ? readUInt8(buffer) + : 0; return ParserError_Success; }