aboutsummaryrefslogtreecommitdiff
path: root/users/arkag
diff options
context:
space:
mode:
authorAlexander Kagno <cwre@protonmail.com>2018-09-25 16:38:04 -0600
committerDrashna Jaelre <drashna@live.com>2018-09-25 15:38:04 -0700
commit61f95410666319ac5ef0cb3d533b820f45ae237c (patch)
treed952edfca10642a78960e0892b5883d475c4d6d4 /users/arkag
parent118e948e355b784b22f94378b5f85285e6dd4634 (diff)
downloadqmk_firmware-61f95410666319ac5ef0cb3d533b820f45ae237c.tar.gz
qmk_firmware-61f95410666319ac5ef0cb3d533b820f45ae237c.zip
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...
Diffstat (limited to 'users/arkag')
-rw-r--r--users/arkag/arkag.c238
-rw-r--r--users/arkag/arkag.h27
-rw-r--r--users/arkag/mechmini2.jpgbin0 -> 3548191 bytes
-rw-r--r--users/arkag/readme.md28
4 files changed, 159 insertions, 134 deletions
diff --git a/users/arkag/arkag.c b/users/arkag/arkag.c
index c716b5e93..a35e13ed6 100644
--- a/users/arkag/arkag.c
+++ b/users/arkag/arkag.c
@@ -1,5 +1,10 @@
1#include "arkag.h" 1#include "arkag.h"
2 2
3/*
4 Current Layout and Keeb:
5 https://github.com/arkag/qmk_firmware/blob/master/keyboards/mechmini/v2/keymaps/arkag/keymap.c
6*/
7
3// Start: Written by konstantin: vomindoraan 8// Start: Written by konstantin: vomindoraan
4#include <ctype.h> 9#include <ctype.h>
5#include <stdlib.h> 10#include <stdlib.h>
@@ -8,38 +13,68 @@
8void send_unicode_hex_string(const char *str) { 13void send_unicode_hex_string(const char *str) {
9 if (!str) { return; } // Saftey net 14 if (!str) { return; } // Saftey net
10 while (*str) { 15 while (*str) {
11 // Find the next code point (token) in the string 16 // Find the next code point (token) in the string
12 for (; *str == ' '; str++); 17 for (; *str == ' '; str++);
13 size_t n = strcspn(str, " "); // Length of the current token 18 size_t n = strcspn(str, " "); // Length of the current token
14 char code_point[n+1]; 19 char code_point[n+1];
15 strncpy(code_point, str, n); 20 strncpy(code_point, str, n);
16 code_point[n] = '\0'; // Make sure it's null-terminated 21 code_point[n] = '\0'; // Make sure it's null-terminated
17 22
18 // Normalize the code point: make all hex digits lowercase 23 // Normalize the code point: make all hex digits lowercase
19 for (char *p = code_point; *p; p++) { 24 for (char *p = code_point; *p; p++) {
20 *p = tolower(*p); 25 *p = tolower(*p);
21 } 26 }
22 27
23 // Send the code point as a Unicode input string 28 // Send the code point as a Unicode input string
24 unicode_input_start(); 29 unicode_input_start();
25 send_string(code_point); 30 send_string(code_point);
26 unicode_input_finish(); 31 unicode_input_finish();
27 str += n; // Move to the first ' ' (or '\0') after the current token 32 str += n; // Move to the first ' ' (or '\0') after the current token
28 } 33 }
29} 34}
30// End: Written by konstantin: vomindoraan 35// End: Written by konstantin: vomindoraan
31 36
32uint8_t current_os, mod_primary_mask, fade_delay; 37// Start: Written by Chris Lewis
33uint16_t flash_timer_one, flash_timer_two, 38#ifndef MIN
34 fade_timer_one, fade_timer_two, 39#define MIN(a,b) (((a)<(b))?(a):(b))
35 active_timer_one, active_timer_two, 40#endif
36 elapsed = 0, 41#ifndef MAX
42#define MAX(a,b) (((a)>(b))?(a):(b))
43#endif
44
45#define TYPING_SPEED_MAX_VALUE 200
46uint8_t typing_speed = 0;
47
48void velocikey_accelerate() {
49 if (typing_speed < TYPING_SPEED_MAX_VALUE) typing_speed += (TYPING_SPEED_MAX_VALUE / 50);
50}
51
52void velocikey_decelerate() {
53 static uint16_t decay_timer = 0;
54
55 if (timer_elapsed(decay_timer) > 500 || decay_timer == 0) {
56 if (typing_speed > 0) typing_speed -= 1;
57 //Decay a little faster at half of max speed
58 if (typing_speed > TYPING_SPEED_MAX_VALUE / 2) typing_speed -= 1;
59 //Decay even faster at 3/4 of max speed
60 if (typing_speed > TYPING_SPEED_MAX_VALUE / 4 * 3) typing_speed -= 3;
61 decay_timer = timer_read();
62 }
63}
64
65uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue) {
66 return MAX(minValue, maxValue - (maxValue - minValue) * ((float)typing_speed / TYPING_SPEED_MAX_VALUE));
67}
68// End: Written by Chris Lewis
69
70uint8_t current_os,
71 mod_primary_mask,
72 fade_interval,
37 num_extra_flashes_off = 0; 73 num_extra_flashes_off = 0;
38Color underglow, 74Color underglow,
39 flash_color, 75 flash_color,
40 saved_color, 76 saved_color,
41 hsv_none = {0,0,0}, 77 hsv_none = {0,0,0};
42 hsv_white = {0,0,127};
43flashState flash_state = no_flash; 78flashState flash_state = no_flash;
44fadeState fade_state = add_fade; 79fadeState fade_state = add_fade;
45activityState state = boot; 80activityState state = boot;
@@ -79,134 +114,103 @@ Color mod_color(Color current_color, bool should_add, uint8_t change_amount) {
79 return current_color; 114 return current_color;
80} 115}
81 116
82void reverse_fade (void) {
83 if (fade_state == add_fade){
84 fade_state = sub_fade;
85 } else {
86 fade_state = add_fade;
87 }
88}
89
90void check_state (void) { 117void check_state (void) {
91 static bool activated, deactivated, slept; 118 static uint16_t active_timer;
92 switch (state) { 119 if (!active_timer) {active_timer = timer_read();}
93 case active: 120 static bool activated, deactivated, slept;
94 if (!activated) { 121 switch (state) {
95 fade_delay = LED_FADE_DELAY; 122 case active:
96 reverse_fade(); 123 if (!activated) {
97 activated = true; 124 if (slept) {rgblight_mode_noeeprom(1);}
98 deactivated = false; 125 activated = true;
99 } 126 deactivated = false;
100 active_timer_two = timer_read(); 127 slept = false;
101 elapsed = active_timer_two - active_timer_one; 128 }
102 if (elapsed < INACTIVE_DELAY) {return;} 129 fade_interval = velocikey_match_speed(1, 25);
103 state = inactive; 130 if (timer_elapsed(active_timer) < INACTIVE_DELAY) {return;}
104 return; 131 active_timer = timer_read();
105 132 state = inactive;
106 case inactive: 133 return;
107 if (!deactivated) { 134
108 fade_delay = LED_FADE_DELAY * 2; 135 case inactive:
109 reverse_fade(); 136 if (!deactivated) {
110 deactivated = true; 137 deactivated = true;
111 slept = false; 138 activated = false;
112 activated = false; 139 slept = false;
113 } 140 }
114 active_timer_two = timer_read(); 141 velocikey_decelerate();
115 elapsed = active_timer_two - active_timer_one; 142 fade_interval = velocikey_match_speed(1, 25);
116 if (elapsed < SLEEP_DELAY) {return;} 143 if (timer_elapsed(active_timer) < SLEEP_DELAY) {return;}
117 state = sleeping; 144 state = sleeping;
118 return; 145 return;
119 146
120 case sleeping: 147 case sleeping:
121 if (!slept) { 148 if (!slept) {
122 fade_delay = LED_FADE_DELAY * 6; 149 rgblight_mode_noeeprom(4);
123 reverse_fade(); 150 slept = true;
124 slept = true; 151 activated = false;
125 deactivated = false; 152 deactivated = false;
126 activated = false; 153 }
127 } 154 return;
128 return; 155
129 156 case boot:
130 case boot: 157 return;
131 return; 158 }
132 }
133} 159}
134 160
135void fade_rgb (void) { 161void fade_rgb (void) {
136 static bool ran_once; 162 static uint16_t fade_timer;
137 if (flash_state != no_flash) {return;}
138 if (state == boot) {return;} 163 if (state == boot) {return;}
164 if (!fade_timer) {fade_timer = timer_read();}
165 if (timer_elapsed(fade_timer) < fade_interval) {return;}
139 switch (fade_state) { 166 switch (fade_state) {
140 case add_fade: 167 case add_fade:
141 if (!ran_once) {
142 fade_timer_one = timer_read();
143 ran_once = true;
144 }
145 fade_timer_two = timer_read();
146 elapsed = fade_timer_two - fade_timer_one;
147 if (elapsed < fade_delay) {return;}
148 if (underglow.h == 359) { 168 if (underglow.h == 359) {
149 fade_state = sub_fade; 169 fade_state = sub_fade;
150 return; 170 return;
151 } 171 }
152 underglow.h = underglow.h + 1; 172 underglow.h = underglow.h + 1;
153 set_color(underglow, false); 173 break;
154 // set_color_at(underglow, 0);
155 fade_timer_one = fade_timer_two;
156 return;
157 174
158 case sub_fade: 175 case sub_fade:
159 fade_timer_two = timer_read();
160 elapsed = fade_timer_two - fade_timer_one;
161 if (elapsed < fade_delay) {return;}
162 if (underglow.h == 0) { 176 if (underglow.h == 0) {
163 fade_state = add_fade; 177 fade_state = add_fade;
164 return; 178 return;
165 } 179 }
166 underglow.h = underglow.h - 1; 180 underglow.h = underglow.h - 1;
181 break;
182 }
183 fade_timer = timer_read();
184 if (flash_state == no_flash) {
167 set_color(underglow, false); 185 set_color(underglow, false);
168 // set_color_at(underglow, 0);
169 fade_timer_one = fade_timer_two;
170 return;
171 } 186 }
172} 187}
173 188
174void flash_rgb (void) { 189void flash_rgb (void) {
175 static bool ran_once; 190 static uint16_t flash_timer;
176 switch(flash_state) { 191 switch(flash_state) {
177 case no_flash: 192 case no_flash:
178 return; 193 return;
179 194
180 case flash_off: 195 case flash_off:
181 if (!ran_once) { 196 if (!flash_timer) {flash_timer = timer_read();}
182 set_color(hsv_none, false); 197 if (timer_elapsed(flash_timer) >= LED_FLASH_DELAY) {
183 flash_timer_one = timer_read();
184 ran_once = true;
185 flash_state = flash_on;
186 return;
187 }
188 flash_timer_two = timer_read();
189 elapsed = flash_timer_two - flash_timer_one;
190 if (elapsed >= LED_FLASH_DELAY) {
191 set_color(hsv_none, false); 198 set_color(hsv_none, false);
192 flash_timer_one = timer_read(); 199 flash_timer = timer_read();
193 flash_state = flash_on; 200 flash_state = flash_on;
194 } 201 }
195 return; 202 return;
196 203
197 case flash_on: 204 case flash_on:
198 flash_timer_two = timer_read(); 205 if (timer_elapsed(flash_timer) >= LED_FLASH_DELAY) {
199 elapsed = flash_timer_two - flash_timer_one;
200 if (elapsed >= LED_FLASH_DELAY) {
201 set_color(flash_color, false); 206 set_color(flash_color, false);
202 flash_timer_one = timer_read(); 207 flash_timer = timer_read();
203 if (num_extra_flashes_off > 0) { 208 if (num_extra_flashes_off > 0) {
204 flash_state = flash_off; 209 flash_state = flash_off;
205 num_extra_flashes_off--; 210 num_extra_flashes_off--;
206 } else { 211 } else {
207 set_color(underglow, false); 212 set_color(underglow, false);
208 flash_state = no_flash; 213 flash_state = no_flash;
209 ran_once = false;
210 } 214 }
211 } 215 }
212 return; 216 return;
@@ -239,8 +243,9 @@ void set_os (uint8_t os, bool update) {
239 mod_primary_mask = MOD_CTL_MASK; 243 mod_primary_mask = MOD_CTL_MASK;
240 } 244 }
241 set_color(underglow, update); 245 set_color(underglow, update);
242 flash_color = underglow; 246 flash_color = underglow;
243 flash_state = flash_off; 247 flash_state = flash_off;
248 state = boot;
244 num_extra_flashes_off = 1; 249 num_extra_flashes_off = 1;
245} 250}
246 251
@@ -462,7 +467,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
462 467
463 case M_REPO: 468 case M_REPO:
464 if (record->event.pressed) { 469 if (record->event.pressed) {
465 SEND_STRING("https://github.com/arkag/qmk_firmware/tree/master/keyboards/mechmini/v2/keymaps/arkag"); 470 SEND_STRING("https://github.com/qmk/qmk_firmware/tree/master/users/arkag");
466 } 471 }
467 return false; 472 return false;
468 473
@@ -505,10 +510,11 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
505 510
506 case KC_LSFT: 511 case KC_LSFT:
507 if (record->event.pressed) { 512 if (record->event.pressed) {
508 set_color(mod_color(underglow, true, 50), false); 513 save_color(underglow);
514 underglow = mod_color(underglow, true, 75);
509 SEND_STRING(SS_DOWN(X_LSHIFT)); 515 SEND_STRING(SS_DOWN(X_LSHIFT));
510 } else { 516 } else {
511 set_color(underglow, false); 517 reset_color();
512 SEND_STRING(SS_UP(X_LSHIFT)); 518 SEND_STRING(SS_UP(X_LSHIFT));
513 } 519 }
514 return false; 520 return false;
@@ -522,8 +528,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
522 528
523 default: 529 default:
524 if (record->event.pressed) { 530 if (record->event.pressed) {
525 active_timer_one = timer_read();
526 state = active; 531 state = active;
532 velocikey_accelerate();
527 } 533 }
528 return true; 534 return true;
529 } 535 }
diff --git a/users/arkag/arkag.h b/users/arkag/arkag.h
index 9c81e4487..a4672a8e8 100644
--- a/users/arkag/arkag.h
+++ b/users/arkag/arkag.h
@@ -25,26 +25,13 @@
25#define MOD_GUI_MASK (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI)) 25#define MOD_GUI_MASK (MOD_BIT(KC_LGUI) | MOD_BIT(KC_RGUI))
26#define MOD_SFT_MASK (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT)) 26#define MOD_SFT_MASK (MOD_BIT(KC_LSFT) | MOD_BIT(KC_RSFT))
27 27
28#define TAP_A LALT_T(KC_A)
29#define TAP_SCN RALT_T(KC_SCOLON)
30
31#define TAP_S LCTL_T(KC_S)
32#define TAP_L RCTL_T(KC_L)
33
34#define TAP_D LSFT_T(KC_D)
35#define TAP_K RSFT_T(KC_K)
36
37#define TAP_F LGUI_T(KC_F)
38#define TAP_J RGUI_T(KC_J)
39
40#define TAP_EQ LSFT_T(KC_EQUAL)
41#define TAP_5 RSFT_T(KC_5)
42
43#define LED_FLASH_DELAY 150 28#define LED_FLASH_DELAY 150
44#define LED_FADE_DELAY 10
45 29
46#define INACTIVE_DELAY 200 30#define ACCEL_DELAY 500
47#define SLEEP_DELAY 60000 31#define DEACCEL_DELAY 500
32
33#define INACTIVE_DELAY 250
34#define SLEEP_DELAY 180000
48 35
49enum { 36enum {
50 _QWERTY = 0, 37 _QWERTY = 0,
@@ -124,6 +111,10 @@ enum tapdances {
124 111
125void send_unicode_hex_string(const char *str); 112void send_unicode_hex_string(const char *str);
126 113
114void velocikey_accelerate(void);
115void velocikey_decelerate(void);
116uint8_t velocikey_match_speed(uint8_t minValue, uint8_t maxValue);
117
127void set_color (Color new, bool update); 118void set_color (Color new, bool update);
128void save_color(Color to_save); 119void save_color(Color to_save);
129void reset_color(void); 120void reset_color(void);
diff --git a/users/arkag/mechmini2.jpg b/users/arkag/mechmini2.jpg
new file mode 100644
index 000000000..611a0859c
--- /dev/null
+++ b/users/arkag/mechmini2.jpg
Binary files differ
diff --git a/users/arkag/readme.md b/users/arkag/readme.md
index 76a5c4525..c685892f8 100644
--- a/users/arkag/readme.md
+++ b/users/arkag/readme.md
@@ -1,3 +1,26 @@
1# Shot on Pixel 2 XL with Cheap Lamp at Work
2
3![mmm, tasty](mechmini2.jpg)
4
5# I don't know what I'm doing
6
7Some links:
8* [Layout File: Mech Mini 2](layout_mm2)
9* [Userspace Header](arkag_h)
10* [Userspace Main](arkag_c)
11
12Here's a list of some things I have working with my currently [keyboard](mm2_home):
13
14* Reactive (sort of) fading while typing, ported from [Velocikey](https://github.com/qmk/qmk_firmware/pull/3754).
15* OS Switching, storing to EEPROM
16* OS Specific Macros and Shortcuts(WIN+SHIFT+S for Windows and CMD+SHIFT+4 for MacOS)
17* Flashing RGB LED on OS change
18* Hex Unicode Macros dependent on OS(half works on Windows due to [WinCompose](https://github.com/SamHocevar/wincompose) not functioning properly just yet).
19* "Sleep" function activates after 3 minutes (breathing).
20* Markdown style macros for surround type __eve__ ~~ryw~~ *her* **eee** (apparently only certain places support underline and strikethrough ಠ__ಠ)
21
22# License Stuff
23
1Copyright 2018 arkag arkag@pm.me 24Copyright 2018 arkag arkag@pm.me
2 25
3This program is free software: you can redistribute it and/or modify 26This program is free software: you can redistribute it and/or modify
@@ -12,3 +35,8 @@ GNU General Public License for more details.
12 35
13You should have received a copy of the GNU General Public License 36You should have received a copy of the GNU General Public License
14along with this program. If not, see <http://www.gnu.org/licenses/>. 37along with this program. If not, see <http://www.gnu.org/licenses/>.
38
39[arkag_c]: /users/arkag/arkag.c
40[arkag_h]: /users/arkag/arkag.h
41[layout_mm2]: /keyboards/mechmini/v2/keymaps/arkag/keymap.c
42[mm2_home]: https://cartel.ltd/projects/mechmini2/