Skip to content

Add haervig userspace and keymaps #13362

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

Merged
merged 18 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 19 additions & 0 deletions keyboards/dztech/dz65rgb/keymaps/haervig/keymap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include QMK_KEYBOARD_H
#include "haervig.h"

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT_65_ansi(
KC_GESC, DK_1, CU_2, DK_3, CU_4, DK_5, CU_6, CU_7, CU_8, CU_9, CU_0, CU_MINS, CU_EQL, CU_BSPC, KC_HOME,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, CU_LBRC, CU_RBRC, CU_BSLS, KC_PGUP,
CTL_T(KC_CAPS), KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, CU_SCLN, CU_QUOT, KC_ENT, KC_PGDN,
CU_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, CU_COMM, CU_DOT, CU_SLSH, CU_RSFT, KC_UP, KC_END,
KC_LCTL, KC_LALT, KC_LGUI, KC_SPC, MO(1), KC_RALT, KC_RCTL, KC_LEFT, KC_DOWN, KC_RGHT
),
[1] = LAYOUT_65_ansi(
_______, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______
)
};
3 changes: 3 additions & 0 deletions keyboards/dztech/dz65rgb/keymaps/haervig/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Userspace defines
DANISH_ENABLE = yes # Enable Custom US Ansi Keycodes for PC with Danish set as input language
RGB_MATRIX_ENABLE = no # Disable the ugly RGB light
2 changes: 2 additions & 0 deletions users/haervig/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#pragma once
#define TAPPING_TERM 200
227 changes: 227 additions & 0 deletions users/haervig/haervig.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#include "haervig.h"

#ifdef DANISH_ENABLE
// These indicate if left and right shift are physically pressed
bool lshift = false;
bool rshift = false;

// Interrupt and times for space cadet shift
bool lshiftp = false;
bool rshiftp = false;
uint16_t lshift_timer = 0;
uint16_t rshift_timer = 0;

// Number of items that are saved in prev_kcs
uint8_t prev_indx = 0;
// Used to save the last 6 actual keycodes activated by frankenkeycodes
uint16_t prev_kcs[6] = {0, 0, 0, 0, 0, 0};

// If true the deadkey characters grave and circonflexe are not automatically escaped
bool esct = false;

/*
Used to add a keycode to a prev_kcs to remember it.
When full the last code gets discarded and replaced by
the new one.
*/
void add_to_prev(uint16_t kc){
for (int i=0; i<prev_indx; i++){
if (kc == prev_kcs[i])
return;
}
if (prev_indx == 6){
for (int i=5; i>0; i--){
prev_kcs[i] = prev_kcs[i-1];
}
prev_kcs[0] = kc;
} else {
prev_kcs[prev_indx] = kc;
prev_indx++;
}
}

/*
Unregisters all codes saved in prev_kcs and resets prev_indx.
gets called on multiple occasions mainly when shift is released
and when frankenkeycodes are pressed. Prevents output of
wrong characters when really specific key combinations
that would never occur during normal usage are pressed.
*/
void unreg_prev(void){
if (prev_indx == 0)
return;
for (int i=0; i<prev_indx; i++){
unregister_code(prev_kcs[i]);
}
prev_indx = 0;
}
#endif

// Interrupt and times for Nav/Esc
bool navesc = false;
uint16_t navesc_timer = 0;

// If true Gui keys and Space Cadet Shift get disabled
bool game = false;

// Interrupts all timers
void timer_timeout(void){
#ifdef DANISH_ENABLE
lshiftp = false;
rshiftp = false;
#endif
navesc = false;
timer_timeout_keymap();
}

__attribute__((weak))
void timer_timeout_keymap(void){
}

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_LGUI:
case KC_RGUI:
if (record->event.pressed)
timer_timeout();
if (game)
return false;
else
return true;
case CU_NAV:
if(record->event.pressed) {
navesc = true;
navesc_timer = timer_read();
layer_on(_NAV);
} else {
if (timer_elapsed(navesc_timer) < TAPPING_TERM && navesc) {
register_code(KC_ESC);
unregister_code(KC_ESC);
}
layer_off(_NAV);
}
return false;

#ifdef DANISH_ENABLE
case CU_LSFT:
if(record->event.pressed) {
lshiftp = true;
lshift_timer = timer_read();
unregister_code(KC_LSFT);
register_code(KC_LSFT);
lshift = true;
} else {
if (timer_elapsed(lshift_timer) < TAPPING_TERM && lshiftp && !game) {
register_code(KC_LSFT);
register_code(KC_8);
unregister_code(KC_8);
unregister_code(KC_LSFT);
}
unreg_prev();
if (!rshift)
unregister_code(KC_LSFT);
lshift = false;
}
return false;
case CU_RSFT:
if(record->event.pressed) {
rshiftp = true;
rshift_timer = timer_read();
unregister_code(KC_LSFT);
register_code(KC_LSFT);
rshift = true;
} else {
if (timer_elapsed(rshift_timer) < TAPPING_TERM && rshiftp && !game) {
register_code(KC_LSFT);
register_code(KC_9);
unregister_code(KC_9);
unregister_code(KC_LSFT);
}
unreg_prev();
if (!lshift)
unregister_code(KC_LSFT);
rshift = false;
}
return false;
case CU_COMM:
SHIFT_NO(DK_COMM, KC_GRV)
case CU_DOT:
SHIFT_NORM(DK_DOT, KC_GRV)
case CU_SLSH:
SHIFT_ALL(DK_7, KC_MINS)
case CU_SCLN:
SHIFT_ALL(DK_COMM, DK_DOT)
case CU_QUOT:
SHIFT_NORM(DK_QUOT, DK_2)
case CU_2:
NORM_ALGR(DK_2, KC_NUHS)
case CU_4:
if (record->event.pressed) { \
timer_timeout(); \
if (lshift || rshift) { \
register_code(KC_LSFT); \
register_code(KC_ALGR); \
unregister_code(KC_3); \
register_code(KC_3); \
unregister_code(KC_3); \
} else { \
unregister_code(KC_4); \
register_code(KC_4); \
unregister_code(KC_4); \
} \
unregister_code(KC_ALGR); \
unregister_code(KC_LSFT); \
} \
return false;
case CU_6:
SHIFT_NORM(DK_6, KC_RBRC)
case CU_7:
SHIFT_NORM(DK_7, DK_6)
case CU_8:
SHIFT_NORM(DK_8, KC_NUHS)
case CU_9:
SHIFT_NORM(DK_9, DK_8)
case CU_0:
SHIFT_NORM(DK_0, DK_9)
case CU_MINS:
SHIFT_NORM(KC_SLSH, KC_SLSH)
case CU_EQL:
SHIFT_SWITCH(DK_0, DK_PLUS)
case CU_BSPC:
SHIFT_NO(KC_BSPC, KC_DEL)
case CU_LBRC:
NORM_ALGRSHIFT(DK_8, DK_8)
case CU_RBRC:
NORM_ALGRSHIFT(DK_9, DK_9)
case CU_BSLS:
ALGR_SWITCH(DK_7, DK_I)
case KC_LCTL:
case KC_RCTL:
if(!record->event.pressed) {
timer_timeout();
unregister_code(KC_Z);
unregister_code(KC_Y);
}
return true;
#endif

default:
if(record->event.pressed) {
timer_timeout();

#ifdef DANISH_ENABLE
if (lshift || rshift)
register_code(KC_LSFT);
else
unregister_code(KC_LSFT);
#endif

}
return process_record_keymap(keycode, record);
}
}

__attribute__((weak))
bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
return true;
}
Loading