Skip to content

Commit

Permalink
Separate keycode handling for LED Matrix and Backlight (qmk#23426)
Browse files Browse the repository at this point in the history
  • Loading branch information
fauxpark authored and whoisjordangarcia committed Jun 8, 2024
1 parent d854eef commit be101b0
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion builddefs/common_features.mk
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ ifeq ($(strip $(LED_MATRIX_ENABLE)), yes)
COMMON_VPATH += $(QUANTUM_DIR)/led_matrix/animations
COMMON_VPATH += $(QUANTUM_DIR)/led_matrix/animations/runners
POST_CONFIG_H += $(QUANTUM_DIR)/led_matrix/post_config.h
SRC += $(QUANTUM_DIR)/process_keycode/process_backlight.c
SRC += $(QUANTUM_DIR)/process_keycode/process_led_matrix.c
SRC += $(QUANTUM_DIR)/led_matrix/led_matrix.c
SRC += $(QUANTUM_DIR)/led_matrix/led_matrix_drivers.c
LIB8TION_ENABLE := yes
Expand Down
30 changes: 2 additions & 28 deletions quantum/process_keycode/process_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,11 @@
*/

#include "process_backlight.h"

#ifdef LED_MATRIX_ENABLE
# include "led_matrix.h"
#else
# include "backlight.h"
#endif
#include "backlight.h"

bool process_backlight(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
#ifdef LED_MATRIX_ENABLE
case QK_BACKLIGHT_ON:
led_matrix_enable();
return false;
case QK_BACKLIGHT_OFF:
led_matrix_disable();
return false;
case QK_BACKLIGHT_DOWN:
led_matrix_decrease_val();
return false;
case QK_BACKLIGHT_UP:
led_matrix_increase_val();
return false;
case QK_BACKLIGHT_TOGGLE:
led_matrix_toggle();
return false;
case QK_BACKLIGHT_STEP:
led_matrix_step();
return false;
#else
case QK_BACKLIGHT_ON:
backlight_level(BACKLIGHT_LEVELS);
return false;
Expand All @@ -63,11 +38,10 @@ bool process_backlight(uint16_t keycode, keyrecord_t *record) {
case QK_BACKLIGHT_STEP:
backlight_step();
return false;
# ifdef BACKLIGHT_BREATHING
#ifdef BACKLIGHT_BREATHING
case QK_BACKLIGHT_TOGGLE_BREATHING:
backlight_toggle_breathing();
return false;
# endif
#endif
}
}
Expand Down
32 changes: 32 additions & 0 deletions quantum/process_keycode/process_led_matrix.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright 2024 QMK
// SPDX-License-Identifier: GPL-2.0-or-later

#include "process_led_matrix.h"
#include "led_matrix.h"

bool process_led_matrix(uint16_t keycode, keyrecord_t *record) {
if (record->event.pressed) {
switch (keycode) {
case QK_BACKLIGHT_ON:
led_matrix_enable();
return false;
case QK_BACKLIGHT_OFF:
led_matrix_disable();
return false;
case QK_BACKLIGHT_DOWN:
led_matrix_decrease_val();
return false;
case QK_BACKLIGHT_UP:
led_matrix_increase_val();
return false;
case QK_BACKLIGHT_TOGGLE:
led_matrix_toggle();
return false;
case QK_BACKLIGHT_STEP:
led_matrix_step();
return false;
}
}

return true;
}
10 changes: 10 additions & 0 deletions quantum/process_keycode/process_led_matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Copyright 2024 QMK
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <stdint.h>
#include <stdbool.h>
#include "action.h"

bool process_led_matrix(uint16_t keycode, keyrecord_t *record);
11 changes: 9 additions & 2 deletions quantum/quantum.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#include "quantum.h"

#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE)
#ifdef BACKLIGHT_ENABLE
# include "process_backlight.h"
#endif

Expand All @@ -40,6 +40,10 @@
# include "process_leader.h"
#endif

#ifdef LED_MATRIX_ENABLE
# include "process_led_matrix.h"
#endif

#ifdef MAGIC_ENABLE
# include "process_magic.h"
#endif
Expand Down Expand Up @@ -333,9 +337,12 @@ bool process_record_quantum(keyrecord_t *record) {
#ifdef AUDIO_ENABLE
process_audio(keycode, record) &&
#endif
#if defined(BACKLIGHT_ENABLE) || defined(LED_MATRIX_ENABLE)
#if defined(BACKLIGHT_ENABLE)
process_backlight(keycode, record) &&
#endif
#if defined(LED_MATRIX_ENABLE)
process_led_matrix(keycode, record) &&
#endif
#ifdef STENO_ENABLE
process_steno(keycode, record) &&
#endif
Expand Down

0 comments on commit be101b0

Please sign in to comment.