Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Keymap Update ] | crkbd/kidbrazil adding layer dependent RGB & better idle timeout. #7901

Merged
merged 19 commits into from
Jan 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 57 additions & 42 deletions keyboards/crkbd/keymaps/kidbrazil/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,49 +52,64 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#endif

#ifdef RGB_MATRIX_ENABLE
//# define RGB_MATRIX_KEYPRESSES // reacts to keypresses
// # define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses)
// # define RGB_DISABLE_AFTER_TIMEOUT 0 // number of ticks to wait until disabling effects
# define RGB_DISABLE_WHEN_USB_SUSPENDED true // turn off effects when suspended
# define RGB_MATRIX_FRAMEBUFFER_EFFECTS
// # define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 // limits the number of LEDs to process in an animation per task run (increases keyboard responsiveness)
// # define RGB_MATRIX_LED_FLUSH_LIMIT 16 // limits in milliseconds how frequently an animation will update the LEDs. 16 (16ms) is equivalent to limiting to 60fps (increases keyboard responsiveness)
# define RGB_MATRIX_MAXIMUM_BRIGHTNESS 150 // limits maximum brightness of LEDs to 150 out of 255. Higher may cause the controller to crash.
# define RGB_MATRIX_HUE_STEP 8
# define RGB_MATRIX_SAT_STEP 8
# define RGB_MATRIX_VAL_STEP 8
# define RGB_MATRIX_SPD_STEP 10
//# define RGB_MATRIX_KEYPRESSES // reacts to keypresses
// # define RGB_MATRIX_KEYRELEASES // reacts to keyreleases (instead of keypresses)
// # define RGB_DISABLE_AFTER_TIMEOUT 0 // number of ticks to wait until disabling effects
#define RGB_DISABLE_WHEN_USB_SUSPENDED true // turn off effects when suspended
#define RGB_MATRIX_FRAMEBUFFER_EFFECTS
// # define RGB_MATRIX_LED_PROCESS_LIMIT (DRIVER_LED_TOTAL + 4) / 5 // limits the number of LEDs to process in an animation per task run (increases keyboard responsiveness)
// # define RGB_MATRIX_LED_FLUSH_LIMIT 16 // limits in milliseconds how frequently an animation will update the LEDs. 16 (16ms) is equivalent to limiting to 60fps (increases keyboard responsiveness)
#define RGB_MATRIX_MAXIMUM_BRIGHTNESS 150 // limits maximum brightness of LEDs to 150 out of 255. Higher may cause the controller to crash.
#define RGB_MATRIX_HUE_STEP 4
#define RGB_MATRIX_SAT_STEP 4
#define RGB_MATRIX_VAL_STEP 4
#define RGB_MATRIX_SPD_STEP 10

/* Disable the animations you don&#39;t want/need. You will need to disable a good number of these *
* because they take up a lot of space. Disable until you can successfully compile your firmware. */
# define DISABLE_RGB_MATRIX_ALPHAS_MODS
# define DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
// # define DISABLE_RGB_MATRIX_BREATHING
# define DISABLE_RGB_MATRIX_CYCLE_ALL
# define DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
# define DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
# define DISABLE_RGB_MATRIX_CYCLE_OUT_IN
# define DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
# define DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
# define DISABLE_RGB_MATRIX_DUAL_BEACON
# define DISABLE_RGB_MATRIX_RAINBOW_BEACON
# define DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
# define DISABLE_RGB_MATRIX_RAINDROPS
# define DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
# define DISABLE_RGB_MATRIX_TYPING_HEATMAP
# define DISABLE_RGB_MATRIX_DIGITAL_RAIN
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
# define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
# define DISABLE_RGB_MATRIX_SPLASH
# define DISABLE_RGB_MATRIX_MULTISPLASH
# define DISABLE_RGB_MATRIX_SOLID_SPLASH
# define DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
/* Disable the animations you don&#39;t want/need. You will need to disable a good number of these *
* because they take up a lot of space. Disable until you can successfully compile your firmware. */
#define DISABLE_RGB_MATRIX_ALPHAS_MODS
#define DISABLE_RGB_MATRIX_GRADIENT_UP_DOWN
#define DISABLE_RGB_MATRIX_BREATHING
#define DISABLE_RGB_MATRIX_BAND_PINWHEEL_SAT
#define DISABLE_RGB_MATRIX_BAND_PINWHEEL_VAL
#define DISABLE_RGB_MATRIX_BAND_SAT
#define DISABLE_RGB_MATRIX_BAND_SPIRAL_SAT
#define DISABLE_RGB_MATRIX_BAND_SPIRAL_VAL
#define DISABLE_RGB_MATRIX_BAND_VAL
#define DISABLE_RGB_MATRIX_CYCLE_ALL
#define DISABLE_RGB_MATRIX_CYCLE_LEFT_RIGHT
#define DISABLE_RGB_MATRIX_CYCLE_OUT_IN
#define DISABLE_RGB_MATRIX_CYCLE_OUT_IN_DUAL
#define DISABLE_RGB_MATRIX_CYCLE_PINWHEEL
#define DISABLE_RGB_MATRIX_CYCLE_SPIRAL
#define DISABLE_RGB_MATRIX_CYCLE_UP_DOWN
#define DISABLE_RGB_MATRIX_DUAL_BEACON
#define DISABLE_RGB_MATRIX_JELLYBEAN_RAINDROPS
#define DISABLE_RGB_MATRIX_RAINBOW_MOVING_CHEVRON
#define DISABLE_RGB_MATRIX_RAINBOW_PINWHEELS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_CROSS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTICROSS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_NEXUS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTINEXUS
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_SIMPLE
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_WIDE
#define DISABLE_RGB_MATRIX_SOLID_REACTIVE_MULTIWIDE
#define DISABLE_RGB_MATRIX_SOLID_SPLASH
#define DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
#define DISABLE_RGB_MATRIX_SOLID_SPLASH
#define DISABLE_RGB_MATRIX_SOLID_MULTISPLASH
#define DISABLE_RGB_MATRIX_SPLASH
#define DISABLE_RGB_MATRIX_MULTISPLASH
#define DISABLE_RGB_MATRIX_SPLASH
#define DISABLE_RGB_MATRIX_MULTISPLASH
#endif
// Custom Font path
#define OLED_FONT_H "keyboards/crkbd/keymaps/kidbrazil/glcdfont.c"
#define OLED_DISABLE_TIMEOUT
10 changes: 10 additions & 0 deletions keyboards/crkbd/keymaps/kidbrazil/enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// [CRKBD layers Init] -------------------------------------------------------//
typedef enum {
_QWERTY,
_NUM,
_SYM,
_GAME,
_WEAPON
}CRKBD_LAYERS;

extern enum CRKBD_LAYERS crkbd_layers;
149 changes: 57 additions & 92 deletions keyboards/crkbd/keymaps/kidbrazil/keymap.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include QMK_KEYBOARD_H
#include "enums.h"
#include "layer.h"

// [Init Variables] ----------------------------------------------------------//
extern uint8_t is_master;
Expand All @@ -9,15 +11,6 @@ bool user_led_enabled = true;
// Boolean to store the master LED clear so it only runs once.
bool master_oled_cleared = false;

// [CRKBD layers Init] -------------------------------------------------------//
enum crkbd_layers {
_QWERTY,
_NUM,
_SYM,
_GAME,
_WEAPON
};

// [Keymaps] -----------------------------------------------------------------//
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QWERTY] = LAYOUT(
Expand All @@ -36,8 +29,8 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {

[_SYM] = LAYOUT(
KC_ESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
LSFT_T(KC_TAB), RGB_TOG, RGB_MOD, RGB_HUI, RGB_SAI, RGB_VAI, KC_MINS, KC_EQL, KC_LCBR, KC_RCBR, KC_PIPE, KC_GRV,
KC_LCTL, RGB_VAD, RGB_RMOD, RGB_HUD, RGB_SAD, TG(_GAME), KC_UNDS, KC_PLUS, KC_LBRC, KC_RBRC, KC_BSLS, KC_TILD,
LSFT_T(KC_TAB), RGB_TOG, KC_MPLY, KC_MUTE, KC_VOLU, KC_VOLD, KC_MINS, KC_EQL, KC_LCBR, KC_RCBR, KC_PIPE, KC_GRV,
KC_LCTL, KC_CALC, KC_MYCM, KC_MPRV, KC_MNXT, TG(_GAME), KC_UNDS, KC_PLUS, KC_LBRC, KC_RBRC, KC_BSLS, KC_TILD,
LGUI_T(KC_PGUP), KC_TRNS, KC_SPC, KC_ENT, KC_TRNS, LALT_T(KC_PGDN)
),

Expand All @@ -51,7 +44,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_WEAPON] = LAYOUT(
KC_ESC, KC_1, KC_2, KC_3, KC_4, KC_5, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_LSFT, KC_A, KC_S, KC_D, KC_F, KC_6, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_LCTL, KC_Z, KC_X, KC_C, KC_V, KC_7, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,
KC_TRNS, KC_LCTL, KC_Z, KC_X, KC_C, KC_V, KC_7, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, EEP_RST,
KC_TRNS, KC_TAB, KC_TRNS, KC_SPC, KC_TRNS, KC_TRNS, KC_TRNS
)
};
Expand All @@ -61,23 +54,24 @@ void keyboard_post_init_user(void) {
// Set RGB to known state
rgb_matrix_enable_noeeprom();
rgb_matrix_set_color_all(RGB_GREEN);
rgblight_mode_noeeprom(RGBLIGHT_MODE_STATIC_LIGHT);
user_led_enabled = true;

}
// [Process User Input] ------------------------------------------------------//
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
// Handle RGB Changes sans eeprom - necessary due to the layer dependent RGB color
// changes in marrix_scan_user
case RGB_TOG:
if (record->event.pressed) {
// Toggle matrix on key press
user_led_enabled ? rgb_matrix_disable_noeeprom() : rgb_matrix_enable_noeeprom();
} else {
// Flip User_led_enabled variable on key release
user_led_enabled = !user_led_enabled;
}
return false; // Skip all further processing of this key
if (record->event.pressed) {
// Toggle matrix on key press
user_led_enabled ? rgb_matrix_disable_noeeprom() : rgb_matrix_enable_noeeprom();
// Toggle boolean flag
user_led_enabled = !user_led_enabled;
}
return false;
default:
// Use process_record_keymap to reset timer on all other keypresses
// Use process_record_keymap to reset timer on all other keypresses to awaken from idle.
if (record->event.pressed) {
#ifdef OLED_DRIVER_ENABLE
oled_timer = timer_read32();
Expand All @@ -91,9 +85,47 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
}

// [Matrix Scan] ------------------------------------------------------------//
void matrix_scan_user(void) {
// Iddle timer to return to default layer if left on game layer
if (timer_elapsed32(oled_timer) > 380000 && timer_elapsed32(oled_timer) < 479999) {
// Reset layer in case it got left on _GAME
// This prevents the issue where the master side sometimes wont switch off as expected
// in the next step.
if (get_highest_layer(layer_state) == _GAME) {
layer_off(_GAME);
layer_on(_QWERTY);
}
return;
}
// Timeout to turn off LEDs
else if (timer_elapsed32(oled_timer) > 480000) {
rgb_matrix_disable_noeeprom();
return;
}
// Set RGB Matrix color based on layers
if (user_led_enabled) {
switch (get_highest_layer(layer_state)){
case _GAME:
rgb_matrix_set_color_all(RGB_PURPLE);
break;
case _NUM:
case _SYM:
case _QWERTY:
rgb_matrix_set_color_all(RGB_GREEN);
break;
default:
rgb_matrix_set_color_all(RGB_GREEN);
break;

}
} else {
rgb_matrix_disable_noeeprom();
return;
}
}
// [OLED Configuration] ------------------------------------------------------//
#ifdef OLED_DRIVER_ENABLE

// Init Oled and Rotate....
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (!has_usb())
Expand All @@ -105,74 +137,6 @@ oled_rotation_t oled_init_user(oled_rotation_t rotation) {
const char *read_logo(void);

// {OLED helpers} -----------------------------------------------//

// Render Blank Space
void render_space(void) {
oled_write_ln_P(PSTR(" "), false);
}

// Render separator lines for oled display
void render_separator(void) {
switch (get_highest_layer(layer_state)){
case _GAME:
case _WEAPON:
oled_write_ln_P(PSTR("===================="), false);
break;
default:
oled_write_ln_P(PSTR("++++++++++++++++++++"), false);
}
}

// Render current layer state
void render_layer_state(void){
// If you want to change the display of OLED, you need to change here
switch (get_highest_layer(layer_state)){
case _QWERTY:
oled_write_ln_P(PSTR("| MODE | QWRTY ]"), false);
break;
case _NUM:
oled_write_ln_P(PSTR("| MODE | NUMBERS ]"), false);
break;
case _SYM:
oled_write_ln_P(PSTR("| MODE | SYMBOLS ]"), false);
break;
case _GAME:
oled_write_ln_P(PSTR("| G A M E ]"), false);
break;
case _WEAPON:
oled_write_ln_P(PSTR("| W E A P O N ]"), false);
break;
default:
oled_write_ln_P(PSTR("| MODE | UNDEF ]"), false);
}
}

// Render USB State
void render_usb_state(void) {
switch (USB_DeviceState) {
case DEVICE_STATE_Unattached:
oled_write_ln_P(PSTR("| USB | FREE ]"), false);
break;
case DEVICE_STATE_Suspended:
oled_write_ln_P(PSTR("| USB | SLEEP ]"), false);
break;
case DEVICE_STATE_Configured:
oled_write_ln_P(PSTR("| USB | READY ]"), false);
break;
case DEVICE_STATE_Powered:
oled_write_ln_P(PSTR("| USB | PWRD ]"), false);
break;
case DEVICE_STATE_Default:
oled_write_ln_P(PSTR("| USB | DFLT ]"), false);
break;
case DEVICE_STATE_Addressed:
oled_write_ln_P(PSTR("| USB | ADDRS ]"), false);
break;
default:
oled_write_ln_P(PSTR("| USB | INVALID ]"), false);
}
}

// Render Logo
void render_logo(void) {
oled_write(read_logo(), false);
Expand Down Expand Up @@ -209,7 +173,8 @@ void render_slave_oled(void) {

// {OLED Task} -----------------------------------------------//
void oled_task_user(void) {
if (timer_elapsed32(oled_timer) > 80000 && timer_elapsed32(oled_timer) < 479999) {
// First time out switches to logo as first indication of iddle.
if (timer_elapsed32(oled_timer) > 100000 && timer_elapsed32(oled_timer) < 479999) {
// Render logo on both halves before full timeout
if (is_master && !master_oled_cleared) {
// Clear master OLED once so the logo renders properly
Expand Down
69 changes: 69 additions & 0 deletions keyboards/crkbd/keymaps/kidbrazil/layer.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#include QMK_KEYBOARD_H
#include "enums.h"

// Render Blank Space
void render_space(void) {
oled_write_ln_P(PSTR(" "), false);
}

// Render separator lines for oled display
void render_separator(void) {
switch (get_highest_layer(layer_state)){
case _GAME:
case _WEAPON:
oled_write_ln_P(PSTR("===================="), false);
break;
default:
oled_write_ln_P(PSTR("++++++++++++++++++++"), false);
}
}

// Render current layer state
void render_layer_state(void){
// If you want to change the display of OLED, you need to change here
switch (get_highest_layer(layer_state)){
case _QWERTY:
oled_write_ln_P(PSTR("| MODE | QWRTY ]"), false);
break;
case _NUM:
oled_write_ln_P(PSTR("| MODE | NUMBERS ]"), false);
break;
case _SYM:
oled_write_ln_P(PSTR("| MODE | SYMBOLS ]"), false);
break;
case _GAME:
oled_write_ln_P(PSTR("| G A M E ]"), false);
break;
case _WEAPON:
oled_write_ln_P(PSTR("| W E A P O N ]"), false);
break;
default:
oled_write_ln_P(PSTR("| MODE | UNDEF ]"), false);
}
}

// Render USB State
void render_usb_state(void) {
switch (USB_DeviceState) {
case DEVICE_STATE_Unattached:
oled_write_ln_P(PSTR("| USB | FREE ]"), false);
break;
case DEVICE_STATE_Suspended:
oled_write_ln_P(PSTR("| USB | SLEEP ]"), false);
break;
case DEVICE_STATE_Configured:
oled_write_ln_P(PSTR("| USB | READY ]"), false);
break;
case DEVICE_STATE_Powered:
oled_write_ln_P(PSTR("| USB | PWRD ]"), false);
break;
case DEVICE_STATE_Default:
oled_write_ln_P(PSTR("| USB | DFLT ]"), false);
break;
case DEVICE_STATE_Addressed:
oled_write_ln_P(PSTR("| USB | ADDRS ]"), false);
break;
default:
oled_write_ln_P(PSTR("| USB | INVALID ]"), false);
}
}
Loading