upload
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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

action_macro.c 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. if (!macro_p) return;
  30. while (true) {
  31. switch (MACRO_READ()) {
  32. case KEY_DOWN:
  33. MACRO_READ();
  34. dprintf("KEY_DOWN(%02X)\n", macro);
  35. if (IS_MOD(macro)) {
  36. add_macro_mods(MOD_BIT(macro));
  37. send_keyboard_report();
  38. } else {
  39. register_code(macro);
  40. }
  41. break;
  42. case KEY_UP:
  43. MACRO_READ();
  44. dprintf("KEY_UP(%02X)\n", macro);
  45. if (IS_MOD(macro)) {
  46. del_macro_mods(MOD_BIT(macro));
  47. send_keyboard_report();
  48. } else {
  49. unregister_code(macro);
  50. }
  51. break;
  52. case WAIT:
  53. MACRO_READ();
  54. dprintf("WAIT(%u)\n", macro);
  55. { uint8_t ms = macro; while (ms--) wait_ms(1); }
  56. break;
  57. case INTERVAL:
  58. interval = MACRO_READ();
  59. dprintf("INTERVAL(%u)\n", interval);
  60. break;
  61. case 0x04 ... 0x73:
  62. dprintf("DOWN(%02X)\n", macro);
  63. register_code(macro);
  64. break;
  65. case 0x84 ... 0xF3:
  66. dprintf("UP(%02X)\n", macro);
  67. unregister_code(macro&0x7F);
  68. break;
  69. case END:
  70. default:
  71. return;
  72. }
  73. // interval
  74. { uint8_t ms = interval; while (ms--) wait_ms(1); }
  75. }
  76. }
  77. #endif