Keyboard firmwares for Atmel AVR and Cortex-M
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

action_macro.c 2.4KB

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