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

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