Created
January 22, 2020 13:59
-
-
Save burakcan/dbb292e47df2defaffd405669fec0e11 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include QMK_KEYBOARD_H | |
#include "quantum.h" | |
#include "adafruit_ble.h" | |
#include "git_macros.h" | |
#include "secrets.h" | |
#include "config.h" | |
#ifndef SAFE_RANGE_USER | |
# define SAFE_RANGE_USER SAFE_RANGE | |
#endif | |
enum custom_keycodes { LAUGH = SAFE_RANGE_USER, VBAT }; | |
// Tap Dance Declarations | |
enum { TD_Q_ESC = 0 }; | |
// Tap Dance Definitions | |
qk_tap_dance_action_t tap_dance_actions[] = {[TD_Q_ESC] = ACTION_TAP_DANCE_DOUBLE(KC_Q, KC_ESC)}; | |
enum { | |
_COLEMAK_DHm, | |
_LOWER, | |
_RAISE, | |
_ADJUST, | |
_GUI, | |
_ALT, | |
}; | |
// clang-format off | |
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = { | |
[_COLEMAK_DHm] = LAYOUT( \ | |
TD(TD_Q_ESC), KC_W, KC_F, KC_P, KC_B, LT(_RAISE, KC_SPC), KC_J, KC_L, KC_U, KC_Y, KC_BSPC, \ | |
LSFT_T(KC_A), LT(_ALT, KC_R), KC_S, KC_T, KC_G, KC_ENT, KC_M, KC_N, KC_E, LT(_ADJUST, KC_I), RSFT_T(KC_O), \ | |
LT(_GUI, KC_Z), LCTL_T(KC_X), LALT_T(KC_C), LGUI_T(KC_D), KC_V, LT(_LOWER, KC_SPC), LGUI_T(KC_K), KC_H, KC_SCLN, KC_COMM, KC_DOT \ | |
), | |
[_LOWER] = LAYOUT( \ | |
KC_GESC, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_QUOT, \ | |
_______, LAUGH , _______, _______, KC_SLSH, KC_BSLS, KC_UNDS, KC_PLUS, KC_LCBR, KC_RCBR, _______, \ | |
_______, _______, _______, _______, KC_TAB, _______, _______, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT \ | |
), | |
[_RAISE] = LAYOUT( \ | |
KC_GRV, KC_7, KC_8, KC_9, _______, _______, SECRET_1, SECRET_2, SECRET_3, SECRET_4, SECRET_5, \ | |
_______, KC_4, KC_5, KC_6, KC_QUES, KC_PIPE, KC_MINS, KC_EQL, KC_LBRC, KC_RBRC, _______, \ | |
KC_0, KC_1, KC_2, KC_3, _______, _______, _______, _______, _______, _______, _______ \ | |
), | |
[_ADJUST] = LAYOUT( \ | |
RESET, EEP_RST, DEBUG, _______, GIT_CHECKOUT_B, _______, _______, GIT_PUSH, GIT_PUSH_U, _______, GIT_PULL, \ | |
GIT_ADD_ALL, GIT_AMEND, GIT_STATUS, _______, _______, GIT_COMMIT, GIT_CHECKOUT_MASTER, _______, _______, _______, VBAT, \ | |
GIT_PUSH_FORCE, KC_VOLD, KC_VOLU, KC__MUTE, _______, _______, GIT_PULL_REBASE_MASTER, _______, OUT_AUTO, OUT_USB, OUT_BT \ | |
), | |
[_GUI] = LAYOUT( \ | |
KC_TILD, LGUI(KC_7), LGUI(KC_8), LGUI(KC_9), _______, _______, _______, _______, _______, _______, _______, \ | |
_______, LGUI(KC_4), LGUI(KC_5), LGUI(KC_6), _______, _______, _______, _______, _______, _______, _______, \ | |
_______, LGUI(KC_1), LGUI(KC_2), LGUI(KC_3), _______, _______, _______, LGUI(KC_LEFT), LGUI(KC_DOWN), LGUI(KC_UP), LGUI(KC_RGHT) \ | |
), | |
[_ALT] = LAYOUT( \ | |
KC_TILD, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \ | |
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, \ | |
_______, _______, _______, _______, _______, _______, _______, LALT(KC_LEFT), LALT(KC_DOWN), LALT(KC_UP), LALT(KC_RGHT) \ | |
), | |
}; | |
// clang-format on | |
// Follower keys | |
uint16_t last_keycode = _______; | |
bool check_follower_key(uint16_t keycode, keyrecord_t *record, uint16_t followed, uint16_t replacement, uint16_t modifier) { | |
if (last_keycode == followed && record->event.pressed) { | |
register_code(modifier); | |
register_code(replacement); | |
return true; | |
} else if (last_keycode == followed && !(record->event.pressed)) { | |
unregister_code(replacement); | |
unregister_code(modifier); | |
last_keycode = replacement; | |
return true; | |
} | |
return false; | |
} | |
bool process_record_follower_keys_user(uint16_t keycode, keyrecord_t *record) { | |
switch (keycode) { | |
case KC_COMM: | |
if (check_follower_key(keycode, record, KC_DOT, KC_SLSH, _______)) { | |
return true; | |
} | |
case KC_MINS: | |
if (check_follower_key(keycode, record, KC_EQL, KC_DOT, KC_LSFT)) { | |
return true; | |
} | |
default: | |
last_keycode = keycode; | |
return false; | |
} | |
} | |
static uint16_t random_value = 157; | |
const uint16_t random_chars[9] = {KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L}; | |
char vbatText[4]; | |
bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |
if (process_record_follower_keys_user(keycode, record)) { | |
return false; | |
} | |
switch (keycode) { | |
case VBAT: | |
if (record->event.pressed) { | |
sprintf(vbatText, "%lu", adafruit_ble_read_battery_voltage()); | |
send_string(vbatText); | |
} | |
return false; | |
case LAUGH: | |
if (record->event.pressed) { | |
uint8_t clockbyte = 0; | |
clockbyte = TCNT1 % 256; | |
uint8_t rval; | |
random_value = ((random_value + randadd) * randmul) % randmod; | |
uint8_t len = ((random_value ^ clockbyte) % 4) + 4; | |
for (uint8_t i = 0; i <= len; i++) { | |
random_value = ((random_value + randadd) * randmul) % randmod; | |
rval = (random_value ^ clockbyte) % 9; | |
register_code(random_chars[rval]); | |
unregister_code(random_chars[rval]); | |
} | |
} | |
return false; | |
case SECRET_1 ... SECRET_5: | |
if (record->event.pressed) { | |
send_string(secret[keycode - SECRET_1]); | |
} | |
return false; | |
case GIT_PULL ... GIT_STATUS: | |
if (record->event.pressed) { | |
send_string(git_macros[keycode - GIT_PULL]); | |
} | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment