aboutsummaryrefslogtreecommitdiff
path: root/users/xtonhasvim
diff options
context:
space:
mode:
authorxton <cmdpix@mac.com>2018-08-28 19:54:17 -0400
committerDrashna Jaelre <drashna@live.com>2018-08-28 16:54:17 -0700
commit3892829d74119b1fe771b4b51c665448a433da1e (patch)
tree7c871491e2ffd3dd0fc3adcf1fa83b2cce859cd4 /users/xtonhasvim
parent3c209830558c5911ed7446c026ba4d38fdbfe83e (diff)
downloadqmk_firmware-3892829d74119b1fe771b4b51c665448a433da1e.tar.gz
qmk_firmware-3892829d74119b1fe771b4b51c665448a433da1e.zip
Keymap: xtonhasvim updates (#3768)
* cherrypicking file changes just for updates * removed unused heat foo * avoid defining own min/max * add license * formatting
Diffstat (limited to 'users/xtonhasvim')
-rw-r--r--users/xtonhasvim/fancylighting.c167
-rw-r--r--users/xtonhasvim/fancylighting.h35
-rw-r--r--users/xtonhasvim/rules.mk1
-rw-r--r--users/xtonhasvim/xtonhasvim.c72
-rw-r--r--users/xtonhasvim/xtonhasvim.h9
5 files changed, 258 insertions, 26 deletions
diff --git a/users/xtonhasvim/fancylighting.c b/users/xtonhasvim/fancylighting.c
new file mode 100644
index 000000000..f4af5ec55
--- /dev/null
+++ b/users/xtonhasvim/fancylighting.c
@@ -0,0 +1,167 @@
1 /* Copyright 2015-2017 Christon DeWan
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifdef RGBLIGHT_ENABLE
18
19#include <math.h>
20
21#include "rgblight.h"
22#include "color.h"
23#include "fancylighting.h"
24
25
26__attribute__ ((weak))
27void matrix_scan_keymap(void) {
28 // override me, if you want.
29 return;
30}
31
32#define ABSDIFF(a,b) ((a)>(b)?(a)-(b):(b)-(a))
33
34#define FADE_BACK_TIME 500
35#define BREATH_FIRE_TIME 1000
36#define ANIMATION_STEP_INTERVAL 20
37#define POWER_KEY_OFFSET (RGBLED_NUM / 2)
38#define SPACE_OFFSET_MAX (RGBLED_NUM / 2)
39
40
41uint16_t effect_start_timer = 0;
42uint8_t user_rgb_mode = 0;
43LED_TYPE shadowed_led[RGBLED_NUM] = {0};
44
45void start_firey_return(void) {
46 user_rgb_mode = BREATH_FIRE;
47 effect_start_timer = timer_read();
48 for(uint8_t i = 0; i < RGBLED_NUM; i++) {
49 shadowed_led[i] = led[i];
50 }
51}
52
53/** 0---max
54 * [___]
55 * [__/]
56 * [_/\]
57 * [/\_]
58 * [\__]
59 * [___]
60 **/
61
62void set_color_for_offsets(uint16_t time_offset, uint16_t space_offset, uint8_t idx) {
63 float time_progress = (float)time_offset / BREATH_FIRE_TIME;
64 float space_progress = (float)space_offset / SPACE_OFFSET_MAX;
65 float progress = time_progress * 5.0 - space_progress;
66 if(progress > 1.0) {
67 progress -= 1.0;
68 progress /= 4.0;
69 progress = 1.0 - progress;
70 }
71 progress = fmax(0.0,progress);
72 progress *= progress; // squared!
73
74 float alpha = (time_progress + 0.1) * 7.0 - space_progress;
75 alpha = fmin(1.0, alpha*alpha);
76
77 LED_TYPE px[1] = {0};
78 sethsv((uint16_t)(fmod(time_progress * 1.5 + space_progress,1.0)*360), 255, (uint8_t)(progress*255),&px[0]);
79 led[idx].r = alpha * px[0].r + ( 1.0 - alpha) * shadowed_led[idx].r;
80 led[idx].g = alpha * px[0].g + ( 1.0 - alpha) * shadowed_led[idx].g;
81 led[idx].b = alpha * px[0].b + ( 1.0 - alpha) * shadowed_led[idx].b;
82}
83
84/**
85 * It's actually a rainbow: a fire curve didn't really look right.
86 * it's still cool, though!
87 */
88void rgb_mode_breath_fire(void) {
89 static uint16_t last_timer = 0;
90 if(!last_timer) last_timer = timer_read();
91 uint16_t this_timer = timer_read();
92
93 // too soon. don't spam updates
94 if(this_timer - last_timer < ANIMATION_STEP_INTERVAL) return;
95
96 uint16_t elapsed = this_timer - effect_start_timer;
97
98 last_timer = this_timer;
99 if(elapsed >= BREATH_FIRE_TIME) {
100 // complete
101 user_rgb_mode = FADE_BACK;
102 effect_start_timer = this_timer;
103 } else {
104 // linear fade
105 for(uint16_t i = 0; i < RGBLED_NUM; i++) {
106 uint16_t space_offset = ABSDIFF(i,POWER_KEY_OFFSET);
107 if(space_offset > SPACE_OFFSET_MAX) space_offset = RGBLED_NUM - space_offset;
108
109 set_color_for_offsets(elapsed, space_offset, i);
110 }
111 rgblight_set();
112 }
113}
114
115void rgb_mode_fade_back(void) {
116 static uint16_t last_timer = 0;
117 if(!last_timer) last_timer = timer_read();
118 uint16_t this_timer = timer_read();
119
120 // too soon. don't spam updates
121 if(this_timer - last_timer < ANIMATION_STEP_INTERVAL) return;
122
123 uint16_t elapsed = this_timer - effect_start_timer;
124
125 last_timer = this_timer;
126 float progress = (float)elapsed / FADE_BACK_TIME;
127 progress = fmin(1.0,progress);
128
129 for(uint8_t i = 0; i < RGBLED_NUM; i++) {
130 led[i].r = shadowed_led[i].r * progress;
131 led[i].g = shadowed_led[i].g * progress;
132 led[i].b = shadowed_led[i].b * progress;
133 }
134 rgblight_set();
135
136 if(elapsed >= FADE_BACK_TIME) user_rgb_mode = 0;
137}
138
139/** called when layer state or vstate has changed */
140__attribute__ ((weak))
141void set_state_leds(void) {
142 return;
143}
144
145void matrix_scan_user(void) {
146 static uint32_t last_layer = 0;
147 static uint32_t last_vstate = 0;
148 if(last_layer != layer_state || last_vstate != vstate) set_state_leds();
149 last_layer = layer_state;
150 last_vstate = vstate;
151
152 switch (user_rgb_mode) {
153 case BREATH_FIRE:
154 rgb_mode_breath_fire();
155 break;
156 case FADE_BACK:
157 rgb_mode_fade_back();
158 break;
159 }
160 matrix_scan_keymap();
161}
162
163#else
164
165void start_firey_return(void) {}
166
167#endif
diff --git a/users/xtonhasvim/fancylighting.h b/users/xtonhasvim/fancylighting.h
new file mode 100644
index 000000000..982010d3d
--- /dev/null
+++ b/users/xtonhasvim/fancylighting.h
@@ -0,0 +1,35 @@
1p /* Copyright 2015-2017 Christon DeWan
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef _fancy_lighting_h
18#define _fancy_lighting_h
19#ifdef RGBLIGHT_ENABLE
20
21#include "xtonhasvim.h"
22
23extern uint8_t user_rgb_mode;
24extern LED_TYPE shadowed_led[];
25
26void start_firey_return(void);
27
28#endif //_fancy_lighting_h
29
30enum xtonhasvim_rgbmodes {
31 BREATH_FIRE = 1,
32 FADE_BACK
33};
34
35#endif //RGBLIGHT_ENABLE
diff --git a/users/xtonhasvim/rules.mk b/users/xtonhasvim/rules.mk
index 3777917f8..a901bfcf6 100644
--- a/users/xtonhasvim/rules.mk
+++ b/users/xtonhasvim/rules.mk
@@ -1 +1,2 @@
1SRC += xtonhasvim.c 1SRC += xtonhasvim.c
2SRC += fancylighting.c
diff --git a/users/xtonhasvim/xtonhasvim.c b/users/xtonhasvim/xtonhasvim.c
index a2ff2fa31..5f6701830 100644
--- a/users/xtonhasvim/xtonhasvim.c
+++ b/users/xtonhasvim/xtonhasvim.c
@@ -15,6 +15,7 @@
15 */ 15 */
16 16
17#include "xtonhasvim.h" 17#include "xtonhasvim.h"
18#include "fancylighting.h"
18 19
19/************************************ 20/************************************
20 * helper foo 21 * helper foo
@@ -53,13 +54,13 @@ static void ALT(uint16_t keycode) {
53} 54}
54 55
55 56
56static uint16_t vstate = VIM_START; 57uint16_t vstate = VIM_START;
57static bool yank_was_lines = false; 58static bool yank_was_lines = false;
58static bool SHIFTED = false; 59static bool SHIFTED = false;
59static uint32_t mod_override_layer_state = 0; 60static uint32_t mod_override_layer_state = 0;
60static uint16_t mod_override_triggering_key = 0; 61static uint16_t mod_override_triggering_key = 0;
61 62
62static void edit(void) { vstate = VIM_START; layer_on(_EDIT); layer_off(_CMD); } 63static void edit(void) { vstate = VIM_START; layer_clear(); }
63#define EDIT edit() 64#define EDIT edit()
64 65
65 66
@@ -102,25 +103,54 @@ static void simple_movement(uint16_t keycode) {
102 } 103 }
103} 104}
104 105
106static void comma_period(uint16_t keycode) {
107 switch (keycode) {
108 case VIM_COMMA:
109 if (SHIFTED) {
110 // indent
111 CMD(KC_LBRACKET);
112 } else {
113 // toggle comment
114 CMD(KC_SLASH);
115 }
116 break;
117 case VIM_PERIOD:
118 if (SHIFTED) {
119 // outdent
120 CMD(KC_RBRACKET);
121 }
122 break;
123 }
124}
125
105__attribute__ ((weak)) 126__attribute__ ((weak))
106bool process_record_keymap(uint16_t keycode, keyrecord_t *record) { 127bool process_record_keymap(uint16_t keycode, keyrecord_t *record) {
107 return true; 128 return true;
108} 129}
109 130
110#define PASS_THRU process_record_keymap(keycode, record)
111
112bool process_record_user(uint16_t keycode, keyrecord_t *record) { 131bool process_record_user(uint16_t keycode, keyrecord_t *record) {
113 if(record->event.pressed && layer_state_is(_CMD) && IS_MOD(keycode)) { 132 /* keymap gets first whack */
133 if(!process_record_keymap(keycode, record)) return false;
134
135 /****** FIREY_RETURN *****/
136 if(record->event.pressed && keycode == FIREY_RETURN) {
137 start_firey_return();
138 TAP(KC_ENT);
139 }
140
141 /****** mod passthru *****/
142 if(record->event.pressed && layer_state_is(vim_cmd_layer()) && (IS_MOD(keycode) || keycode == LSFT(KC_LALT))) {
114 mod_override_layer_state = layer_state; 143 mod_override_layer_state = layer_state;
115 mod_override_triggering_key = keycode; 144 mod_override_triggering_key = keycode;
145 // TODO: change this to track key location instead
116 layer_clear(); 146 layer_clear();
117 return PASS_THRU; // let the event fall through... 147 return true; // let the event fall through...
118 } 148 }
119 if(mod_override_layer_state && !record->event.pressed && keycode == mod_override_triggering_key) { 149 if(mod_override_layer_state && !record->event.pressed && keycode == mod_override_triggering_key) {
120 layer_state_set(mod_override_layer_state); 150 layer_state_set(mod_override_layer_state);
121 mod_override_layer_state = 0; 151 mod_override_layer_state = 0;
122 mod_override_triggering_key = 0; 152 mod_override_triggering_key = 0;
123 return PASS_THRU; 153 return true;
124 } 154 }
125 155
126 if (VIM_START <= keycode && keycode <= VIM_ESC) { 156 if (VIM_START <= keycode && keycode <= VIM_ESC) {
@@ -132,7 +162,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
132 if (record->event.pressed) { 162 if (record->event.pressed) {
133 if(keycode == VIM_START) { 163 if(keycode == VIM_START) {
134 // entry from anywhere 164 // entry from anywhere
135 layer_on(_CMD); 165 layer_on(vim_cmd_layer());
136 vstate = VIM_START; 166 vstate = VIM_START;
137 167
138 // reset state 168 // reset state
@@ -176,7 +206,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
176 break; 206 break;
177 case VIM_D: 207 case VIM_D:
178 if(SHIFTED) { 208 if(SHIFTED) {
179 TAP(KC_K); 209 CTRL(KC_K);
180 } else { 210 } else {
181 vstate = VIM_D; 211 vstate = VIM_D;
182 } 212 }
@@ -300,19 +330,8 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
300 } 330 }
301 break; 331 break;
302 case VIM_COMMA: 332 case VIM_COMMA:
303 if(SHIFTED) {
304 // indent
305 CMD(KC_LBRACKET);
306 } else {
307 // toggle comment
308 CMD(KC_SLASH);
309 }
310 break;
311 case VIM_PERIOD: 333 case VIM_PERIOD:
312 if(SHIFTED) { 334 comma_period(keycode);
313 // outdent
314 CMD(KC_RBRACKET);
315 }
316 break; 335 break;
317 } 336 }
318 break; 337 break;
@@ -483,6 +502,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
483 TAP(KC_RIGHT); 502 TAP(KC_RIGHT);
484 vstate = VIM_START; 503 vstate = VIM_START;
485 break; 504 break;
505 case VIM_COMMA:
506 case VIM_PERIOD:
507 comma_period(keycode);
508 break;
486 default: 509 default:
487 // do nothing 510 // do nothing
488 break; 511 break;
@@ -539,6 +562,10 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
539 TAP(KC_RIGHT); 562 TAP(KC_RIGHT);
540 vstate = VIM_START; 563 vstate = VIM_START;
541 break; 564 break;
565 case VIM_COMMA:
566 case VIM_PERIOD:
567 comma_period(keycode);
568 break;
542 default: 569 default:
543 // do nothing 570 // do nothing
544 break; 571 break;
@@ -610,6 +637,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
610 } 637 }
611 return false; 638 return false;
612 } else { 639 } else {
613 return PASS_THRU; 640 return true;
614 } 641 }
615} 642}
643
diff --git a/users/xtonhasvim/xtonhasvim.h b/users/xtonhasvim/xtonhasvim.h
index 21b794c03..5ff4932a4 100644
--- a/users/xtonhasvim/xtonhasvim.h
+++ b/users/xtonhasvim/xtonhasvim.h
@@ -26,6 +26,7 @@ bool process_record_xtonhasvim(uint16_t keycode, keyrecord_t *record);
26 26
27enum xtonhasvim_keycodes { 27enum xtonhasvim_keycodes {
28 DUMMY = SAFE_RANGE, 28 DUMMY = SAFE_RANGE,
29 FIREY_RETURN, // kick off special effects
29 VIM_START, // bookend for vim states 30 VIM_START, // bookend for vim states
30 VIM_A, 31 VIM_A,
31 VIM_B, 32 VIM_B,
@@ -57,10 +58,10 @@ enum xtonhasvim_keycodes {
57 VIM_SAFE_RANGE // start other keycodes here. 58 VIM_SAFE_RANGE // start other keycodes here.
58}; 59};
59 60
60enum xtonhasvim_layers { 61// NOTE: YOU MUST DEFINE THIS
61 _EDIT = 12, 62extern uint8_t vim_cmd_layer(void);
62 _CMD 63
63}; 64extern uint16_t vstate;
64 65
65 66
66#endif 67#endif