Moving LT(0, x) overrides to keymap level

This commit is contained in:
Blake Drayson 2024-10-15 19:40:21 +01:00
parent 7bf782d9d6
commit 60f6f30808
4 changed files with 89 additions and 135 deletions

View File

@ -28,95 +28,8 @@ The pixel graphics used here are from a combination of sources;
3. Key press indicator graphics were commissioned for this project and were designed by the
amazing https://corteximplant.com/@jadedtwin / https://www.jadedtwin.com/
*/
#include "daisy_v2.h"
enum my_keycodes {
ENCODER_PRESS = QK_USER,
};
#include "quantum.h"
void board_init(void) {
SYSCFG->CFGR1 |= SYSCFG_CFGR1_I2C1_DMA_RMP;
}
const uint8_t max_layer = 3;
uint8_t current_display_mode = 0;
bool hidden = false;
uint8_t key_pressed = 0;
/* EEPROM Stuct and function to allow init / saving of OLED mode */
typedef union {
uint32_t raw;
struct {
uint8_t oled_mode :8;
};
} kb_config_t;
kb_config_t kb_config;
void eeconfig_init_kb(void) {
//Init initial value and save to EEPROM.
kb_config.raw = 0;
eeconfig_update_kb(kb_config.raw);
}
/* End */
void keyboard_post_init_user(void) {
//Read user value and set current_display_mode.
kb_config.oled_mode = eeconfig_read_kb();
current_display_mode = kb_config.oled_mode;
//This is an adjustment to resolve the issue that occurs when there is a
//static colour underglow the first LED can be a different colour on first init.
rgblight_disable_noeeprom();
rgblight_enable_noeeprom();
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
if (!process_record_user(keycode, record)) {
return false;
}
#ifdef OLED_ENABLE
if (record->event.pressed) {
key_pressed++;
} else {
if (key_pressed)
key_pressed--;
}
#endif
switch(keycode) {
case LT(0, ENCODER_PRESS):
if (record->event.pressed) {
// on tap
if (record->tap.count) {
tap_code(KC_MUTE);
}
#ifdef OLED_ENABLE
// on hold
else {
hidden = false;
current_display_mode = (current_display_mode + 1) % 5;
// When mode changes update EEPROM.
kb_config.oled_mode = current_display_mode;
eeconfig_update_kb(kb_config.raw);
}
#endif
}
return false;
}
return true;
}
#ifdef OLED_ENABLE
uint32_t flash_timer = 0;
bool layer_changed = false;
// when the layer is changed, flash the layer number on the screen
layer_state_t layer_state_set_kb(layer_state_t state) {
flash_timer = timer_read();
layer_changed = true;
return layer_state_set_user(state);
}
#endif

View File

@ -1,46 +0,0 @@
/*Copyright 2024 Blake Drayson / Draytronics
Contact info@draytronics.co.uk
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
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
This code is inspired by and adapted from the code used in the Printed Pad by Noah Beidelman (@noahbei)
It also references the concept of glitching animations from Aleks (@aleksbrgt)
The pixel graphics used here are from a combination of sources;
1. Layer indicators are created by myself and free to use by anyone.
2. "Revengeday", "Cyber Cafe", "Cortex Implant" logos are used with kind permission of OBEY THE SYSTEM.
A collective of Fediverse instances and creatives. https://git.cyberwa.re/obey-the-system.
They are licenced as Non-Commercial and for use by members of the network, with attribution.
3. Key press indicator graphics were commissioned for this project and were designed by the
amazing https://corteximplant.com/@jadedtwin / https://www.jadedtwin.com/
*/
#pragma once
#include "quantum.h"
//for oled key press
extern uint8_t key_pressed;
// for changing oled display mode
extern uint8_t current_display_mode;
// for hidden animation toggle
extern bool hidden;
//for determining when the layer is changed and having a timer for how long we flash the layer
extern uint32_t flash_timer;
extern bool layer_changed;

View File

@ -90,3 +90,29 @@ const uint16_t PROGMEM encoder_map[][NUM_ENCODERS][NUM_DIRECTIONS] = {
[_CODE] = { ENCODER_CCW_CW(KC_VOLD, KC_VOLU) },
};
#endif
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch(keycode) {
case LT(0, ENCODER_PRESS):
if (record->event.pressed) {
// on tap
if (record->tap.count) {
tap_code(KC_MUTE);
}
#ifdef OLED_ENABLE
// on hold
else {
void oled_display_mode_step(void);
oled_display_mode_step();
// hidden = false;
// current_display_mode = (current_display_mode + 1) % 5;
// // When mode changes update EEPROM.
// kb_config.oled_mode = current_display_mode;
// eeconfig_update_kb(kb_config.raw);
}
#endif
}
return false;
}
return true;
}

View File

@ -28,9 +28,21 @@ The pixel graphics used here are from a combination of sources;
3. Key press indicator graphics were commissioned for this project and were designed by the
amazing https://corteximplant.com/@jadedtwin / https://www.jadedtwin.com/
*/
#include "daisy_v2.h"
#include "quantum.h"
#ifdef OLED_ENABLE
static uint8_t key_pressed = 0;
// for changing oled display mode
static uint8_t current_display_mode = 0;
// for hidden animation toggle
static bool hidden = false;
static uint32_t flash_timer = 0;
static bool layer_changed = false;
static void flash_current_layer(void);
uint8_t FRAME_DURATION = 100;
@ -41,6 +53,34 @@ uint8_t current_frame = 0;
static bool glitch = true;
static bool dirty = false;
/* EEPROM Stuct and function to allow init / saving of OLED mode */
typedef union {
uint32_t raw;
struct {
uint8_t oled_mode :8;
};
} kb_config_t;
kb_config_t kb_config;
void eeconfig_init_kb(void) {
//Init initial value and save to EEPROM.
kb_config.raw = 0;
eeconfig_update_kb(kb_config.raw);
}
/* End */
void keyboard_post_init_user(void) {
//Read user value and set current_display_mode.
kb_config.oled_mode = eeconfig_read_kb();
current_display_mode = kb_config.oled_mode;
//This is an adjustment to resolve the issue that occurs when there is a
//static colour underglow the first LED can be a different colour on first init.
rgblight_disable_noeeprom();
rgblight_enable_noeeprom();
}
static void render_CortexImplant_animation(void){
// 'CortexImplant_Clean', 128x32px
@ -2310,6 +2350,13 @@ static void render_daisy_logo(void){
bool logo_rendered = false;
void oled_display_mode_step(void) {
hidden = false;
current_display_mode = (current_display_mode + 1) % 5;
kb_config.oled_mode = current_display_mode;
eeconfig_update_kb(kb_config.raw);
}
bool oled_task_kb(void) {
if (!oled_task_user()) {
return false;
@ -2353,4 +2400,18 @@ bool oled_task_kb(void) {
}
return false;
}
bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
key_pressed = record->event.pressed;
return process_record_user(keycode, record);
}
// when the layer is changed, flash the layer number on the screen
layer_state_t layer_state_set_kb(layer_state_t state) {
flash_timer = timer_read();
layer_changed = true;
return layer_state_set_user(state);
}
#endif