Keyboard firmwares for Atmel AVR and Cortex-M
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

action_macro.c 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 <util/delay.h>
  15. #include "action.h"
  16. #include "action_macro.h"
  17. #ifdef DEBUG_ACTION
  18. #include "debug.h"
  19. #else
  20. #include "nodebug.h"
  21. #endif
  22. #ifndef NO_ACTION_MACRO
  23. #define MACRO_READ() (macro = pgm_read_byte(macro_p++))
  24. void action_macro_play(const prog_macro_t *macro_p)
  25. {
  26. macro_t macro = END;
  27. uint8_t interval = 0;
  28. if (!macro_p) return;
  29. while (true) {
  30. switch (MACRO_READ()) {
  31. case INTERVAL:
  32. interval = MACRO_READ();
  33. debug("INTERVAL("); debug_dec(interval); debug(")\n");
  34. break;
  35. case WAIT:
  36. MACRO_READ();
  37. debug("WAIT("); debug_dec(macro); debug(")\n");
  38. { uint8_t ms = macro; while (ms--) _delay_ms(1); }
  39. break;
  40. case MODS_DOWN:
  41. MACRO_READ();
  42. debug("MODS_DOWN("); debug_hex(macro); debug(")\n");
  43. add_mods(macro);
  44. break;
  45. case MODS_UP:
  46. MACRO_READ();
  47. debug("MODS_UP("); debug_hex(macro); debug(")\n");
  48. del_mods(macro);
  49. break;
  50. case 0x04 ... 0x73:
  51. debug("DOWN("); debug_hex(macro); debug(")\n");
  52. register_code(macro);
  53. break;
  54. case 0x84 ... 0xF3:
  55. debug("UP("); debug_hex(macro); debug(")\n");
  56. unregister_code(macro&0x7F);
  57. break;
  58. case END:
  59. default:
  60. return;
  61. }
  62. // interval
  63. { uint8_t ms = interval; while (ms--) _delay_ms(1); }
  64. }
  65. }
  66. #endif