commit 7bf4443e8028681c9c9f5bc97df0f5b21bedf09f parent 540e0f6ca58fb51188b9aea1b9bda6ea3dfbe76d Author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se> Date: Wed, 5 Oct 2022 22:35:07 +0200 keyboard-fw: simplify get_media_keys Signed-off-by: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se> Diffstat:
M | reform2-keyboard-fw/keyboard.c | | | 37 | ++++++++++--------------------------- |
1 file changed, 10 insertions(+), 27 deletions(-)
diff --git a/reform2-keyboard-fw/keyboard.c b/reform2-keyboard-fw/keyboard.c @@ -102,34 +102,17 @@ inline bool is_media_key(uint8_t keycode) { return (keycode>=HID_KEYBOARD_SC_MEDIA_PLAY); } -bool get_media_keys(uint8_t keycode, USB_MediaReport_Data_t* mcr) { - bool media_key = false; - if (keycode == HID_KEYBOARD_SC_MEDIA_MUTE) { - if (mcr) mcr->Mute = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_VOLUME_UP) { - if (mcr) mcr->VolumeUp = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN) { - if (mcr) mcr->VolumeDown = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_BACKWARD) { - if (mcr) mcr->PreviousTrack = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_FORWARD) { - if (mcr) mcr->NextTrack = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_PLAY) { - if (mcr) mcr->PlayPause = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN) { - if (mcr) mcr->BrightnessDown = 1; - media_key = true; - } else if (keycode == HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP) { - if (mcr) mcr->BrightnessUp = 1; - media_key = true; +void get_media_keys(uint8_t keycode, USB_MediaReport_Data_t* mcr) { + switch (keycode) { + case HID_KEYBOARD_SC_MEDIA_MUTE: mcr->Mute = 1; break; + case HID_KEYBOARD_SC_MEDIA_VOLUME_UP: mcr->VolumeUp = 1; break; + case HID_KEYBOARD_SC_MEDIA_VOLUME_DOWN: mcr->VolumeDown = 1; break; + case HID_KEYBOARD_SC_MEDIA_BACKWARD: mcr->PreviousTrack = 1; break; + case HID_KEYBOARD_SC_MEDIA_FORWARD: mcr->NextTrack = 1; break; + case HID_KEYBOARD_SC_MEDIA_PLAY: mcr->PlayPause = 1; break; + case HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_DOWN: mcr->BrightnessDown = 1; break; + case HID_KEYBOARD_SC_MEDIA_BRIGHTNESS_UP: mcr->BrightnessUp = 1; break; } - return media_key; } #define MAX_SCANCODES 6