Keyboard firmwares for Atmel AVR and Cortex-M
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

action_macro.c 2.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. Copyright 2013 Jun Wako <[email protected]>
  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. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include "action.h"
  15. #include "action_util.h"
  16. #include "action_macro.h"
  17. #include "wait.h"
  18. #ifdef DEBUG_ACTION
  19. #include "debug.h"
  20. #else
  21. #include "nodebug.h"
  22. #endif
  23. #ifndef NO_ACTION_MACRO
  24. #define MACRO_READ() (macro = MACRO_GET(macro_p++))
  25. void action_macro_play(const macro_t *macro_p)
  26. {
  27. macro_t macro = END;
  28. uint8_t interval = 0;
  29. uint8_t mod_storage = 0;
  30. if (!macro_p) return;
  31. while (true) {
  32. switch (MACRO_READ()) {
  33. case KEY_DOWN:
  34. MACRO_READ();
  35. dprintf("KEY_DOWN(%02X)\n", macro);
  36. if (IS_MOD(macro)) {
  37. add_weak_mods(MOD_BIT(macro));
  38. send_keyboard_report();
  39. } else {
  40. register_code(macro);
  41. }
  42. break;
  43. case KEY_UP:
  44. MACRO_READ();
  45. dprintf("KEY_UP(%02X)\n", macro);
  46. if (IS_MOD(macro)) {
  47. del_weak_mods(MOD_BIT(macro));
  48. send_keyboard_report();
  49. } else {
  50. unregister_code(macro);
  51. }
  52. break;
  53. case WAIT:
  54. MACRO_READ();
  55. dprintf("WAIT(%u)\n", macro);
  56. { uint8_t ms = macro; while (ms--) wait_ms(1); }
  57. break;
  58. case INTERVAL:
  59. interval = MACRO_READ();
  60. dprintf("INTERVAL(%u)\n", interval);
  61. break;
  62. case MOD_STORE:
  63. mod_storage = get_mods();
  64. break;
  65. case MOD_RESTORE:
  66. set_mods(mod_storage);
  67. send_keyboard_report();
  68. break;
  69. case MOD_CLEAR:
  70. clear_mods();
  71. send_keyboard_report();
  72. break;
  73. case 0x04 ... 0x73:
  74. dprintf("DOWN(%02X)\n", macro);
  75. register_code(macro);
  76. break;
  77. case 0x84 ... 0xF3:
  78. dprintf("UP(%02X)\n", macro);
  79. unregister_code(macro&0x7F);
  80. break;
  81. case END:
  82. default:
  83. return;
  84. }
  85. // interval
  86. { uint8_t ms = interval; while (ms--) wait_ms(1); }
  87. }
  88. }
  89. #endif