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

Oled Timeout Update for KidBrazil Keymap #1

Merged
merged 12 commits into from
Dec 15, 2019
99 changes: 62 additions & 37 deletions keyboards/crkbd/keymaps/kidbrazil/keymap.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#include QMK_KEYBOARD_H

#ifdef RGBLIGHT_ENABLE
//Following line allows macro to read current RGB settings
extern rgblight_config_t rgblight_config;
#endif

// [Init Variables] ----------------------------------------------------------//
extern uint8_t is_master;
// Oled timer similar to Drashna's
static uint32_t oled_timer = 0;
// Boolean to store
bool eeprom_oled_enabled = false;

// [CRKBD layers Init] -------------------------------------------------------//
enum crkbd_layers {
_QWERTY,
_NUM,
Expand All @@ -15,6 +16,7 @@ enum crkbd_layers {
_WEAPON
};

// [Keymaps] -----------------------------------------------------------------//
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QWERTY] = LAYOUT(\
KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,\
Expand Down Expand Up @@ -52,32 +54,56 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
)
};

int RGB_current_mode;
//int RGB_current_mode;

// [Persistent Default Layer] ------------------------------------------------//
void persistent_default_layer_set(uint16_t default_layer) {
eeconfig_update_default_layer(default_layer);
default_layer_set(default_layer);
}

// void matrix_scan_user(void) {
// rgblight_config_t rgblight_config;
// rgblight_config.raw = eeconfig_read_rgblight();
// // Save LED State
// eeprom_oled_enabled = rgblight_config.enable;
// }

// [Process User Input] ------------------------------------------------------//
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
// Use process_record_keymap to reset timer on keypress
if (record->event.pressed) {
#ifdef OLED_DRIVER_ENABLE
oled_timer = timer_read32();
#endif
// Restore LEDs if they are enabled in eeprom
rgb_matrix_enable_noeeprom();
}
return true;
}

// [OLED Configuration] ------------------------------------------------------//
#ifdef OLED_DRIVER_ENABLE

// Set LED Rotation
// Init Oled and Rotate....
oled_rotation_t oled_init_user(oled_rotation_t rotation) {
if (!has_usb())
return OLED_ROTATION_180; // flips the display 180 to see it from my side
return rotation;
}

// Load logo from font
// Read logo from font file
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 display based on Layer
switch (biton32(layer_state)){
case _GAME:
case _WEAPON:
Expand All @@ -88,7 +114,7 @@ void render_separator(void) {
}
}

// Render Current Layer
// Render current layer state
void render_layer_state(void){
// If you want to change the display of OLED, you need to change here
switch (biton32(layer_state)){
Expand Down Expand Up @@ -167,36 +193,35 @@ void render_master_oled(void) {
}
}

// lave OLED scren (Right Hand)
void render_slave_oled(void) {
//now print logo
render_logo();
}

// OLED Task
void oled_task_user(void){
switch (USB_DeviceState) {
case DEVICE_STATE_Unattached:
case DEVICE_STATE_Powered:
case DEVICE_STATE_Suspended:
render_logo();
break;
default:
if (is_master) {
render_master_oled();
} else {
render_slave_oled();
}
}
// {OLED Task} -----------------------------------------------//
void oled_task_user(void) {
// Drashna style timeout for LED and OLED
if (timer_elapsed32(oled_timer) > 30000) {
oled_off();
rgb_matrix_disable_noeeprom();
return;
}
else {
oled_on();
}
// Show logo when USB dormant
switch (USB_DeviceState) {
case DEVICE_STATE_Unattached:
case DEVICE_STATE_Powered:
case DEVICE_STATE_Suspended:
render_logo();
break;
default:
if (is_master) {
render_master_oled();
} else {
render_slave_oled();
}
}
}
#endif

// Suspend / Wake -----------------
void suspend_power_down_kb(void) {
rgb_matrix_set_suspend_state(true);
oled_off();
}

void suspend_wakeup_init_user(void) {
rgb_matrix_set_suspend_state(false);
oled_on();
}
3 changes: 1 addition & 2 deletions keyboards/crkbd/keymaps/kidbrazil/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ RGB_MATRIX_ENABLE = WS2812
OLED_DRIVER_ENABLE = yes

# If you want to change the display of OLED, you need to change here
SRC += ./keyboards/crkbd/keymaps/kidbrazil/layer_state_reader.c \
./keyboards/crkbd/keymaps/kidbrazil/logo_reader.c \
SRC += ./keyboards/crkbd/keymaps/kidbrazil/logo_reader.c \
#./lib/rgb_state_reader.c \
#./lib/logo_reader.c \
#./lib/keylogger.c \
Expand Down