encoders.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #pragma once
  2. /*
  3. Copyright 2018-2022 Eric Gebhart <e.a.gebhart@gmail.com>
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 2 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include QMK_KEYBOARD_H
  16. typedef struct {
  17. uint16_t layer;
  18. uint16_t index; // 0 or 1, left/right.
  19. uint16_t clockwise;
  20. uint16_t counter_clockwise;
  21. uint16_t mods;
  22. void (*cw_func)(void);
  23. void (*ccw_func)(void);
  24. } encoder_action_t;
  25. extern encoder_action_t encoder_actions[];
  26. extern uint8_t NUM_ENCODER_ACTIONS;
  27. // haven't looked at the real values for index, but I know
  28. // 0 and 1 are left and right on my kyria.
  29. #define LEFT 0
  30. #define RIGHT 1
  31. #define LAYER_NONE -1
  32. #define MOD_NONE 0x00
  33. #define ENCODER_ACTION(LAYER, INDEX, CW_KC, CCW_KC, MOD) \
  34. {LAYER, INDEX, CW_KC, CCW_KC, MOD, NULL, NULL},
  35. #define ENCODER_FUNCTION(LAYER, INDEX, CW_FUNC, CCW_FUNC, MOD) \
  36. {LAYER, INDEX, 0, 0, MOD, CW_FUNC, CCW_FUNC},
  37. bool do_encoder_action(uint8_t index, bool clockwise, bool layer_actions);