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