Keymap: Velocikey implemented at userspace, readme is more helpful (#3974)

* deleting arkag branch, forcibly moving changes over to master

* fade_color function added, not tested

* added half functions some stuff

* surround_type function implemented and working.

* added flashing function and removed fading, flashing supports infinite flashing along with controlled number flashes

* added a fade state machine and functionality

* build optimizations, changed fade to bounce between bounds rather than roll over, added a HALMAK layout

* changes to sleep breath function, changed how I will switch to HALMAK

* support for halmak added

* support for activity detection added, condensed fading and flashing state machines, removed support for HALMAK and COLEMAK because arkag is stupid

* changed sleep and inactive behaviors, now the color shifting reverses on state change, yay! save_color and reset_color are made to enable layer color changing to look cooler.

* reformatted some if statements in state detection

* changes to force fade to pause on boot, or plug in.

* Attempting to move over to userspace, pushing to repository for help

* userspace stuff....

* userspace stuff....

* layout changes, working userspace,

Removed left side shift and replaced it with a MT() for LSFT and SPC. Userspace seems to be working properly now! HURRAY

* Layout change

Removed space/shift and reset modifiers to what they were originally. Added homerow modifiers.

* Removed excessive tabs in files

* Moved mods on homerow around...

* changes recommended by @drashna

* removed homerow mods, more flashy lighting!

* changed delays for lighting.

* velocikey code retro fit into userspace to match typing speed

currently "working" but isn't as reactive as I want.

* Readme and other documentation hidden throughout code

* Added a pretty picture

* pretty picture actually added

* More readme updates

* Velocikey now working inside my userspace!

* Changed repo macro and fixed readme

* Removed media layer, moved media control to LAZY layer

* fixed more merge issues when I had to merge...
This commit is contained in:
Alexander Kagno 2018-09-25 16:38:04 -06:00 committed by Drashna Jaelre
parent 118e948e35
commit 61f9541066
5 changed files with 169 additions and 145 deletions

View file

@ -1,16 +1,21 @@
#include QMK_KEYBOARD_H
#include "arkag.h"
/*
Userspace:
https://github.com/arkag/qmk_firmware/blob/master/users/arkag/arkag.c
*/
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[_QWERTY] = LAYOUT_2u_space_ortho(
KC_ESC, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
KC_TAB, TAP_A, TAP_S, TAP_D, TAP_F, KC_G, KC_H, TAP_J, TAP_K, TAP_L, TAP_SCN, QUOTE,
XXXXXXX, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_ENT,
KC_TAB, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, QUOTE,
KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_ENT,
M_PMOD, LRALT, M_SMOD, LOWER, RAISE, KC_SPC, KC_SLSH, LAZY, KC_LEFT, KC_DOWN, KC_RGHT),
[_RAISE] = LAYOUT_2u_space_ortho(
GRAVE, KC_1, KC_2, THREE, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, _______,
_______, OBRACK, CBRACK, TAP_EQ, HYPHEN, _______, _______, KC_4, TAP_5, KC_6, _______, KC_NLCK,
_______, OBRACK, CBRACK, KC_EQL, HYPHEN, _______, _______, KC_4, KC_5, KC_6, _______, KC_NLCK,
_______, _______, _______, CEDILLA, _______, KC_COMM, KC_PDOT, KC_1, KC_2, KC_3, KC_PPLS, KC_PENT,
_______, _______, _______, KEEB, _______, _______, _______, M_OS, KC_PSLS, KC_PMNS, KC_PAST),
@ -18,7 +23,7 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
_______, _______, _______, _______, _______, _______, _______, M_ULIN, M_ITAL, _______, M_P_B, M_C_A_D,
_______, _______, STRIKE, _______, _______, _______, _______, _______, _______, _______, _______, _______,
KC_CAPS, KC_DEL, _______, _______, _______, M_BOLD, _______, _______, _______, _______, KC_PGUP, _______,
_______, _______, _______, _______, _______, MEDIA, KC_BSLS, M_CALC, KC_HOME, KC_PGDN, KC_END),
_______, _______, _______, _______, _______, _______, KC_BSLS, M_CALC, KC_HOME, KC_PGDN, KC_END),
[_KEEB] = LAYOUT_2u_space_ortho(
KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12,
@ -26,15 +31,9 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
RGB_M_P, RGB_TOG, RGB_MOD, RGB_VAI, RGB_VAD, RGB_HUI, RGB_HUD, RGB_SAI, RGB_SAD, _______, _______, _______,
RESET, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
[_MEDIA] = LAYOUT_2u_space_ortho(
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, KC_MPLY, KC_VOLU, KC_MUTE,
_______, _______, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT),
[_LAZY] = LAYOUT_2u_space_ortho(
_______, _______, _______, _______, _______, M_TM, _______, M_SNIPT, M_SHRUG, _______, _______, _______,
_______, _______, _______, _______, _______, M_TM, _______, M_SNIPT, M_SHRUG, _______, _______, KC_MUTE,
_______, _______, _______, _______, _______, M_GGT, _______, M_UF, M_LOD, M_REPO, _______, _______,
_______, _______, _______, _______, _______, _______, _______, M_TF, M_LENNY, _______, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, _______, _______),
_______, _______, _______, _______, _______, _______, _______, M_TF, M_LENNY, _______, KC_VOLU, KC_MPLY,
_______, _______, _______, _______, _______, _______, _______, _______, KC_MPRV, KC_VOLD, KC_MNXT),
};

View file

@ -1,5 +1,10 @@
#include "arkag.h"
/*
Current Layout and Keeb:
https://github.com/arkag/qmk_firmware/blob/master/keyboards/mechmini/v2/keymaps/arkag/keymap.c
*/
// Start: Written by konstantin: vomindoraan
#include <ctype.h>
#include <stdlib.h>
@ -8,38 +13,68 @@
void send_unicode_hex_string(const char *str) {
if (!str) { return; } // Saftey net
while (*str) {
// Find the next code point (token) in the string
for (; *str == ' '; str++);
size_t n = strcspn(str, " "); // Length of the current token
char code_point[n+1];
strncpy(code_point, str, n);
code_point[n] = '\0'; // Make sure it's null-terminated
// Find the next code point (token) in the string
for (; *str == ' '; str++);
size_t n = strcspn(str, " "); // Length of the current token
char code_point[n+1];
strncpy(code_point, str, n);
code_point[n] = '\0'; // Make sure it's null-terminated
// Normalize the code point: make all hex digits lowercase
for (char *p = code_point; *p; p++) {
*p = tolower(*p);
}
// Normalize the code point: make all hex digits lowercase
for (char *p = code_point; *p; p++) {
*p = tolower(*p);
}
// Send the code point as a Unicode input string
unicode_input_start();
send_string(code_point);
unicode_input_finish();
str += n; // Move to the first ' ' (or '\0') after the current token
// Send the code point as a Unicode input string
unicode_input_start();
send_string(code_point);
unicode_input_finish();
str += n; // Move to the first ' ' (or '\0') after the current token
}
}
// End: Written by konstantin: vomindoraan
uint8_t current_os, mod_primary_mask, fade_delay;
uint16_t flash_timer_one, flash_timer_two,
fade_timer_one, fade_timer_two,
active_timer_one, active_timer_two,
elapsed = 0,
// Start: Written by Chris Lewis
#ifndef MIN
#define MIN(a,b) (((a)<(b))?(a):(b))
#endif
#ifndef MAX
#define MAX(a,b) (((a)>(b))?(a):(b))
#endif
#define TYPING_SPEED_MAX_VALUE 200
uint8_t typing_speed = 0;
void velocikey_accelerate() {
if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 50);
}
void velocikey_decelerate() {
static uint16_t decay_timer = 0;
if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
if (typing_speed > 0) typing_speed -= 1;
//Decay a little faster at half of max speed
if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
//Decay even faster at 3/4 of max speed
if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 3;
decay_timer = timer_read();
}
}
uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
}
// End: Written by Chris Lewis
uint8_t current_os,
mod_primary_mask,
fade_interval,
num_extra_flashes_off = 0;
Color underglow,
flash_color,
saved_color,
hsv_none = {0,0,0},
hsv_white = {0,0,127};
hsv_none = {0,0,0};
flashState flash_state = no_flash;
fadeState fade_state = add_fade;
activityState state = boot;
@ -79,134 +114,103 @@ Color mod_color(Color current_color, bool should_add, uint8_t change_amount) {
return current_color;
}
void reverse_fade (void) {
if (fade_state == add_fade){
fade_state = sub_fade;
} else {
fade_state = add_fade;
void check_state (void) {
static uint16_t active_timer;
if (!active_timer) {active_timer = timer_read();}
static bool activated, deactivated, slept;
switch (state) {
case active:
if (!activated) {
if (slept) {rgblight_mode_noeeprom(1);}
activated = true;
deactivated = false;
slept = false;
}
fade_interval = velocikey_match_speed(1, 25);
if (timer_elapsed(active_timer) < INACTIVE_DELAY) {return;}
active_timer = timer_read();
state = inactive;
return;
case inactive:
if (!deactivated) {
deactivated = true;
activated = false;
slept = false;
}
velocikey_decelerate();
fade_interval = velocikey_match_speed(1, 25);
if (timer_elapsed(active_timer) < SLEEP_DELAY) {return;}
state = sleeping;
return;
case sleeping:
if (!slept) {
rgblight_mode_noeeprom(4);
slept = true;
activated = false;
deactivated = false;
}
return;
case boot:
return;
}
}
void check_state (void) {
static bool activated, deactivated, slept;
switch (state) {
case active:
if (!activated) {
fade_delay = LED_FADE_DELAY;
reverse_fade();
activated = true;
deactivated = false;
}
active_timer_two = timer_read();
elapsed = active_timer_two - active_timer_one;
if (elapsed < INACTIVE_DELAY) {return;}
state = inactive;
return;
case inactive:
if (!deactivated) {
fade_delay = LED_FADE_DELAY * 2;
reverse_fade();
deactivated = true;
slept = false;
activated = false;
}
active_timer_two = timer_read();
elapsed = active_timer_two - active_timer_one;
if (elapsed < SLEEP_DELAY) {return;}
state = sleeping;
return;
case sleeping:
if (!slept) {
fade_delay = LED_FADE_DELAY * 6;
reverse_fade();
slept = true;
deactivated = false;
activated = false;
}
return;
case boot:
return;
}
}
void fade_rgb (void) {
static bool ran_once;
if (flash_state != no_flash) {return;}
static uint16_t fade_timer;
if (state == boot) {return;}
if (!fade_timer) {fade_timer = timer_read();}
if (timer_elapsed(fade_timer) < fade_interval) {return;}
switch (fade_state) {
case add_fade:
if (!ran_once) {
fade_timer_one = timer_read();
ran_once = true;
}
fade_timer_two = timer_read();
elapsed = fade_timer_two - fade_timer_one;
if (elapsed < fade_delay) {return;}
if (underglow.h == 359) {
fade_state = sub_fade;
return;
}
underglow.h = underglow.h + 1;
set_color(underglow, false);
// set_color_at(underglow, 0);
fade_timer_one = fade_timer_two;
return;
break;
case sub_fade:
fade_timer_two = timer_read();
elapsed = fade_timer_two - fade_timer_one;
if (elapsed < fade_delay) {return;}
if (underglow.h == 0) {
fade_state = add_fade;
return;
}
underglow.h = underglow.h - 1;
break;
}
fade_timer = timer_read();
if (flash_state == no_flash) {
set_color(underglow, false);
// set_color_at(underglow, 0);
fade_timer_one = fade_timer_two;
return;
}
}
void flash_rgb (void) {
static bool ran_once;
static uint16_t flash_timer;
switch(flash_state) {
case no_flash:
return;
case flash_off:
if (!ran_once) {
if (!flash_timer) {flash_timer = timer_read();}
if (timer_elapsed(flash_timer) >= LED_FLASH_DELAY) {
set_color(hsv_none, false);
flash_timer_one = timer_read();
ran_once = true;
flash_state = flash_on;
return;
}
flash_timer_two = timer_read();
elapsed = flash_timer_two - flash_timer_one;
if (elapsed >= LED_FLASH_DELAY) {
set_color(hsv_none, false);
flash_timer_one = timer_read();
flash_timer = timer_read();
flash_state = flash_on;
}
return;
case flash_on:
flash_timer_two = timer_read();
elapsed = flash_timer_two - flash_timer_one;
if (elapsed >= LED_FLASH_DELAY) {
if (timer_elapsed(flash_timer) >= LED_FLASH_DELAY) {
set_color(flash_color, false);
flash_timer_one = timer_read();
flash_timer = timer_read();
if (num_extra_flashes_off > 0) {
flash_state = flash_off;
num_extra_flashes_off--;
} else {
set_color(underglow, false);
flash_state = no_flash;
ran_once = false;
}
}
return;
@ -239,8 +243,9 @@ void set_os (uint8_t os, bool update) {
mod_primary_mask = MOD_CTL_MASK;
}
set_color(underglow, update);
flash_color = underglow;
flash_state = flash_off;
flash_color = underglow;
flash_state = flash_off;
state = boot;
num_extra_flashes_off = 1;
}
@ -462,7 +467,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case M_REPO:
if (record->event.pressed) {
SEND_STRING("https://github.com/arkag/qmk_firmware/tree/master/keyboards/mechmini/v2/keymaps/arkag");
SEND_STRING("https://github.com/qmk/qmk_firmware/tree/master/users/arkag");
}
return false;
@ -505,10 +510,11 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
case KC_LSFT:
if (record->event.pressed) {
set_color(mod_color(underglow, true, 50), false);
save_color(underglow);
underglow = mod_color(underglow, true, 75);
SEND_STRING(SS_DOWN(X_LSHIFT));
} else {
set_color(underglow, false);
reset_color();
SEND_STRING(SS_UP(X_LSHIFT));
}
return false;
@ -522,8 +528,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
default:
if (record->event.pressed) {
active_timer_one = timer_read();
state = active;
velocikey_accelerate();
}
return true;
}

View file

@ -25,26 +25,13 @@
#define MOD_GUI_MASK (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))
#define MOD_SFT_MASK (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT))
#define TAP_A LALT_T(KC_A)
#define TAP_SCN RALT_T(KC_SCOLON)
#define TAP_S LCTL_T(KC_S)
#define TAP_L RCTL_T(KC_L)
#define TAP_D LSFT_T(KC_D)
#define TAP_K RSFT_T(KC_K)
#define TAP_F LGUI_T(KC_F)
#define TAP_J RGUI_T(KC_J)
#define TAP_EQ LSFT_T(KC_EQUAL)
#define TAP_5 RSFT_T(KC_5)
#define LED_FLASH_DELAY 150
#define LED_FADE_DELAY 10
#define INACTIVE_DELAY 200
#define SLEEP_DELAY 60000
#define ACCEL_DELAY 500
#define DEACCEL_DELAY 500
#define INACTIVE_DELAY 250
#define SLEEP_DELAY 180000
enum {
_QWERTY = 0,
@ -124,6 +111,10 @@ enum tapdances {
void send_unicode_hex_string(const char *str);
void velocikey_accelerate(void);
void velocikey_decelerate(void);
uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue);
void set_color (Color new, bool update);
void save_color(Color to_save);
void reset_color(void);

BIN
users/arkag/mechmini2.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 MiB

View file

@ -1,3 +1,26 @@
# Shot on Pixel 2 XL with Cheap Lamp at Work
![mmm, tasty](mechmini2.jpg)
# I don't know what I'm doing
Some links:
* [Layout File: Mech Mini 2](layout_mm2)
* [Userspace Header](arkag_h)
* [Userspace Main](arkag_c)
Here's a list of some things I have working with my currently [keyboard](mm2_home):
* Reactive (sort of) fading while typing, ported from [Velocikey](https://github.com/qmk/qmk_firmware/pull/3754).
* OS Switching, storing to EEPROM
* OS Specific Macros and Shortcuts(WIN+SHIFT+S for Windows and CMD+SHIFT+4 for MacOS)
* Flashing RGB LED on OS change
* Hex Unicode Macros dependent on OS(half works on Windows due to [WinCompose](https://github.com/SamHocevar/wincompose) not functioning properly just yet).
* "Sleep" function activates after 3 minutes (breathing).
* Markdown style macros for surround type __eve__ ~~ryw~~ *her* **eee** (apparently only certain places support underline and strikethrough ಠ__ಠ)
# License Stuff
Copyright 2018 arkag arkag@pm.me
This program is free software: you can redistribute it and/or modify
@ -12,3 +35,8 @@ 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/>.
[arkag_c]: /users/arkag/arkag.c
[arkag_h]: /users/arkag/arkag.h
[layout_mm2]: /keyboards/mechmini/v2/keymaps/arkag/keymap.c
[mm2_home]: https://cartel.ltd/projects/mechmini2/