Keyboard firmwares for Atmel AVR and Cortex-M
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.

action_macro.c 2.2KB

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