]> git.donarmstrong.com Git - tmk_firmware.git/blob - common/action_macro.c
Add option 7bit data to serial_soft.c
[tmk_firmware.git] / 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 <util/delay.h>
18 #include "action.h"
19 #include "action_util.h"
20 #include "action_macro.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 = pgm_read_byte(macro_p++))
32 void action_macro_play(const macro_t *macro_p)
33 {
34     macro_t macro = END;
35     uint8_t interval = 0;
36
37     if (!macro_p) return;
38     while (true) {
39         switch (MACRO_READ()) {
40             case KEY_DOWN:
41                 MACRO_READ();
42                 dprintf("KEY_DOWN(%02X)\n", macro);
43                 if (IS_MOD(macro)) {
44                     add_weak_mods(MOD_BIT(macro));
45                 } else {
46                     register_code(macro);
47                 }
48                 break;
49             case KEY_UP:
50                 MACRO_READ();
51                 dprintf("KEY_UP(%02X)\n", macro);
52                 if (IS_MOD(macro)) {
53                     del_weak_mods(MOD_BIT(macro));
54                 } else {
55                     unregister_code(macro);
56                 }
57                 break;
58             case WAIT:
59                 MACRO_READ();
60                 dprintf("WAIT(%u)\n", macro);
61                 { uint8_t ms = macro; while (ms--) _delay_ms(1); }
62                 break;
63             case INTERVAL:
64                 interval = MACRO_READ();
65                 dprintf("INTERVAL(%u)\n", interval);
66                 break;
67             case 0x04 ... 0x73:
68                 dprintf("DOWN(%02X)\n", macro);
69                 register_code(macro);
70                 break;
71             case 0x84 ... 0xF3:
72                 dprintf("UP(%02X)\n", macro);
73                 unregister_code(macro&0x7F);
74                 break;
75             case END:
76             default:
77                 return;
78         }
79         // interval
80         { uint8_t ms = interval; while (ms--) _delay_ms(1); }
81     }
82 }
83 #endif