Skip to content

Commit

Permalink
Add user horrortroll in userspace (#19769)
Browse files Browse the repository at this point in the history
  • Loading branch information
HorrorTroll authored Apr 2, 2023
1 parent 27e6e27 commit d300811
Show file tree
Hide file tree
Showing 37 changed files with 258 additions and 1,280 deletions.
63 changes: 62 additions & 1 deletion keyboards/gopolar/gg86/gg86.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2021 Gopolar
/* Copyright 2023 Gopolar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,6 +20,11 @@
#include "lib/logo.h"

#ifdef RGB_MATRIX_ENABLE

#include <string.h>
#include <math.h>
#include <lib/lib8tion/lib8tion.h>

led_config_t g_led_config = { {
{ 87, 86, 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, 75, NO_LED, 74, 73, 72 },
{ 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71 },
Expand Down Expand Up @@ -50,6 +55,62 @@ led_config_t g_led_config = { {
// Underglow (88 -> 99)
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
} };

bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case RGB_TOG:
if (record->event.pressed) {
switch (rgb_matrix_get_flags()) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
rgb_matrix_set_color_all(0, 0, 0);
}
break;
case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
}
break;
case (LED_FLAG_UNDERGLOW): {
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_color_all(0, 0, 0);
}
break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
}
break;
}
}
return false;
}
return process_record_user(keycode, record);
}

bool rgb_matrix_indicators_kb(void) {
if (!rgb_matrix_indicators_user()) {
return false;
}

HSV hsv = rgb_matrix_config.hsv;
uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
hsv.h = time;
RGB rgb = hsv_to_rgb(hsv);

if (host_keyboard_led_state().caps_lock) {
rgb_matrix_set_color(25, rgb.r, rgb.g, rgb.b);
} else if (!(rgb_matrix_get_flags() & LED_FLAG_INDICATOR)) {
rgb_matrix_set_color(25, 0, 0, 0);
}

if (host_keyboard_led_state().scroll_lock) {
rgb_matrix_set_color(73, rgb.r, rgb.g, rgb.b);
} else if (!(rgb_matrix_get_flags() & LED_FLAG_INDICATOR)) {
rgb_matrix_set_color(73, 0, 0, 0);
}
return true;
}
#endif

#ifdef OLED_ENABLE
Expand Down
111 changes: 1 addition & 110 deletions keyboards/gopolar/gg86/keymaps/bongocat/keymap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2021 HorrorTroll <https://github.com/HorrorTroll>
/* Copyright 2023 HorrorTroll <https://github.com/HorrorTroll>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,11 +19,6 @@
// OLED animation
#include "oled/bongocat.h"

#include <string.h>
#include <math.h>

#include <lib/lib8tion/lib8tion.h>

// Each layer gets a name for readability, which is then used in the keymap matrix below.
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
// Layer names don't all need to be of the same length, obviously, and you can also skip them
Expand All @@ -34,22 +29,6 @@ enum layer_names {
_FN,
};

enum user_rgb_mode {
RGB_MODE_ALL,
RGB_MODE_KEYLIGHT,
RGB_MODE_UNDERGLOW,
RGB_MODE_NONE,
};

typedef union {
uint32_t raw;
struct {
uint8_t rgb_mode :8;
};
} user_config_t;

user_config_t user_config;

// enum layer_keycodes { };

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
Expand Down Expand Up @@ -121,94 +100,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
};

void keyboard_post_init_user(void) {
user_config.raw = eeconfig_read_user();
switch (user_config.rgb_mode) {
case RGB_MODE_ALL:
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
break;
case RGB_MODE_KEYLIGHT:
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
rgb_matrix_set_color_all(0, 0, 0);
break;
case RGB_MODE_UNDERGLOW:
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
break;
case RGB_MODE_NONE:
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_color_all(0, 0, 0);
break;
}
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case RGB_TOG:
if (record->event.pressed) {
switch (rgb_matrix_get_flags()) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
rgb_matrix_set_color_all(0, 0, 0);
user_config.rgb_mode = RGB_MODE_KEYLIGHT;
}
break;
case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
user_config.rgb_mode = RGB_MODE_UNDERGLOW;
}
break;
case (LED_FLAG_UNDERGLOW): {
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_color_all(0, 0, 0);
user_config.rgb_mode = RGB_MODE_NONE;
}
break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
user_config.rgb_mode = RGB_MODE_ALL;
}
break;
}
eeconfig_update_user(user_config.raw);
}
return false;
}

return true;
}

bool rgb_matrix_indicators_user(void) {
HSV hsv = rgb_matrix_config.hsv;
uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
hsv.h = time;
RGB rgb = hsv_to_rgb(hsv);

if ((rgb_matrix_get_flags() & LED_FLAG_KEYLIGHT)) {
if (host_keyboard_led_state().caps_lock) {
rgb_matrix_set_color(25, rgb.r, rgb.g, rgb.b);
}
if (host_keyboard_led_state().scroll_lock) {
rgb_matrix_set_color(73, rgb.r, rgb.g, rgb.b);
}
} else {
if (host_keyboard_led_state().caps_lock) {
rgb_matrix_set_color(25, rgb.r, rgb.g, rgb.b);
} else {
rgb_matrix_set_color(25, 0, 0, 0);
}
if (host_keyboard_led_state().scroll_lock) {
rgb_matrix_set_color(73, rgb.r, rgb.g, rgb.b);
} else {
rgb_matrix_set_color(73, 0, 0, 0);
}
}
return false;
}

#ifdef OLED_ENABLE
bool oled_task_user(void) {
led_t led_usb_state = host_keyboard_led_state();
Expand Down
2 changes: 0 additions & 2 deletions keyboards/gopolar/gg86/keymaps/bongocat/readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# Keymap with VIA and Bongo Cat on OLED

Keymap is default 87 qwerty, with TKL 7u-spacebar layout
111 changes: 1 addition & 110 deletions keyboards/gopolar/gg86/keymaps/default/keymap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright 2021 Gopolar
/* Copyright 2023 Gopolar
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -19,34 +19,13 @@
// OLED animation
#include "lib/wave.h"

#include <string.h>
#include <math.h>

#include <lib/lib8tion/lib8tion.h>

// Each layer gets a name for readability, which is then used in the keymap matrix below.
// The underscores don't mean anything - you can have a layer called STUFF or any other name.
// Layer names don't all need to be of the same length, obviously, and you can also skip them
// entirely and just use numbers.

// enum layer_names { };

enum user_rgb_mode {
RGB_MODE_ALL,
RGB_MODE_KEYLIGHT,
RGB_MODE_UNDERGLOW,
RGB_MODE_NONE,
};

typedef union {
uint32_t raw;
struct {
uint8_t rgb_mode :8;
};
} user_config_t;

user_config_t user_config;

// enum layer_keycodes { };

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
Expand Down Expand Up @@ -170,94 +149,6 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),
};

void keyboard_post_init_user(void) {
user_config.raw = eeconfig_read_user();
switch (user_config.rgb_mode) {
case RGB_MODE_ALL:
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
break;
case RGB_MODE_KEYLIGHT:
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
rgb_matrix_set_color_all(0, 0, 0);
break;
case RGB_MODE_UNDERGLOW:
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
break;
case RGB_MODE_NONE:
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_color_all(0, 0, 0);
break;
}
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case RGB_TOG:
if (record->event.pressed) {
switch (rgb_matrix_get_flags()) {
case LED_FLAG_ALL: {
rgb_matrix_set_flags(LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR);
rgb_matrix_set_color_all(0, 0, 0);
user_config.rgb_mode = RGB_MODE_KEYLIGHT;
}
break;
case (LED_FLAG_KEYLIGHT | LED_FLAG_MODIFIER | LED_FLAG_INDICATOR): {
rgb_matrix_set_flags(LED_FLAG_UNDERGLOW);
rgb_matrix_set_color_all(0, 0, 0);
user_config.rgb_mode = RGB_MODE_UNDERGLOW;
}
break;
case (LED_FLAG_UNDERGLOW): {
rgb_matrix_set_flags(LED_FLAG_NONE);
rgb_matrix_set_color_all(0, 0, 0);
user_config.rgb_mode = RGB_MODE_NONE;
}
break;
default: {
rgb_matrix_set_flags(LED_FLAG_ALL);
rgb_matrix_enable_noeeprom();
user_config.rgb_mode = RGB_MODE_ALL;
}
break;
}
eeconfig_update_user(user_config.raw);
}
return false;
}

return true;
}

bool rgb_matrix_indicators_user(void) {
HSV hsv = rgb_matrix_config.hsv;
uint8_t time = scale16by8(g_rgb_timer, qadd8(32, 1));
hsv.h = time;
RGB rgb = hsv_to_rgb(hsv);

if ((rgb_matrix_get_flags() & LED_FLAG_KEYLIGHT)) {
if (host_keyboard_led_state().caps_lock) {
rgb_matrix_set_color(25, rgb.r, rgb.g, rgb.b);
}
if (host_keyboard_led_state().scroll_lock) {
rgb_matrix_set_color(73, rgb.r, rgb.g, rgb.b);
}
} else {
if (host_keyboard_led_state().caps_lock) {
rgb_matrix_set_color(25, rgb.r, rgb.g, rgb.b);
} else {
rgb_matrix_set_color(25, 0, 0, 0);
}
if (host_keyboard_led_state().scroll_lock) {
rgb_matrix_set_color(73, rgb.r, rgb.g, rgb.b);
} else {
rgb_matrix_set_color(73, 0, 0, 0);
}
}
return false;
}

#ifdef OLED_ENABLE
static void render_layer_info(void) {
switch (get_highest_layer(layer_state)) {
Expand Down
Loading

0 comments on commit d300811

Please sign in to comment.