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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

action_macro.c 2.1KB

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 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 KEY_DOWN:
  32. MACRO_READ();
  33. dprintf("KEY_DOWN(%02X)\n", macro);
  34. register_code(macro);
  35. break;
  36. case KEY_UP:
  37. MACRO_READ();
  38. dprintf("KEY_UP(%02X)\n", macro);
  39. unregister_code(macro);
  40. break;
  41. case WAIT:
  42. MACRO_READ();
  43. dprintf("WAIT(%u)\n", macro);
  44. { uint8_t ms = macro; while (ms--) _delay_ms(1); }
  45. break;
  46. case INTERVAL:
  47. interval = MACRO_READ();
  48. dprintf("INTERVAL(%u)\n", interval);
  49. break;
  50. case 0x04 ... 0x73:
  51. dprintf("DOWN(%02X)\n", macro);
  52. register_code(macro);
  53. break;
  54. case 0x84 ... 0xF3:
  55. dprintf("UP(%02X)\n", macro);
  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