]> git.donarmstrong.com Git - qmk_firmware.git/blob - tmk_core/common/action_macro.c
Generate API docs from source code comments (#2491)
[qmk_firmware.git] / tmk_core / common / action_macro.c
1 /*
2 Copyright 2013 Jun Wako <wakojun@gmail.com>
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17 #include "action.h"
18 #include "action_util.h"
19 #include "action_macro.h"
20 #include "wait.h"
21
22 #ifdef DEBUG_ACTION
23 #include "debug.h"
24 #else
25 #include "nodebug.h"
26 #endif
27
28
29 #ifndef NO_ACTION_MACRO
30
31 #define MACRO_READ()  (macro = MACRO_GET(macro_p++))
32 /** \brief Action Macro Play
33  *
34  * FIXME: Needs doc
35  */
36 void action_macro_play(const macro_t *macro_p)
37 {
38     macro_t macro = END;
39     uint8_t interval = 0;
40
41     if (!macro_p) return;
42     while (true) {
43         switch (MACRO_READ()) {
44             case KEY_DOWN:
45                 MACRO_READ();
46                 dprintf("KEY_DOWN(%02X)\n", macro);
47                 if (IS_MOD(macro)) {
48                     add_macro_mods(MOD_BIT(macro));
49                     send_keyboard_report();
50                 } else {
51                     register_code(macro);
52                 }
53                 break;
54             case KEY_UP:
55                 MACRO_READ();
56                 dprintf("KEY_UP(%02X)\n", macro);
57                 if (IS_MOD(macro)) {
58                     del_macro_mods(MOD_BIT(macro));
59                     send_keyboard_report();
60                 } else {
61                     unregister_code(macro);
62                 }
63                 break;
64             case WAIT:
65                 MACRO_READ();
66                 dprintf("WAIT(%u)\n", macro);
67                 { uint8_t ms = macro; while (ms--) wait_ms(1); }
68                 break;
69             case INTERVAL:
70                 interval = MACRO_READ();
71                 dprintf("INTERVAL(%u)\n", interval);
72                 break;
73             case 0x04 ... 0x73:
74                 dprintf("DOWN(%02X)\n", macro);
75                 register_code(macro);
76                 break;
77             case 0x84 ... 0xF3:
78                 dprintf("UP(%02X)\n", macro);
79                 unregister_code(macro&0x7F);
80                 break;
81             case END:
82             default:
83                 return;
84         }
85         // interval
86         { uint8_t ms = interval; while (ms--) wait_ms(1); }
87     }
88 }
89 #endif