]> git.donarmstrong.com Git - qmk_firmware.git/blob - keyboards/handwired/frenchdev/keymaps/default/keymap.c
506383a1bbafa19466f3d6681847d6f47a6ea67c
[qmk_firmware.git] / keyboards / handwired / frenchdev / keymaps / default / keymap.c
1 #include QMK_KEYBOARD_H
2 #include "mousekey.h"
3 #include "keymap_bepo.h"
4
5
6 // Each layer gets a name for readability, which is then used in the keymap matrix below.
7 // The underscores don't mean anything - you can have a layer called STUFF or any other name.
8 #define _BASE 0
9 #define _SYMBOLS 1
10 #define _MEDIA 2
11 #define _TRNS 8
12
13 #define PEDAL_DELAY 250
14 #define KEY_DELAY 130
15
16 enum macros {
17     M_LP,   // left pedal
18     M_RP,   // right pedal
19     M_SF,   // shift
20     M_SFS,  // shift and space
21     M_L1E,  // L1 and space
22     L2INS,  // L2 and insert
23     L2LOC,  // Lock L2
24     M_UN,   // undo
25     M_CUT,  // cut
26     M_CP,   // copy
27     M_PS,   // paste
28     M_SE,   // search
29     M_SFU,  // shift and underscore
30 };
31
32 static uint16_t key_timer_left_pedal;
33 static uint16_t key_timer_right_pedal;
34 static uint16_t key_timer_shift;
35 static uint16_t key_timer_1;
36 static uint16_t key_timer_2;
37
38 static uint16_t shift_count = 0; //this is used to keep track of shift state and avoid inserting non breakable space
39 static uint16_t l2_locked = 0; //this indicate wether L2 is locked
40
41 #define BP_CBSP  CTL_T(KC_BSPC)
42 #define BP_CDEL  CTL_T(KC_DEL)
43
44 //layout : http://www.keyboard-layout-editor.com/#/gists/4480e3ab8026eb7c710a7e22203ef4aa
45 const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
46 /* base
47  *   left foot clicked is right click
48  *   left foot pressed is layer 2
49  *   right foot clicked is left click
50  *   right foot pressed is layer 1 + scroll lock (used with autohotkey for easier scrolling with trackballs)
51  *                      ,------.                                    ..                                    ,------.                      *
52  *               ,------|  F3  |-------------.                      ..                      ,-------------|  F10 |------.               *
53  *        ,------|  F2  |------|  F4  |  F5  |------.               ..               ,------|  F8  |  F9  |------| F11  |------.        *
54  *        |  F1  |------| »/3  |------|------|  F6  |               ..               |  F7  |------|------| -/8  |------|  F12 |        *
55  * ,------+------| «/2  |------|  (/4 | )/5  |------|               ..               |------| @/6  | +/7  |------| //9  |------+------. *
56  * |  ESC | "/1  |------|  O   |------|------|  ¨   |               ..               |  ^   |------|------|  D   |------| * /0 |BCKSP | *
57  * |------+------|  É   |------|  P   |  È   |------|               ..               |------|  K   |  V   |------|  L   |------+------| *
58  * | TAB  |  B   |------|  E   |------|------|  _   |               ..               | =/°  |------|------|  S   |------|  J   |ENTER | *
59  * |------+------|  U   |------|  I   |  F   |------|               ..               |------|  C   |  T   |------|  R   |------+------| *
60  * | `    |  A   |------|  Y   |------|------|  ;   |               ..               |  !   |------|------|  UP  |------|  N   |  '/? | *
61  * |------+------|  À   |------|  X   |  W   |------|-------------. .. .-------------|------|  M   |  G   |------|  H   |------+------| *
62  * | SHIFT|  Z   |------|  .   |------|------|sp/sh |bsp/ct|L2/ins| .. |L2lock|del/CT|sp/sh |------|------| DOWN |------|  Q   |SHIFT | *
63  * |------+------|  /   |------|  ,   | space|------|------|------  ..  ------|------|------| L1/sp| LEFT |------|  UP  |------+------| *
64  * | CTRL | win  |------/      \-------------| L1   | alt  |        ..        | CAPS | L1   |-------------/      \------| :    | CTRL | *
65  * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
66  *M(M_LP)
67  */
68 [_BASE] = LAYOUT(
69            KC_F1,   KC_F2,   KC_F3,   KC_F4,   KC_F5,   KC_F6,                                          KC_F7,   KC_F8,   KC_F9,   KC_F10,  KC_F11,  KC_F12,     \
70   KC_ESC,  BP_DQOT, BP_LGIL, BP_RGIL, BP_LPRN, BP_RPRN, BP_DTRM,                                        BP_DCRC, BP_AT,   BP_PLUS, BP_MINS, BP_SLSH, BP_ASTR, KC_BSPC, \
71   KC_TAB,  BP_B,    BP_ECUT, BP_O,    BP_P,    BP_EGRV, BP_UNDS,                                        BP_EQL,  BP_K,    BP_V,    BP_D,    BP_L,    BP_J,    KC_ENT,  \
72   BP_GRV,  BP_A,    BP_U,    BP_E,    BP_I,    BP_F,    BP_SCLN,                                        BP_EXLM, BP_C,    BP_T,    BP_S,    BP_R,    BP_N,    BP_APOS, \
73   M(M_SF), BP_Z,    BP_AGRV, BP_Y,    BP_X,    KC_RBRACKET,    M(M_SFS), BP_CBSP, M(L2INS), M(L2LOC), BP_CDEL, M(M_SFS),BP_M,    BP_G,    KC_UP,   BP_H,    BP_Q,    M(M_SF), \
74   KC_LCTL, KC_LGUI, KC_PSLS, BP_DOT,  BP_COMM, KC_SPACE,M(M_L1E), KC_LALT,                     KC_CAPS, M(M_L1E),KC_SPACE,KC_LEFT, KC_DOWN, KC_RIGHT,BP_COLN, KC_RCTL,   \
75   //left pedals
76   M(M_LP), M(M_RP), KC_TRNS, \
77   //right pedals
78   M(M_LP), M(M_RP), KC_TRNS \
79 ),
80
81  /* Larer 1 for symbols.
82  *   left foot is middle click
83   *                      ,------.                                    ..                                    ,------.                      *
84   *               ,------|      |-------------.                      ..                      ,-------------|      |------.               *
85   *        ,------|      |------|      |      |------.               ..               ,------|      |      |------|      |------.        *
86   *        |      |------|  §   |------|------|      |               ..               |      |------|------|  ±   |------|      |        *
87   * ,------+------|  ¶   |------|  µ   |      |------|               ..               |------|  ≤   |  ≥   |------|  ÷   |------+------. *
88   * |      |  ¤   |------|  {   |------|------|  ~   |               ..               |  ˇ   |------|------|  ]   |------|  ×   |      | *
89   * |------+------|  *   |------|  }   |  `   |------|               ..               |------|  #   |  [   |------|  %   |------+------| *
90   * |      |  \   |------|  (   |------|------|      |               ..               |  ≠   |------|------|  >   |------|  ‰  |      | *
91   * |------+------|  Ù   |------|  )   |  +   |------|               ..               |------|  Ç   |  <   |------|  &   |------+------| *
92   * |      |  =   |------| copy |------|------|  :   |               ..               |  ?   |------|------| PGUP |------|  _   |      | *
93   * |------+------|  cut |------| paste|search|------|-------------. .. .-------------|------|  $   |  =   |------|  |   |------+------| *
94   * |      | undo |------|  \   |------|------|      |      |      | .. |      |      |      |------|------| PGDN |------|  /   |      | *
95   * |------+------|      |------|      |      |------|------|------  ..  ------|------|------|      | HOME |------| PGDN |------+------| *
96   * |      |      |------/      \-------------|      |      |        ..        |      |      |-------------/      \------|      |      | *
97   * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
98   *
99   */
100 [_SYMBOLS] = LAYOUT(
101            KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                       KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,          \
102   KC_TRNS, BP_DCUR, BP_PARG, BP_SECT, BP_DGRK, KC_TRNS, BP_TILD,                                       BP_DCAR, BP_LEQL, BP_GEQL, BP_PSMS, BP_OBEL, BP_TIMS, KC_TRNS, \
103   KC_TRNS, BP_BSLS, BP_ASTR, BP_LCBR, BP_RCBR, BP_GRV,  KC_TRNS,                                       BP_DIFF, BP_HASH, BP_LBRC, BP_RBRC, BP_PERC, BP_PMIL, KC_TRNS, \
104   KC_TRNS, BP_EQL,  BP_UGRV, BP_LPRN, BP_RPRN, BP_PLUS, BP_COLN,                                       BP_QEST, BP_CCED, BP_LESS, BP_GRTR, BP_AMPR, BP_UNDS, KC_TRNS, \
105   KC_TRNS, M(M_UN), M(M_CUT),M(M_CP), M(M_PS), M(M_SE), KC_TRNS, KC_TRNS, KC_TRNS,   KC_TRNS, KC_TRNS, KC_TRNS, BP_DLR,  BP_EQL,  KC_PGUP, BP_PIPE, BP_SLSH, KC_TRNS, \
106   KC_TRNS, KC_TRNS, BP_BSLS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                     KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END,  KC_TRNS, KC_TRNS,  \
107   //left pedals
108   KC_TRNS, KC_BTN1, KC_TRNS, \
109   //right pedals
110   KC_TRNS, KC_BTN1, KC_TRNS  \
111 ),
112
113  /* MEDIA, mouse and numpad.
114   * right pedal is left clic
115   *                      ,------.                                    ..                                    ,------.                      *
116   *               ,------|PAUSE |-------------.                      ..                      ,-------------| PRINT|------.               *
117   *        ,------|SCROLL|------|MUTE  |VOLUD |------.               ..               ,------| pre  | next |------| calc |------.        *
118   *        |RESET |------| stop |------|------|VOLDU |               ..               | play |------|------| stop |------| num  |        *
119   * ,------+------|      |------| pre  | next |------|               ..               |------| pre  | next |------|      |------+------. *
120   * |      |      |------|scrolu|------|------| play |               ..               | play |------|------|  8   |------|  -   |      | *
121   * |------+------|      |------|      | bt4  |------|               ..               |------| next |  7   |------|  9   |------+------| *
122   * |      |      |------|scrold|------|------| bt5  |               ..               | pre  |------|------|  5   |------|  +   |      | *
123   * |------+------|      |------|mclic | rclic|------|               ..               |------| rclic|  4   |------|  6   |------+------| *
124   * |      |      |------|      |------|------| lclic|               ..               | lclic|------|------|  2   |------|  *   |      | *
125   * |------+------|      |------|      | mclck|------|-------------. .. .-------------|------| mclic|  1   |------|  3   |------+------| *
126   * |      |      |------|      |------|------|      |      |      | .. |      |      |      |------|------| num. |------|  /   |      | *
127   * |------+------|      |------|      |      |------|------|------  ..  ------|------|------|      |  0   |------|  .   |------+------| *
128   * |      |      |------/      \-------------|      |      |        ..        |      |      |-------------/      \------|  ,   |      | *
129   * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
130   *
131   */
132 [_MEDIA] = LAYOUT(
133            RESET,   KC_SLCK, KC_PAUS, KC_MUTE, KC_VOLD, KC_VOLU,                                     KC_MUTE, KC_VOLD, KC_VOLU, KC_PSCR, KC_CALC, KC_NLCK,          \
134   KC_TRNS, KC_TRNS, KC_TRNS, KC_MSTP, KC_MPRV, KC_MNXT, KC_MPLY,                                     KC_MPLY, KC_MPRV, KC_MNXT, KC_MSTP, KC_TRNS, KC_PMNS, KC_TRNS, \
135   KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_U, KC_TRNS, KC_BTN4, KC_BTN5,                                     KC_BTN4, KC_BTN5, KC_KP_7, KC_KP_8, KC_KP_9, KC_PPLS, KC_TRNS, \
136   KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_D, KC_BTN3, KC_BTN2, KC_BTN1,                                     KC_BTN1, KC_BTN2, KC_KP_4, KC_KP_5, KC_KP_6, KC_PAST, KC_TRNS, \
137   KC_TRNS, M(M_UN), M(M_CUT),M(M_CP), M(M_PS), KC_BTN3, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_KP_1, KC_KP_2, KC_KP_3, KC_PSLS, KC_TRNS, \
138   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_0, KC_PDOT, BP_DOT,  BP_COMM, KC_TRNS,  \
139   //left pedals
140   KC_BTN3, M(M_RP), KC_TRNS, \
141   //right pedals
142   KC_BTN3, M(M_RP), KC_TRNS  \
143 ),
144
145 /* TRNS - skeleton for laters
146  *                      ,------.                                    ..                                    ,------.                      *
147  *               ,------|      |-------------.                      ..                      ,-------------|      |------.               *
148  *        ,------|      |------|      |      |------.               ..               ,------|      |      |------|      |------.        *
149  *        |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |        *
150  * ,------+------|      |------|      |      |------|               ..               |------|      |      |------|      |------+------. *
151  * |      |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |      | *
152  * |------+------|      |------|      |      |------|               ..               |------|      |      |------|      |------+------| *
153  * |      |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |      | *
154  * |------+------|      |------|      |      |------|               ..               |------|      |      |------|      |------+------| *
155  * |      |      |------|      |------|------|      |               ..               |      |------|------|      |------|      |      | *
156  * |------+------|      |------|      |      |------|-------------. .. .-------------|------|      |      |------|      |------+------| *
157  * |      |      |------|      |------|------|      |      |      | .. |      |      |      |------|------|      |------|      |      | *
158  * |------+------|      |------|      |      |------|------|------  ..  ------|------|------|      |      |------|      |------+------| *
159  * |      |      |------/      \-------------|      |      |        ..        |      |      |-------------/      \------|      |      | *
160  * `-------------/                           \-------------/        ..        \-------------/                           \-------------/ *
161  *
162  */
163
164 [_TRNS] = LAYOUT(
165            KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,          \
166   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
167   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
168   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                                     KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
169   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
170   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS,                   KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
171   //left pedals
172   KC_BTN3, M(M_RP), KC_TRNS, \
173   //right pedals
174   KC_BTN3, M(M_RP), KC_TRNS  \
175 ),
176
177 };
178
179 void hold_shift(void) {
180   shift_count = shift_count + 1;
181   register_code(KC_LSHIFT);
182 }
183
184 void release_shift(void) {
185   shift_count = shift_count - 1;
186   if(shift_count <= 0){
187     unregister_code(KC_LSHIFT);
188     shift_count = 0;
189   }
190 }
191
192 void press_space(void) {
193   if(shift_count > 0) unregister_code (KC_LSHIFT);
194   register_code (KC_SPACE);
195   unregister_code (KC_SPACE);
196   if(shift_count > 0) register_code (KC_LSHIFT);
197 }
198
199 void press_enter(void) {
200   if(shift_count > 0) unregister_code (KC_LSHIFT);
201   register_code (KC_ENT);
202   unregister_code (KC_ENT);
203   if(shift_count > 0) register_code (KC_LSHIFT);
204 }
205
206 void press_underscore(void) {
207   if(shift_count > 0) unregister_code (KC_LSHIFT);
208   register_code ((unsigned char) BP_UNDS);
209   unregister_code ((unsigned char) BP_UNDS);
210   if(shift_count > 0) register_code (KC_LSHIFT);
211 }
212
213 const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
214 {
215   switch(id) {
216     case M_LP: //left pedal
217       if (record->event.pressed) {
218         layer_on(1);
219         register_code (KC_SLCK);
220         key_timer_left_pedal = timer_read(); // if the key is being pressed, we start the timer.
221       } else {
222         if (timer_elapsed(key_timer_left_pedal) < KEY_DELAY) {
223            mousekey_on (KC_BTN2);
224            mousekey_send();
225            mousekey_off (KC_BTN2);
226            mousekey_send();
227         }
228         unregister_code (KC_SLCK);
229         layer_off(1);
230       }
231     break;
232     case M_RP: //right pedal
233       if (record->event.pressed) {
234         layer_on(2);
235         key_timer_right_pedal = timer_read(); // if the key is being pressed, we start the timer.
236       } else {
237         if (timer_elapsed(key_timer_right_pedal) < PEDAL_DELAY) {
238            mousekey_on (KC_BTN1);
239            mousekey_send();
240            mousekey_off (KC_BTN1);
241            mousekey_send();
242         }
243         layer_off(2);
244       }
245       break;
246     case M_SF: // shift, using macro to keep track of shift state and avoid inserting nbsp by mistake
247       if (record->event.pressed) {
248         hold_shift();
249       } else {
250         release_shift();
251       }
252       break;
253     case M_SFS: // shift when held, space when tapped
254       if (record->event.pressed) {
255         hold_shift();
256         key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
257       } else {
258         if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
259           press_space();
260         }
261         release_shift();
262       }
263       break;
264     case M_SFU: // shift when held, _ when tapped
265       if (record->event.pressed) {
266         hold_shift();
267         key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
268       } else {
269         if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
270           press_space();
271         }
272         release_shift();
273       }
274       break;
275     case M_L1E: // L1 when held, space when tapped
276       if (record->event.pressed) {
277         layer_on(1);
278         key_timer_1 = timer_read(); // if the key is being pressed, we start the timer.
279       } else {
280         if (timer_elapsed(key_timer_1) < KEY_DELAY) {
281           press_enter();
282         }
283         layer_off(1);
284       }
285       break;
286     case L2INS: //activate layer 2, if released before 100ms trigger INS. basicaly equivalent to LT(2, KC_INS) but without delay for activation of layer 2
287       if (record->event.pressed) {
288         layer_on(2);
289         key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
290       } else {
291         if (timer_elapsed(key_timer_2) < KEY_DELAY) {
292            register_code (KC_INS);
293            unregister_code (KC_INS);
294         }
295         l2_locked = 0;
296         layer_off(2);
297       }
298     break;
299     case L2LOC: //lock L2
300       if (record->event.pressed) {
301         key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
302         layer_on(2);
303       } else {
304         if (timer_elapsed(key_timer_2) < KEY_DELAY && l2_locked == 0) {
305           l2_locked = 1;
306           layer_on(2);
307         } else {
308           l2_locked = 0;
309           layer_off(2);
310         }
311       }
312     break;
313     case M_UN: // undo
314       if (record->event.pressed) {
315         register_code(KC_LCTL);
316         register_code(BP_Z);
317         unregister_code(BP_Z);
318         unregister_code(KC_LCTL);
319       }
320     break;
321     case M_CUT: // cut
322       if (record->event.pressed) {
323         register_code(KC_LCTL);
324         register_code(BP_X);
325         unregister_code(BP_X);
326         unregister_code(KC_LCTL);
327       }
328     break;
329     case M_CP: // copy
330       if (record->event.pressed) {
331         register_code(KC_LCTL);
332         register_code(BP_C);
333         unregister_code(BP_C);
334         unregister_code(KC_LCTL);
335       }
336     break;
337     case M_PS: // paste
338       if (record->event.pressed) {
339         register_code(KC_LCTL);
340         register_code(BP_V);
341         unregister_code(BP_V);
342         unregister_code(KC_LCTL);
343       }
344     break;
345     case M_SE: // search
346       if (record->event.pressed) {
347         register_code(KC_LCTL);
348         register_code(BP_F);
349         unregister_code(BP_F);
350         unregister_code(KC_LCTL);
351       }
352     break;
353   }
354   return MACRO_NONE;
355 };
356
357 void matrix_init_user(void) {
358 }
359
360 // Bleah globals need to be initialized.
361 uint8_t old_layer=_BASE;
362
363 void matrix_scan_user(void) {
364     uint8_t layer = biton32(layer_state);
365
366     frenchdev_led_1_off();
367     frenchdev_led_2_off();
368     switch (layer) {
369         case _BASE:
370             frenchdev_led_2_on();
371             break;
372         case _SYMBOLS:
373             frenchdev_led_1_on();
374             break;
375         case _MEDIA:
376            frenchdev_led_1_on();
377            frenchdev_led_2_on();
378         default:
379             // none
380             break;
381     }
382 }
383
384
385 bool process_record_user(uint16_t keycode, keyrecord_t *record) {
386   return true;
387 }
388
389 void led_set_user(uint8_t usb_led) {
390   if (usb_led & (1<<USB_LED_CAPS_LOCK)){
391     frenchdev_led_3_on();
392   } else {
393     frenchdev_led_3_off();
394   }
395   return ;
396 }