From 484a9b12bc3961fc0dd9481d3cb734959db42191 Mon Sep 17 00:00:00 2001 From: Wilba Date: Tue, 21 Jan 2020 05:18:25 +1100 Subject: Add VIA support for QMK backlight, QMK RGBLight (#7911) * Add VIA support for QMK backlight, QMK RGBLight * clang-format changes --- keyboards/cannonkeys/satisfaction75/config.h | 3 ++ keyboards/cannonkeys/satisfaction75/led_custom.h | 2 + .../cannonkeys/satisfaction75/satisfaction75.c | 63 ++++++++++++++++++++++ 3 files changed, 68 insertions(+) (limited to 'keyboards/cannonkeys/satisfaction75') diff --git a/keyboards/cannonkeys/satisfaction75/config.h b/keyboards/cannonkeys/satisfaction75/config.h index 7a4354c8a7..69d02806e2 100644 --- a/keyboards/cannonkeys/satisfaction75/config.h +++ b/keyboards/cannonkeys/satisfaction75/config.h @@ -73,6 +73,9 @@ along with this program. If not, see . // 6 for 3x custom encoder settings, left, right, and press (18 bytes) #define VIA_EEPROM_CUSTOM_CONFIG_SIZE 21 +// VIA lighting is handled by the keyboard-level code +#define VIA_CUSTOM_LIGHTING_ENABLE + /* * Feature disable options * These options are also useful to firmware size reduction. diff --git a/keyboards/cannonkeys/satisfaction75/led_custom.h b/keyboards/cannonkeys/satisfaction75/led_custom.h index fe5c9e5dcf..d818b48ce9 100644 --- a/keyboards/cannonkeys/satisfaction75/led_custom.h +++ b/keyboards/cannonkeys/satisfaction75/led_custom.h @@ -3,3 +3,5 @@ void backlight_task(void); void breathing_interrupt_disable(void); void breathing_interrupt_enable(void); +void breathing_enable(void); +void breathing_disable(void); diff --git a/keyboards/cannonkeys/satisfaction75/satisfaction75.c b/keyboards/cannonkeys/satisfaction75/satisfaction75.c index 0fe09c384f..f92067c98f 100644 --- a/keyboards/cannonkeys/satisfaction75/satisfaction75.c +++ b/keyboards/cannonkeys/satisfaction75/satisfaction75.c @@ -55,6 +55,54 @@ backlight_config_t kb_backlight_config = { }; #ifdef VIA_ENABLE + +void backlight_get_value( uint8_t *data ) +{ + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + switch (*value_id) + { + case id_qmk_backlight_brightness: + { + // level / BACKLIGHT_LEVELS * 255 + value_data[0] = ((uint16_t)kb_backlight_config.level) * 255 / BACKLIGHT_LEVELS; + break; + } + case id_qmk_backlight_effect: + { + value_data[0] = kb_backlight_config.breathing ? 1 : 0; + break; + } + } +} + +void backlight_set_value( uint8_t *data ) +{ + uint8_t *value_id = &(data[0]); + uint8_t *value_data = &(data[1]); + switch (*value_id) + { + case id_qmk_backlight_brightness: + { + // level / 255 * BACKLIGHT_LEVELS + kb_backlight_config.level = ((uint16_t)value_data[0]) * BACKLIGHT_LEVELS / 255; + backlight_set(kb_backlight_config.level); + break; + } + case id_qmk_backlight_effect: + { + if ( value_data[0] == 0 ) { + kb_backlight_config.breathing = false; + breathing_disable(); + } else { + kb_backlight_config.breathing = true; + breathing_enable(); + } + break; + } + } +} + void raw_hid_receive_kb( uint8_t *data, uint8_t length ) { uint8_t *command_id = &(data[0]); @@ -139,6 +187,21 @@ void raw_hid_receive_kb( uint8_t *data, uint8_t length ) } break; } + case id_lighting_set_value: + { + backlight_set_value(command_data); + break; + } + case id_lighting_get_value: + { + backlight_get_value(command_data); + break; + } + case id_lighting_save: + { + backlight_config_save(); + break; + } default: { // Unhandled message. -- cgit v1.2.3