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.

93 lines
2.7 KiB

  1. /*
  2. Copyright 2013 Jun Wako <wakojun@gmail.com>
  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. /** \brief Action Macro Play
  26. *
  27. * FIXME: Needs doc
  28. */
  29. void action_macro_play(const macro_t *macro_p) {
  30. macro_t macro = END;
  31. uint8_t interval = 0;
  32. if (!macro_p) return;
  33. while (true) {
  34. switch (MACRO_READ()) {
  35. case KEY_DOWN:
  36. MACRO_READ();
  37. dprintf("KEY_DOWN(%02X)\n", macro);
  38. if (IS_MOD(macro)) {
  39. add_macro_mods(MOD_BIT(macro));
  40. send_keyboard_report();
  41. } else {
  42. register_code(macro);
  43. }
  44. break;
  45. case KEY_UP:
  46. MACRO_READ();
  47. dprintf("KEY_UP(%02X)\n", macro);
  48. if (IS_MOD(macro)) {
  49. del_macro_mods(MOD_BIT(macro));
  50. send_keyboard_report();
  51. } else {
  52. unregister_code(macro);
  53. }
  54. break;
  55. case WAIT:
  56. MACRO_READ();
  57. dprintf("WAIT(%u)\n", macro);
  58. {
  59. uint8_t ms = macro;
  60. while (ms--) wait_ms(1);
  61. }
  62. break;
  63. case INTERVAL:
  64. interval = MACRO_READ();
  65. dprintf("INTERVAL(%u)\n", interval);
  66. break;
  67. case 0x04 ... 0x73:
  68. dprintf("DOWN(%02X)\n", macro);
  69. register_code(macro);
  70. break;
  71. case 0x84 ... 0xF3:
  72. dprintf("UP(%02X)\n", macro);
  73. unregister_code(macro & 0x7F);
  74. break;
  75. case END:
  76. default:
  77. return;
  78. }
  79. // interval
  80. {
  81. uint8_t ms = interval;
  82. while (ms--) wait_ms(1);
  83. }
  84. }
  85. }
  86. #endif