summaryrefslogtreecommitdiff
path: root/keyboards/linworks/fave84h/keymaps/via
diff options
context:
space:
mode:
authorWolf Van Herreweghe <wolfvanh@gmail.com>2023-02-10 04:59:03 +0100
committerGitHub <noreply@github.com>2023-02-09 20:59:03 -0700
commit25ff06c01d84ba0d580e8a572e9b655cc555dcd9 (patch)
treebccd7bfee10f95210aa5a8f14c98794b6d977ccb /keyboards/linworks/fave84h/keymaps/via
parent5208361dcbd2bfd851a598964b88ac7da5e5340e (diff)
Move FAve 84H to data driven design + Via Custom UI (#19763)
Co-authored-by: Wolf <contact@vwolf.be>
Diffstat (limited to 'keyboards/linworks/fave84h/keymaps/via')
-rw-r--r--keyboards/linworks/fave84h/keymaps/via/keymap.c131
1 files changed, 126 insertions, 5 deletions
diff --git a/keyboards/linworks/fave84h/keymaps/via/keymap.c b/keyboards/linworks/fave84h/keymaps/via/keymap.c
index 0cc5a93d13..bfc3c69b8a 100644
--- a/keyboards/linworks/fave84h/keymaps/via/keymap.c
+++ b/keyboards/linworks/fave84h/keymaps/via/keymap.c
@@ -57,14 +57,135 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS
- ),
+ )
+};
+
+// Single Indicator memory layout
+typedef struct _indicator_config_t {
+ uint8_t h;
+ uint8_t s;
+ uint8_t v;
+ bool enabled;
+} indicator_config;
+
+// Board memory layout
+typedef struct _fave_config_t {
+ indicator_config caps;
+} fave_config;
+fave_config fave;
+
+void eeconfig_init_user(void) {
+ // Default values
+ fave.caps.h = 0;
+ fave.caps.s = 0;
+ fave.caps.v = RGB_MATRIX_MAXIMUM_BRIGHTNESS;
+ fave.caps.enabled = true;
+
+ // Write default value to EEPROM now
+ eeconfig_update_kb_datablock(&fave);
+}
+
+enum via_fave {
+ id_caps_indicator_enabled = 1,
+ id_caps_indicator_brightness = 2,
+ id_caps_indicator_color = 3
};
+//On Keyboard startup
+void keyboard_post_init_user(void) {
+ //Read our custom menu variables from memory
+ eeconfig_read_kb_datablock(&fave);
+}
+
bool rgb_matrix_indicators_user(void) {
- led_t host_leds = host_keyboard_led_state();
- if (host_leds.caps_lock) {
- rgb_matrix_set_color(12, 254, 189, 41); // set caps lock led color first number is index, R G B
+ if (fave.caps.enabled) {
+ // The rgb_matrix_set_color function needs an RGB code to work, so first the indicator color is cast to an HSV value and then translated to RGB
+ HSV hsv_caps_indicator_color = {fave.caps.h, fave.caps.s, fave.caps.v};
+ RGB rgb_caps_indicator_color = hsv_to_rgb(hsv_caps_indicator_color);
+ if (host_keyboard_led_state().caps_lock)
+ rgb_matrix_set_color(CAPS_INDICATOR_INDEX, rgb_caps_indicator_color.r, rgb_caps_indicator_color.g, rgb_caps_indicator_color.b);
+ }
+
+ return true;
+}
+
+void fave_config_set_value(uint8_t *data) {
+ // data = [ value_id, value_data ]
+ uint8_t *value_id = &(data[0]);
+ uint8_t *value_data = &(data[1]);
+
+ switch (*value_id) {
+ case id_caps_indicator_enabled: {
+ fave.caps.enabled = value_data[0];
+ break;
+ }
+ case id_caps_indicator_brightness: {
+ fave.caps.v = value_data[0];
+ break;
+ }
+ case id_caps_indicator_color: {
+ fave.caps.h = value_data[0];
+ fave.caps.s = value_data[1];
+ break;
+ }
}
- return false;
+}
+
+void fave_config_get_value(uint8_t *data) {
+ // data = [ value_id, value_data ]
+ uint8_t *value_id = &(data[0]);
+ uint8_t *value_data = &(data[1]);
+
+ switch (*value_id) {
+ case id_caps_indicator_enabled: {
+ value_data[0] = fave.caps.enabled;
+ break;
+ }
+ case id_caps_indicator_brightness: {
+ value_data[0] = fave.caps.v;
+ break;
+ }
+ case id_caps_indicator_color: {
+ value_data[0] = fave.caps.h;
+ value_data[1] = fave.caps.s;
+ break;
+ }
+ }
+}
+
+void fave_config_save(void) {
+ eeconfig_update_kb_datablock(&fave);
+}
+
+void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
+ // data = [ command_id, channel_id, value_id, value_data ]
+ uint8_t *command_id = &(data[0]);
+ uint8_t *channel_id = &(data[1]);
+ uint8_t *value_id_and_data = &(data[2]);
+
+ if (*channel_id == id_custom_channel) {
+ switch (*command_id) {
+ case id_custom_set_value: {
+ fave_config_set_value(value_id_and_data);
+ break;
+ }
+ case id_custom_get_value: {
+ fave_config_get_value(value_id_and_data);
+ break;
+ }
+ case id_custom_save: {
+ fave_config_save();
+ break;
+ }
+ default: {
+ // Unhandled message.
+ *command_id = id_unhandled;
+ break;
+ }
+ }
+ return;
+ }
+
+ *command_id = id_unhandled;
}