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.

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