logo

qmk_firmware

custom branch of QMK firmware git clone https://anongit.hacktivis.me/git/qmk_firmware.git

keymap.c (3197B)


  1. /* Copyright 2021 jpuerto
  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. #include QMK_KEYBOARD_H
  17. #include "analog.h"
  18. int16_t max_pot_val = 1023;
  19. int16_t max_ticks = 20;
  20. int16_t pot_oldVal = 0;
  21. int16_t pot_val = 0;
  22. bool moving = false;
  23. #define POT_TOLERANCE 50
  24. #define POT_PIN F0
  25. #include "print.h"
  26. void matrix_init_user(void) {
  27. analogReference(ADC_REF_POWER);
  28. }
  29. void matrix_scan_user(void){
  30. pot_val = (analogReadPin(POT_PIN));
  31. // If there is a big enough change, then we need to do something
  32. if (abs(pot_val - pot_oldVal) > POT_TOLERANCE) {
  33. moving = true;
  34. pot_oldVal = pot_val;
  35. }
  36. else{
  37. if (moving){
  38. // Do some fancy conversion to get 'absolute' position to num tap_codes to send
  39. // Reset moving to 0 so that we don't get multiple attempts to do this
  40. int num_ticks = ((float)pot_val/max_pot_val)*max_ticks;
  41. for (int i = 0; i<max_ticks;++i){
  42. tap_code(KC_VOLD);
  43. }
  44. for (int i = 0; i<num_ticks;++i){
  45. tap_code(KC_VOLU);
  46. }
  47. moving = false;
  48. }
  49. }
  50. }
  51. // Defines names for use in layer keycodes and the keymap
  52. enum layer_names {
  53. _BASE,
  54. _NUM,
  55. _FN
  56. };
  57. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  58. /* Base */
  59. [_BASE] = LAYOUT(
  60. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6,
  61. KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_BSPC,
  62. KC_LCTL, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  63. KC_LCAP, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_SLSH,
  64. KC_LGUI, MO(_NUM), MO(_FN), KC_SPC, KC_ENT, KC_LEFT, KC_DOWN, KC_RIGHT
  65. ),
  66. [_NUM] = LAYOUT(
  67. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6,
  68. KC_TAB, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_BSPC,
  69. KC_LCTL, QK_BOOT, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT,
  70. KC_LSFT, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_UP, KC_SLSH,
  71. QK_BOOT, KC_TRNS, KC_TRNS, KC_SPC, KC_ENT, KC_LEFT, KC_DOWN, KC_RIGHT
  72. ),
  73. [_FN] = LAYOUT(
  74. KC_1, KC_2, KC_3, KC_4, KC_5, KC_6,
  75. KC_TAB, KC_EXLM, KC_AT, KC_HASH, KC_DLR, KC_PERC, KC_CIRC, KC_AMPR, KC_ASTR, KC_LPRN, KC_RPRN, KC_BSPC,
  76. KC_LCTL, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_MINS, KC_EQL, KC_LCBR, KC_RCBR, KC_PIPE, KC_GRV,
  77. KC_LSFT, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_UNDS, KC_PLUS, KC_LBRC, KC_RBRC, KC_BSLS, KC_TILD,
  78. QK_BOOT, KC_TRNS, KC_TRNS, KC_SPC, KC_ENT, KC_LEFT, KC_DOWN, KC_RIGHT
  79. )
  80. };