annotate Macro/PartialMap/macro.c @ 215:00a8c7f491d4

Fixing first and last element bug for layers.
author Jacob Alexander <haata@kiibohd.com>
date Tue, 16 Sep 2014 17:21:41 -0700
parents 5a5404338b9f
children 738445f38639
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1 /* Copyright (C) 2014 by Jacob Alexander
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
2 *
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
3 * This file is free software: you can redistribute it and/or modify
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
4 * it under the terms of the GNU General Public License as published by
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
5 * the Free Software Foundation, either version 3 of the License, or
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
6 * (at your option) any later version.
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
7 *
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
8 * This file is distributed in the hope that it will be useful,
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
11 * GNU General Public License for more details.
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
12 *
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
13 * You should have received a copy of the GNU General Public License
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
14 * along with this file. If not, see <http://www.gnu.org/licenses/>.
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
15 */
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
16
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
17 // ----- Includes -----
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
18
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
19 // Compiler Includes
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
20 #include <Lib/MacroLib.h>
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
21
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
22 // Project Includes
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
23 #include <cli.h>
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
24 #include <led.h>
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
25 #include <print.h>
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
26 #include <scan_loop.h>
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
27
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
28 // Keymaps
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
29 #include "usb_hid.h"
205
a2e9bb170eef Adding CMake build support for the KLL compiler
Jacob Alexander <haata@kiibohd.com>
parents: 204
diff changeset
30 #include <generatedKeymap.h> // Generated using kll at compile time, in build directory
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
31
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
32 // Local Includes
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
33 #include "macro.h"
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
34
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
35
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
36
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
37 // ----- Function Declarations -----
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
38
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
39 void cliFunc_capList ( char* args );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
40 void cliFunc_capSelect ( char* args );
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
41 void cliFunc_keyHold ( char* args );
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
42 void cliFunc_keyPress ( char* args );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
43 void cliFunc_keyRelease( char* args );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
44 void cliFunc_layerList ( char* args );
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
45 void cliFunc_layerState( char* args );
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
46 void cliFunc_macroDebug( char* args );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
47 void cliFunc_macroList ( char* args );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
48 void cliFunc_macroProc ( char* args );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
49 void cliFunc_macroShow ( char* args );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
50 void cliFunc_macroStep ( char* args );
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
51
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
52
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
53
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
54 // ----- Enums -----
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
55
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
56 // Bit positions are important, passes (correct key) always trump incorrect key votes
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
57 typedef enum TriggerMacroVote {
197
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
58 TriggerMacroVote_Release = 0x10, // Correct key
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
59 TriggerMacroVote_PassRelease = 0x18, // Correct key (both pass and release)
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
60 TriggerMacroVote_Pass = 0x8, // Correct key
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
61 TriggerMacroVote_DoNothingRelease = 0x4, // Incorrect key
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
62 TriggerMacroVote_DoNothing = 0x2, // Incorrect key
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
63 TriggerMacroVote_Fail = 0x1, // Incorrect key
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
64 TriggerMacroVote_Invalid = 0x0, // Invalid state
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
65 } TriggerMacroVote;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
66
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
67 typedef enum TriggerMacroEval {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
68 TriggerMacroEval_DoNothing,
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
69 TriggerMacroEval_DoResult,
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
70 TriggerMacroEval_DoResultAndRemove,
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
71 TriggerMacroEval_Remove,
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
72 } TriggerMacroEval;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
73
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
74 typedef enum ResultMacroEval {
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
75 ResultMacroEval_DoNothing,
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
76 ResultMacroEval_Remove,
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
77 } ResultMacroEval;
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
78
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
79
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
80
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
81 // ----- Variables -----
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
82
132
e08d7b586ea3 Adding analog.c lib from teensyduino.
Jacob Alexander <haata@kiibohd.com>
parents: 126
diff changeset
83 // Macro Module command dictionary
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
84 const char macroCLIDictName[] = "Macro Module Commands";
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
85 const CLIDictItem macroCLIDict[] = {
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
86 { "capList", "Prints an indexed list of all non USB keycode capabilities.", cliFunc_capList },
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
87 { "capSelect", "Triggers the specified capabilities. First two args are state and stateType." NL "\t\t\033[35mK11\033[0m Keyboard Capability 0x0B", cliFunc_capSelect },
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
88 { "keyHold", "Send key-hold events to the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyHold },
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
89 { "keyPress", "Send key-press events to the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyPress },
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
90 { "keyRelease", "Send key-release event to macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyRelease },
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
91 { "layerList", "List available layers.", cliFunc_layerList },
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
92 { "layerState", "Modify specified indexed layer state <layer> <state byte>." NL "\t\t\033[35mL2\033[0m Indexed Layer 0x02" NL "\t\t0 Off, 1 Shift, 2 Latch, 4 Lock States", cliFunc_layerState },
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
93 { "macroDebug", "Disables/Enables sending USB keycodes to the Output Module and prints U/K codes.", cliFunc_macroDebug },
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
94 { "macroList", "List the defined trigger and result macros.", cliFunc_macroList },
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
95 { "macroProc", "Pause/Resume macro processing.", cliFunc_macroProc },
181
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
96 { "macroShow", "Show the macro corresponding to the given index." NL "\t\t\033[35mT16\033[0m Indexed Trigger Macro 0x10, \033[35mR12\033[0m Indexed Result Macro 0x0C", cliFunc_macroShow },
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
97 { "macroStep", "Do N macro processing steps. Defaults to 1.", cliFunc_macroStep },
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
98 { 0, 0, 0 } // Null entry for dictionary end
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
99 };
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
100
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
101
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
102 // Macro debug flag - If set, clears the USB Buffers after signalling processing completion
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
103 uint8_t macroDebugMode = 0;
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
104
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
105 // Macro pause flag - If set, the macro module pauses processing, unless unset, or the step counter is non-zero
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
106 uint8_t macroPauseMode = 0;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
107
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
108 // Macro step counter - If non-zero, the step counter counts down every time the macro module does one processing loop
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
109 uint16_t macroStepCounter = 0;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
110
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
111
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
112 // Key Trigger List Buffer
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
113 TriggerGuide macroTriggerListBuffer[ MaxScanCode ];
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
114 uint8_t macroTriggerListBufferSize = 0;
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
115
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
116 // Pending Trigger Macro Index List
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
117 // * Any trigger macros that need processing from a previous macro processing loop
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
118 // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
119 // Possibly could be calculated by the KLL compiler
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
120 // XXX It may be possible to calculate the worst case using the KLL compiler
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
121 uint16_t macroTriggerMacroPendingList[ TriggerMacroNum ] = { 0 };
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
122 uint16_t macroTriggerMacroPendingListSize = 0;
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
123
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
124 // Layer Index Stack
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
125 // * When modifying layer state and the state is non-0x0, the stack must be adjusted
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
126 uint16_t macroLayerIndexStack[ LayerNum + 1 ] = { 0 };
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
127 uint16_t macroLayerIndexStackSize = 0;
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
128
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
129 // Pending Result Macro Index List
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
130 // * Any result macro that needs processing from a previous macro processing loop
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
131 uint16_t macroResultMacroPendingList[ ResultMacroNum ] = { 0 };
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
132 uint16_t macroResultMacroPendingListSize = 0;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
133
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
134
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
135
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
136 // ----- Capabilities -----
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
137
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
138 // Sets the given layer with the specified layerState
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
139 void Macro_layerState( uint8_t state, uint8_t stateType, uint16_t layer, uint8_t layerState )
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
140 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
141 // Is layer in the LayerIndexStack?
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
142 uint8_t inLayerIndexStack = 0;
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
143 uint16_t stackItem = 0;
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
144 while ( stackItem < macroLayerIndexStackSize )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
145 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
146 // Flag if layer is already in the LayerIndexStack
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
147 if ( macroLayerIndexStack[ stackItem ] == layer )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
148 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
149 inLayerIndexStack = 1;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
150 break;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
151 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
152
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
153 // Increment to next item
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
154 stackItem++;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
155 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
156
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
157 // Toggle Layer State Byte
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
158 if ( LayerState[ layer ] & layerState )
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
159 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
160 // Unset
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
161 LayerState[ layer ] &= ~layerState;
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
162 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
163 else
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
164 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
165 // Set
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
166 LayerState[ layer ] |= layerState;
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
167 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
168
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
169 // If the layer was not in the LayerIndexStack add it
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
170 if ( !inLayerIndexStack )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
171 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
172 macroLayerIndexStack[ macroLayerIndexStackSize++ ] = layer;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
173 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
174
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
175 // If the layer is in the LayerIndexStack and the state is 0x00, remove
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
176 if ( LayerState[ layer ] == 0x00 && inLayerIndexStack )
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
177 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
178 // Remove the layer from the LayerIndexStack
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
179 // Using the already positioned stackItem variable from the loop above
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
180 while ( stackItem < macroLayerIndexStackSize )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
181 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
182 macroLayerIndexStack[ stackItem ] = macroLayerIndexStack[ stackItem + 1 ];
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
183 stackItem++;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
184 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
185
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
186 // Reduce LayerIndexStack size
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
187 macroLayerIndexStackSize--;
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
188 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
189 }
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
190
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
191 // Modifies the specified Layer control byte
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
192 // Argument #1: Layer Index -> uint16_t
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
193 // Argument #2: Layer State -> uint8_t
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
194 void Macro_layerState_capability( uint8_t state, uint8_t stateType, uint8_t *args )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
195 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
196 // Display capability name
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
197 if ( stateType == 0xFF && state == 0xFF )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
198 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
199 print("Macro_layerState(layerIndex,layerState)");
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
200 return;
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
201 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
202
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
203 // Only use capability on press or release
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
204 // TODO Analog
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
205 // XXX This may cause issues, might be better to implement state table here to decide -HaaTa
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
206 if ( stateType == 0x00 && state == 0x02 ) // Hold condition
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
207 return;
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
208
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
209 // Get layer index from arguments
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
210 // Cast pointer to uint8_t to uint16_t then access that memory location
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
211 uint16_t layer = *(uint16_t*)(&args[0]);
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
212
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
213 // Get layer toggle byte
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
214 uint8_t layerState = args[ sizeof(uint16_t) ];
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
215
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
216 Macro_layerState( state, stateType, layer, layerState );
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
217 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
218
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
219
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
220 // Latches given layer
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
221 // Argument #1: Layer Index -> uint16_t
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
222 void Macro_layerLatch_capability( uint8_t state, uint8_t stateType, uint8_t *args )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
223 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
224 // Display capability name
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
225 if ( stateType == 0xFF && state == 0xFF )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
226 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
227 print("Macro_layerLatch(layerIndex)");
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
228 return;
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
229 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
230
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
231 // Only use capability on press
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
232 // TODO Analog
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
233 // XXX To make sense, this code be on press or release. Or it could even be a sticky shift (why? dunno) -HaaTa
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
234 if ( stateType == 0x00 && state != 0x01 ) // All normal key conditions except press
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
235 return;
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
236
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
237 // Get layer index from arguments
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
238 // Cast pointer to uint8_t to uint16_t then access that memory location
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
239 uint16_t layer = *(uint16_t*)(&args[0]);
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
240
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
241 Macro_layerState( state, stateType, layer, 0x02 );
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
242 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
243
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
244
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
245 // Locks given layer
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
246 // Argument #1: Layer Index -> uint16_t
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
247 void Macro_layerLock_capability( uint8_t state, uint8_t stateType, uint8_t *args )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
248 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
249 // Display capability name
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
250 if ( stateType == 0xFF && state == 0xFF )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
251 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
252 print("Macro_layerLock(layerIndex)");
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
253 return;
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
254 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
255
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
256 // Only use capability on press
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
257 // TODO Analog
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
258 // XXX Could also be on release, but that's sorta dumb -HaaTa
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
259 if ( stateType == 0x00 && state != 0x01 ) // All normal key conditions except press
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
260 return;
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
261
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
262 // Get layer index from arguments
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
263 // Cast pointer to uint8_t to uint16_t then access that memory location
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
264 uint16_t layer = *(uint16_t*)(&args[0]);
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
265
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
266 Macro_layerState( state, stateType, layer, 0x04 );
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
267 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
268
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
269
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
270 // Shifts given layer
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
271 // Argument #1: Layer Index -> uint16_t
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
272 void Macro_layerShift_capability( uint8_t state, uint8_t stateType, uint8_t *args )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
273 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
274 // Display capability name
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
275 if ( stateType == 0xFF && state == 0xFF )
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
276 {
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
277 print("Macro_layerShift(layerIndex)");
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
278 return;
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
279 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
280
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
281 // Only use capability on press or release
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
282 // TODO Analog
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
283 if ( stateType == 0x00 && ( state == 0x00 || state == 0x02 ) ) // Only pass press or release conditions
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
284 return;
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
285
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
286 // Get layer index from arguments
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
287 // Cast pointer to uint8_t to uint16_t then access that memory location
199
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
288 uint16_t layer = *(uint16_t*)(&args[0]);
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
289
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
290 Macro_layerState( state, stateType, layer, 0x01 );
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
291 }
559a467f6d57 Preparing for kll compiler usage
Jacob Alexander <haata@kiibohd.com>
parents: 197
diff changeset
292
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
293
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
294
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
295 // ----- Functions -----
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
296
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
297 // Looks up the trigger list for the given scan code (from the active layer)
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
298 // NOTE: Calling function must handle the NULL pointer case
202
1a68a9a04ad3 Adding variable width state variable width.
Jacob Alexander <haata@kiibohd.com>
parents: 201
diff changeset
299 nat_ptr_t *Macro_layerLookup( uint8_t scanCode )
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
300 {
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
301 // If no trigger macro is defined at the given layer, fallthrough to the next layer
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
302 for ( uint16_t layerIndex = 0; layerIndex < macroLayerIndexStackSize; layerIndex++ )
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
303 {
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
304 // Lookup Layer
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
305 const Layer *layer = &LayerIndex[ macroLayerIndexStack[ layerIndex ] ];
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
306
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
307 // Check if latch has been pressed for this layer
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
308 // XXX Regardless of whether a key is found, the latch is removed on first lookup
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
309 uint8_t latch = LayerState[ layerIndex ] & 0x02;
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
310 if ( latch )
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
311 {
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
312 LayerState[ layerIndex ] &= ~0x02;
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
313 }
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
314
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
315 // Only use layer, if state is valid
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
316 // XOR each of the state bits
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
317 // If only two are enabled, do not use this state
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
318 if ( (LayerState[ layerIndex ] & 0x01) ^ (latch>>1) ^ ((LayerState[ layerIndex ] & 0x04)>>2) )
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
319 {
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
320 // Lookup layer
202
1a68a9a04ad3 Adding variable width state variable width.
Jacob Alexander <haata@kiibohd.com>
parents: 201
diff changeset
321 nat_ptr_t **map = (nat_ptr_t**)layer->triggerMap;
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
322
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
323 // Determine if layer has key defined
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
324 // Make sure scanCode is between layer first and last scancodes
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
325 if ( map != 0
215
00a8c7f491d4 Fixing first and last element bug for layers.
Jacob Alexander <haata@kiibohd.com>
parents: 214
diff changeset
326 && scanCode <= layer->last
00a8c7f491d4 Fixing first and last element bug for layers.
Jacob Alexander <haata@kiibohd.com>
parents: 214
diff changeset
327 && scanCode >= layer->first
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
328 && *map[ scanCode - layer->first ] != 0 )
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
329 {
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
330 return map[ scanCode - layer->first ];
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
331 }
191
3404be65670b Adding generic layerToggle and USB Key Output capabilities.
Jacob Alexander <haata@kiibohd.com>
parents: 190
diff changeset
332 }
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
333 }
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
334
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
335 // Do lookup on default layer
202
1a68a9a04ad3 Adding variable width state variable width.
Jacob Alexander <haata@kiibohd.com>
parents: 201
diff changeset
336 nat_ptr_t **map = (nat_ptr_t**)LayerIndex[0].triggerMap;
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
337
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
338 // Lookup default layer
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
339 const Layer *layer = &LayerIndex[ macroLayerIndexStack[ 0 ] ];
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
340
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
341 // Make sure scanCode is between layer first and last scancodes
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
342 if ( map != 0
215
00a8c7f491d4 Fixing first and last element bug for layers.
Jacob Alexander <haata@kiibohd.com>
parents: 214
diff changeset
343 && scanCode <= layer->last
00a8c7f491d4 Fixing first and last element bug for layers.
Jacob Alexander <haata@kiibohd.com>
parents: 214
diff changeset
344 && scanCode >= layer->first
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
345 && *map[ scanCode - layer->first ] != 0 )
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
346 {
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
347 return map[ scanCode - layer->first ];
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
348 }
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
349
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
350 // Otherwise no defined Trigger Macro
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
351 erro_msg("Scan Code has no defined Trigger Macro: ");
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
352 printHex( scanCode );
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
353 return 0;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
354 }
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
355
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
356
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
357 // Update the scancode key state
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
358 // States:
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
359 // * 0x00 - Off
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
360 // * 0x01 - Pressed
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
361 // * 0x02 - Held
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
362 // * 0x03 - Released
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
363 // * 0x04 - Unpressed (this is currently ignored)
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
364 inline void Macro_keyState( uint8_t scanCode, uint8_t state )
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
365 {
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
366 // Only add to macro trigger list if one of three states
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
367 switch ( state )
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
368 {
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
369 case 0x01: // Pressed
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
370 case 0x02: // Held
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
371 case 0x03: // Released
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
372 macroTriggerListBuffer[ macroTriggerListBufferSize ].scanCode = scanCode;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
373 macroTriggerListBuffer[ macroTriggerListBufferSize ].state = state;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
374 macroTriggerListBuffer[ macroTriggerListBufferSize ].type = 0x00; // Normal key
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
375 macroTriggerListBufferSize++;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
376 break;
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
377 }
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
378 }
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
379
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
380
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
381 // Update the scancode analog state
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
382 // States:
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
383 // * 0x00 - Off
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
384 // * 0x01 - Released
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
385 // * 0x02-0xFF - Analog value (low to high)
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
386 inline void Macro_analogState( uint8_t scanCode, uint8_t state )
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
387 {
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
388 // Only add to macro trigger list if non-off
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
389 if ( state != 0x00 )
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
390 {
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
391 macroTriggerListBuffer[ macroTriggerListBufferSize ].scanCode = scanCode;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
392 macroTriggerListBuffer[ macroTriggerListBufferSize ].state = state;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
393 macroTriggerListBuffer[ macroTriggerListBufferSize ].type = 0x02; // Analog key
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
394 macroTriggerListBufferSize++;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
395 }
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
396 }
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
397
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
398
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
399 // Update led state
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
400 // States:
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
401 // * 0x00 - Off
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
402 // * 0x01 - On
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
403 inline void Macro_ledState( uint8_t ledCode, uint8_t state )
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
404 {
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
405 // Only add to macro trigger list if non-off
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
406 if ( state != 0x00 )
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
407 {
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
408 macroTriggerListBuffer[ macroTriggerListBufferSize ].scanCode = ledCode;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
409 macroTriggerListBuffer[ macroTriggerListBufferSize ].state = state;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
410 macroTriggerListBuffer[ macroTriggerListBufferSize ].type = 0x01; // LED key
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
411 macroTriggerListBufferSize++;
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
412 }
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
413 }
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
414
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
415
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
416 // Append result macro to pending list, checking for duplicates
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
417 // Do nothing if duplicate
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
418 inline void Macro_appendResultMacroToPendingList( TriggerMacro *triggerMacro )
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
419 {
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
420 // Lookup result macro index
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
421 var_uint_t resultMacroIndex = triggerMacro->result;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
422
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
423 // Iterate through result macro pending list, making sure this macro hasn't been added yet
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
424 for ( var_uint_t macro = 0; macro < macroResultMacroPendingListSize; macro++ )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
425 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
426 // If duplicate found, do nothing
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
427 if ( macroResultMacroPendingList[ macro ] == resultMacroIndex )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
428 return;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
429 }
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
430
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
431 // No duplicates found, add to pending list
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
432 macroResultMacroPendingList[ macroResultMacroPendingListSize++ ] = resultMacroIndex;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
433
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
434 // Lookup scanCode of the last key in the last combo
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
435 var_uint_t pos = 0;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
436 for ( uint8_t comboLength = triggerMacro->guide[0]; comboLength > 0; )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
437 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
438 pos += TriggerGuideSize * comboLength + 1;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
439 comboLength = triggerMacro->guide[ pos ];
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
440 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
441
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
442 uint8_t scanCode = ((TriggerGuide*)&triggerMacro->guide[ pos - TriggerGuideSize ])->scanCode;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
443
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
444 // Lookup scanCode in buffer list for the current state and stateType
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
445 for ( uint8_t keyIndex = 0; keyIndex < macroTriggerListBufferSize; keyIndex++ )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
446 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
447 if ( macroTriggerListBuffer[ keyIndex ].scanCode == scanCode )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
448 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
449 ResultMacroList[ resultMacroIndex ].state = macroTriggerListBuffer[ keyIndex ].state;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
450 ResultMacroList[ resultMacroIndex ].stateType = macroTriggerListBuffer[ keyIndex ].type;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
451 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
452 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
453
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
454 // Reset the macro position
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
455 ResultMacroList[ resultMacroIndex ].pos = 0;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
456 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
457
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
458
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
459 // Determine if long ResultMacro (more than 1 seqence element)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
460 inline uint8_t Macro_isLongResultMacro( ResultMacro *macro )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
461 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
462 // Check the second sequence combo length
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
463 // If non-zero return non-zero (long sequence)
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
464 // 0 otherwise (short sequence)
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
465 var_uint_t position = 1;
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
466 for ( var_uint_t result = 0; result < macro->guide[0]; result++ )
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
467 position += ResultGuideSize( (ResultGuide*)&macro->guide[ position ] );
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
468 return macro->guide[ position ];
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
469 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
470
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
471
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
472 // Determine if long TriggerMacro (more than 1 sequence element)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
473 inline uint8_t Macro_isLongTriggerMacro( TriggerMacro *macro )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
474 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
475 // Check the second sequence combo length
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
476 // If non-zero return non-zero (long sequence)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
477 // 0 otherwise (short sequence)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
478 return macro->guide[ macro->guide[0] * TriggerGuideSize + 1 ];
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
479 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
480
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
481
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
482 // Votes on the given key vs. guide, short macros
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
483 inline TriggerMacroVote Macro_evalShortTriggerMacroVote( TriggerGuide *key, TriggerGuide *guide )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
484 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
485 // Depending on key type
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
486 switch ( guide->type )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
487 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
488 // Normal State Type
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
489 case 0x00:
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
490 // For short TriggerMacros completely ignore incorrect keys
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
491 if ( guide->scanCode == key->scanCode )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
492 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
493 switch ( key->state )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
494 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
495 // Correct key, pressed, possible passing
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
496 case 0x01:
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
497 return TriggerMacroVote_Pass;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
498
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
499 // Correct key, held, possible passing or release
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
500 case 0x02:
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
501 return TriggerMacroVote_PassRelease;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
502
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
503 // Correct key, released, possible release
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
504 case 0x03:
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
505 return TriggerMacroVote_Release;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
506 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
507 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
508
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
509 return TriggerMacroVote_DoNothing;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
510
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
511 // LED State Type
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
512 case 0x01:
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
513 erro_print("LED State Type - Not implemented...");
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
514 break;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
515
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
516 // Analog State Type
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
517 case 0x02:
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
518 erro_print("Analog State Type - Not implemented...");
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
519 break;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
520
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
521 // Invalid State Type
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
522 default:
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
523 erro_print("Invalid State Type. This is a bug.");
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
524 break;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
525 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
526
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
527 // XXX Shouldn't reach here
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
528 return TriggerMacroVote_Invalid;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
529 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
530
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
531
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
532 // Votes on the given key vs. guide, long macros
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
533 // A long macro is defined as a guide with more than 1 combo
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
534 inline TriggerMacroVote Macro_evalLongTriggerMacroVote( TriggerGuide *key, TriggerGuide *guide )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
535 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
536 // Depending on key type
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
537 switch ( guide->type )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
538 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
539 // Normal State Type
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
540 case 0x00:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
541 // Depending on the state of the buffered key, make voting decision
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
542 // Incorrect key
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
543 if ( guide->scanCode != key->scanCode )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
544 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
545 switch ( key->state )
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
546 {
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
547 // Wrong key, pressed, fail
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
548 case 0x01:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
549 return TriggerMacroVote_Fail;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
550
197
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
551 // Wrong key, held, do not pass (no effect)
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
552 case 0x02:
197
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
553 return TriggerMacroVote_DoNothing;
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
554
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
555 // Wrong key released, fail out if pos == 0
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
556 case 0x03:
197
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
557 return TriggerMacroVote_DoNothing | TriggerMacroVote_DoNothingRelease;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
558 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
559 }
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
560
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
561 // Correct key
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
562 else
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
563 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
564 switch ( key->state )
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
565 {
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
566 // Correct key, pressed, possible passing
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
567 case 0x01:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
568 return TriggerMacroVote_Pass;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
569
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
570 // Correct key, held, possible passing or release
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
571 case 0x02:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
572 return TriggerMacroVote_PassRelease;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
573
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
574 // Correct key, released, possible release
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
575 case 0x03:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
576 return TriggerMacroVote_Release;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
577 }
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
578 }
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
579
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
580 break;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
581
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
582 // LED State Type
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
583 case 0x01:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
584 erro_print("LED State Type - Not implemented...");
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
585 break;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
586
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
587 // Analog State Type
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
588 case 0x02:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
589 erro_print("Analog State Type - Not implemented...");
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
590 break;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
591
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
592 // Invalid State Type
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
593 default:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
594 erro_print("Invalid State Type. This is a bug.");
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
595 break;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
596 }
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
597
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
598 // XXX Shouldn't reach here
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
599 return TriggerMacroVote_Invalid;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
600 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
601
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
602
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
603 // Evaluate/Update TriggerMacro
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
604 inline TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
605 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
606 // Lookup TriggerMacro
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
607 TriggerMacro *macro = &TriggerMacroList[ triggerMacroIndex ];
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
608
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
609 // Check if macro has finished and should be incremented sequence elements
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
610 if ( macro->state == TriggerMacro_Release )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
611 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
612 macro->state = TriggerMacro_Waiting;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
613 macro->pos = macro->pos + macro->guide[ macro->pos ] * TriggerGuideSize + 1;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
614 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
615
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
616 // Current Macro position
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
617 var_uint_t pos = macro->pos;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
618
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
619 // Length of the combo being processed
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
620 uint8_t comboLength = macro->guide[ pos ] * TriggerGuideSize;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
621
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
622 // If no combo items are left, remove the TriggerMacro from the pending list
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
623 if ( comboLength == 0 )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
624 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
625 return TriggerMacroEval_Remove;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
626 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
627
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
628 // Check if this is a long Trigger Macro
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
629 uint8_t longMacro = Macro_isLongTriggerMacro( macro );
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
630
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
631 // Iterate through the items in the combo, voting the on the key state
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
632 // If any of the pressed keys do not match, fail the macro
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
633 //
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
634 // The macro is waiting for input when in the TriggerMacro_Waiting state
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
635 // Once all keys have been pressed/held (only those keys), entered TriggerMacro_Press state (passing)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
636 // Transition to the next combo (if it exists) when a single key is released (TriggerMacro_Release state)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
637 // On scan after position increment, change to TriggerMacro_Waiting state
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
638 // TODO Add support for system LED states (NumLock, CapsLock, etc.)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
639 // TODO Add support for analog key states
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
640 // TODO Add support for 0x00 Key state (not pressing a key, not all that useful in general)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
641 // TODO Add support for Press/Hold/Release differentiation when evaluating (not sure if useful)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
642 TriggerMacroVote overallVote = TriggerMacroVote_Invalid;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
643 for ( uint8_t comboItem = pos + 1; comboItem < pos + comboLength + 1; comboItem += TriggerGuideSize )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
644 {
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
645 // Assign TriggerGuide element (key type, state and scancode)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
646 TriggerGuide *guide = (TriggerGuide*)(&macro->guide[ comboItem ]);
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
647
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
648 TriggerMacroVote vote = TriggerMacroVote_Invalid;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
649 // Iterate through the key buffer, comparing to each key in the combo
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
650 for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
651 {
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
652 // Lookup key information
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
653 TriggerGuide *keyInfo = &macroTriggerListBuffer[ key ];
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
654
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
655 // If vote is a pass (>= 0x08, no more keys in the combo need to be looked at)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
656 // Also mask all of the non-passing votes
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
657 vote |= longMacro
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
658 ? Macro_evalLongTriggerMacroVote( keyInfo, guide )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
659 : Macro_evalShortTriggerMacroVote( keyInfo, guide );
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
660 if ( vote >= TriggerMacroVote_Pass )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
661 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
662 vote &= TriggerMacroVote_Release | TriggerMacroVote_PassRelease | TriggerMacroVote_Pass;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
663 break;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
664 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
665 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
666
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
667 // If no pass vote was found after scanning all of the keys
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
668 // Fail the combo, if this is a short macro (long macros already will have a fail vote)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
669 if ( !longMacro && vote < TriggerMacroVote_Pass )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
670 vote |= TriggerMacroVote_Fail;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
671
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
672 // After voting, append to overall vote
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
673 overallVote |= vote;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
674 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
675
197
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
676 // If no pass vote was found after scanning the entire combo
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
677 // And this is the first position in the combo, just remove it (nothing important happened)
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
678 if ( longMacro && overallVote & TriggerMacroVote_DoNothingRelease && pos == 0 )
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
679 overallVote |= TriggerMacroVote_Fail;
1ebb6fb5f74f All basic macros tested and working!
Jacob Alexander <haata@kiibohd.com>
parents: 196
diff changeset
680
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
681 // Decide new state of macro after voting
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
682 // Fail macro, remove from pending list
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
683 if ( overallVote & TriggerMacroVote_Fail )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
684 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
685 return TriggerMacroEval_Remove;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
686 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
687 // Do nothing, incorrect key is being held or released
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
688 else if ( overallVote & TriggerMacroVote_DoNothing && longMacro )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
689 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
690 // Just doing nothing :)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
691 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
692 // If passing and in Waiting state, set macro state to Press
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
693 else if ( overallVote & TriggerMacroVote_Pass
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
694 && ( macro->state == TriggerMacro_Waiting || macro->state == TriggerMacro_Press ) )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
695 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
696 macro->state = TriggerMacro_Press;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
697
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
698 // If in press state, and this is the final combo, send request for ResultMacro
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
699 // Check to see if the result macro only has a single element
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
700 // If this result macro has more than 1 key, only send once
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
701 // TODO Add option to have long macro repeat rate
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
702 if ( macro->guide[ pos + comboLength + 1 ] == 0 )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
703 {
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
704 // Long result macro (more than 1 combo)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
705 if ( Macro_isLongResultMacro( &ResultMacroList[ macro->result ] ) )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
706 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
707 // Only ever trigger result once, on press
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
708 if ( overallVote == TriggerMacroVote_Pass )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
709 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
710 return TriggerMacroEval_DoResultAndRemove;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
711 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
712 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
713 // Short result macro
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
714 else
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
715 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
716 // Only trigger result once, on press, if long trigger (more than 1 combo)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
717 if ( Macro_isLongTriggerMacro( macro ) )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
718 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
719 return TriggerMacroEval_DoResultAndRemove;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
720 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
721 // Otherwise, trigger result continuously
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
722 else
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
723 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
724 return TriggerMacroEval_DoResult;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
725 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
726 }
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
727 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
728 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
729 // If ready for transition and in Press state, set to Waiting and increment combo position
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
730 // Position is incremented (and possibly remove the macro from the pending list) on the next iteration
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
731 else if ( overallVote & TriggerMacroVote_Release && macro->state == TriggerMacro_Press )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
732 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
733 macro->state = TriggerMacro_Release;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
734
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
735 // If this is the last combo in the sequence, remove from the pending list
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
736 if ( macro->guide[ macro->pos + macro->guide[ macro->pos ] * TriggerGuideSize + 1 ] == 0 )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
737 return TriggerMacroEval_Remove;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
738 }
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
739 // Otherwise, just remove the macro on key release
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
740 // One more result has to be called to indicate to the ResultMacro that the key transitioned to the release state
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
741 else if ( overallVote & TriggerMacroVote_Release )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
742 {
201
326f75709d10 Fixing release state for keys
Jacob Alexander <jacob.alexander@virtualinstruments.com>
parents: 199
diff changeset
743 return TriggerMacroEval_DoResultAndRemove;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
744 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
745
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
746 // If this is a short macro, just remove it
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
747 // The state can be rebuilt on the next iteration
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
748 if ( !longMacro )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
749 return TriggerMacroEval_Remove;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
750
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
751 return TriggerMacroEval_DoNothing;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
752 }
166
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
753
2fba36caf039 Initial work for KLL macro support
Jacob Alexander <haata@kiibohd.com>
parents: 159
diff changeset
754
185
68f3dc0cddd0 Macro cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 184
diff changeset
755 // Evaluate/Update ResultMacro
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
756 inline ResultMacroEval Macro_evalResultMacro( var_uint_t resultMacroIndex )
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
757 {
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
758 // Lookup ResultMacro
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
759 ResultMacro *macro = &ResultMacroList[ resultMacroIndex ];
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
760
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
761 // Current Macro position
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
762 var_uint_t pos = macro->pos;
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
763
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
764 // Length of combo being processed
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
765 uint8_t comboLength = macro->guide[ pos ];
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
766
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
767 // Function Counter, used to keep track of the combo items processed
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
768 var_uint_t funcCount = 0;
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
769
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
770 // Combo Item Position within the guide
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
771 var_uint_t comboItem = pos + 1;
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
772
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
773 // Iterate through the Result Combo
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
774 while ( funcCount < comboLength )
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
775 {
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
776 // Assign TriggerGuide element (key type, state and scancode)
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
777 ResultGuide *guide = (ResultGuide*)(&macro->guide[ comboItem ]);
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
778
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
779 // Do lookup on capability function
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
780 void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func);
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
781
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
782 // Call capability
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
783 capability( macro->state, macro->stateType, &guide->args );
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
784
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
785 // Increment counters
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
786 funcCount++;
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
787 comboItem += ResultGuideSize( (ResultGuide*)(&macro->guide[ comboItem ]) );
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
788 }
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
789
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
790 // Move to next item in the sequence
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
791 macro->pos = comboItem;
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
792
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
793 // If the ResultMacro is finished, remove
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
794 if ( macro->guide[ comboItem ] == 0 )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
795 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
796 return ResultMacroEval_Remove;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
797 }
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
798
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
799 // Otherwise leave the macro in the list
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
800 return ResultMacroEval_DoNothing;
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
801 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
802
159
84beeecd2c94 Kishsaver is fully working with DPH!
Jacob Alexander <haata@kiibohd.com>
parents: 150
diff changeset
803
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
804 // Update pending trigger list
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
805 inline void Macro_updateTriggerMacroPendingList()
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
806 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
807 // Iterate over the macroTriggerListBuffer to add any new Trigger Macros to the pending list
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
808 for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
809 {
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
810 // TODO LED States
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
811 // TODO Analog Switches
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
812 // Only add TriggerMacro to pending list if key was pressed (not held, released or off)
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
813 if ( macroTriggerListBuffer[ key ].state == 0x00 && macroTriggerListBuffer[ key ].state != 0x01 )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
814 continue;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
815
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
816 // Lookup Trigger List
202
1a68a9a04ad3 Adding variable width state variable width.
Jacob Alexander <haata@kiibohd.com>
parents: 201
diff changeset
817 nat_ptr_t *triggerList = Macro_layerLookup( macroTriggerListBuffer[ key ].scanCode );
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
818
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
819 // Number of Triggers in list
202
1a68a9a04ad3 Adding variable width state variable width.
Jacob Alexander <haata@kiibohd.com>
parents: 201
diff changeset
820 nat_ptr_t triggerListSize = triggerList[0];
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
821
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
822 // Iterate over triggerList to see if any TriggerMacros need to be added
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
823 // First item is the number of items in the TriggerList
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
824 for ( var_uint_t macro = 1; macro < triggerListSize + 1; macro++ )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
825 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
826 // Lookup trigger macro index
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
827 var_uint_t triggerMacroIndex = triggerList[ macro ];
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
828
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
829 // Iterate over macroTriggerMacroPendingList to see if any macro in the scancode's
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
830 // triggerList needs to be added
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
831 var_uint_t pending = 0;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
832 for ( ; pending < macroTriggerMacroPendingListSize; pending++ )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
833 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
834 // Stop scanning if the trigger macro index is found in the pending list
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
835 if ( macroTriggerMacroPendingList[ pending ] == triggerMacroIndex )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
836 break;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
837 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
838
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
839 // If the triggerMacroIndex (macro) was not found in the macroTriggerMacroPendingList
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
840 // Add it to the list
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
841 if ( pending == macroTriggerMacroPendingListSize )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
842 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
843 macroTriggerMacroPendingList[ macroTriggerMacroPendingListSize++ ] = triggerMacroIndex;
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
844
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
845 // Reset macro position
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
846 TriggerMacroList[ triggerMacroIndex ].pos = 0;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
847 TriggerMacroList[ triggerMacroIndex ].state = TriggerMacro_Waiting;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
848 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
849 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
850 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
851 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
852
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
853
185
68f3dc0cddd0 Macro cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 184
diff changeset
854 // Macro Procesing Loop
68f3dc0cddd0 Macro cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 184
diff changeset
855 // Called once per USB buffer send
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
856 inline void Macro_process()
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
857 {
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
858 // Only do one round of macro processing between Output Module timer sends
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
859 if ( USBKeys_Sent != 0 )
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
860 return;
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
861
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
862 // If the pause flag is set, only process if the step counter is non-zero
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
863 if ( macroPauseMode )
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
864 {
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
865 if ( macroStepCounter == 0 )
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
866 return;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
867
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
868 // Proceed, decrementing the step counter
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
869 macroStepCounter--;
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
870 dbug_print("Macro Step");
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
871 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
872
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
873 // Update pending trigger list, before processing TriggerMacros
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
874 Macro_updateTriggerMacroPendingList();
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
875
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
876 // Tail pointer for macroTriggerMacroPendingList
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
877 // Macros must be explicitly re-added
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
878 var_uint_t macroTriggerMacroPendingListTail = 0;
185
68f3dc0cddd0 Macro cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 184
diff changeset
879
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
880 // Iterate through the pending TriggerMacros, processing each of them
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
881 for ( var_uint_t macro = 0; macro < macroTriggerMacroPendingListSize; macro++ )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
882 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
883 switch ( Macro_evalTriggerMacro( macroTriggerMacroPendingList[ macro ] ) )
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
884 {
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
885 // Trigger Result Macro (purposely falling through)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
886 case TriggerMacroEval_DoResult:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
887 // Append ResultMacro to PendingList
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
888 Macro_appendResultMacroToPendingList( &TriggerMacroList[ macroTriggerMacroPendingList[ macro ] ] );
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
889
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
890 default:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
891 macroTriggerMacroPendingList[ macroTriggerMacroPendingListTail++ ] = macroTriggerMacroPendingList[ macro ];
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
892 break;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
893
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
894 // Trigger Result Macro and Remove (purposely falling through)
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
895 case TriggerMacroEval_DoResultAndRemove:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
896 // Append ResultMacro to PendingList
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
897 Macro_appendResultMacroToPendingList( &TriggerMacroList[ macroTriggerMacroPendingList[ macro ] ] );
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
898
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
899 // Remove Macro from Pending List, nothing to do, removing by default
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
900 case TriggerMacroEval_Remove:
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
901 break;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
902 }
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
903 }
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
904
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
905 // Update the macroTriggerMacroPendingListSize with the tail pointer
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
906 macroTriggerMacroPendingListSize = macroTriggerMacroPendingListTail;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
907
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
908
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
909 // Tail pointer for macroResultMacroPendingList
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
910 // Macros must be explicitly re-added
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
911 var_uint_t macroResultMacroPendingListTail = 0;
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
912
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
913 // Iterate through the pending ResultMacros, processing each of them
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
914 for ( var_uint_t macro = 0; macro < macroResultMacroPendingListSize; macro++ )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
915 {
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
916 switch ( Macro_evalResultMacro( macroResultMacroPendingList[ macro ] ) )
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
917 {
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
918 // Re-add macros to pending list
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
919 case ResultMacroEval_DoNothing:
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
920 default:
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
921 macroResultMacroPendingList[ macroResultMacroPendingListTail++ ] = macroResultMacroPendingList[ macro ];
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
922 break;
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
923
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
924 // Remove Macro from Pending List, nothing to do, removing by default
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
925 case ResultMacroEval_Remove:
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
926 break;
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
927 }
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
928 }
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
929
190
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
930 // Update the macroResultMacroPendingListSize with the tail pointer
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
931 macroResultMacroPendingListSize = macroResultMacroPendingListTail;
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
932
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
933 // Signal buffer that we've used it
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
934 Scan_finishedWithMacro( macroTriggerListBufferSize );
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
935
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
936 // Reset TriggerList buffer
7a71c6e38d56 Macro processing is now feature complete.
Jacob Alexander <haata@kiibohd.com>
parents: 189
diff changeset
937 macroTriggerListBufferSize = 0;
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
938
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
939 // If Macro debug mode is set, clear the USB Buffer
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
940 if ( macroDebugMode )
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
941 {
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
942 USBKeys_Modifiers = 0;
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
943 USBKeys_Sent = 0;
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
944 }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
945 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
946
185
68f3dc0cddd0 Macro cleanup.
Jacob Alexander <haata@kiibohd.com>
parents: 184
diff changeset
947
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
948 inline void Macro_setup()
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
949 {
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
950 // Register Macro CLI dictionary
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
951 CLI_registerDictionary( macroCLIDict, macroCLIDictName );
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
952
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
953 // Disable Macro debug mode
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
954 macroDebugMode = 0;
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
955
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
956 // Disable Macro pause flag
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
957 macroPauseMode = 0;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
958
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
959 // Set Macro step counter to zero
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
960 macroStepCounter = 0;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
961
176
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
962 // Make sure macro trigger buffer is empty
d3ae6b409cfa Initial work for partial layers and macros.
Jacob Alexander <haata@kiibohd.com>
parents: 166
diff changeset
963 macroTriggerListBufferSize = 0;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
964
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
965 // Initialize TriggerMacro states
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
966 for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
967 {
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
968 TriggerMacroList[ macro ].pos = 0;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
969 TriggerMacroList[ macro ].state = TriggerMacro_Waiting;
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
970 }
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
971
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
972 // Initialize ResultMacro states
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
973 for ( var_uint_t macro = 0; macro < ResultMacroNum; macro++ )
189
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
974 {
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
975 ResultMacroList[ macro ].pos = 0;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
976 ResultMacroList[ macro ].state = 0;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
977 ResultMacroList[ macro ].stateType = 0;
4493d8d2c959 Adding TriggerMacro processing.
Jacob Alexander <haata@kiibohd.com>
parents: 186
diff changeset
978 }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
979 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
980
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
981
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
982 // ----- CLI Command Functions -----
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
983
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
984 void cliFunc_capList( char* args )
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
985 {
180
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
986 print( NL );
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
987 info_msg("Capabilities List");
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
988 printHex( CapabilitiesNum );
180
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
989
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
990 // Iterate through all of the capabilities and display them
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
991 for ( var_uint_t cap = 0; cap < CapabilitiesNum; cap++ )
180
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
992 {
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
993 print( NL "\t" );
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
994 printHex( cap );
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
995 print(" - ");
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
996
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
997 // Display/Lookup Capability Name (utilize debug mode of capability)
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
998 void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
180
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
999 capability( 0xFF, 0xFF, 0 );
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
1000 }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1001 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1002
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1003 void cliFunc_capSelect( char* args )
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1004 {
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1005 // Parse code from argument
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1006 char* curArgs;
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1007 char* arg1Ptr;
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1008 char* arg2Ptr = args;
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1009
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1010 // Total number of args to scan (must do a lookup if a keyboard capability is selected)
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1011 var_uint_t totalArgs = 2; // Always at least two args
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1012 var_uint_t cap = 0;
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1013
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1014 // Arguments used for keyboard capability function
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1015 var_uint_t argSetCount = 0;
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1016 uint8_t *argSet = (uint8_t*)args;
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1017
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1018 // Process all args
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1019 for ( var_uint_t c = 0; argSetCount < totalArgs; c++ )
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1020 {
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1021 curArgs = arg2Ptr;
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1022 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1023
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1024 // Stop processing args if no more are found
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1025 // Extra arguments are ignored
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1026 if ( *arg1Ptr == '\0' )
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1027 break;
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1028
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1029 // For the first argument, choose the capability
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1030 if ( c == 0 ) switch ( arg1Ptr[0] )
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1031 {
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1032 // Keyboard Capability
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1033 case 'K':
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1034 // Determine capability index
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1035 cap = numToInt( &arg1Ptr[1] );
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1036
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1037 // Lookup the number of args
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1038 totalArgs += CapabilitiesList[ cap ].argCount;
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1039 continue;
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1040 }
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1041
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1042 // Because allocating memory isn't doable, and the argument count is arbitrary
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1043 // The argument pointer is repurposed as the argument list (much smaller anyways)
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1044 argSet[ argSetCount++ ] = (uint8_t)numToInt( arg1Ptr );
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1045
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1046 // Once all the arguments are prepared, call the keyboard capability function
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1047 if ( argSetCount == totalArgs )
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1048 {
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1049 // Indicate that the capability was called
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1050 print( NL );
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1051 info_msg("K");
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1052 printInt8( cap );
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1053 print(" - ");
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1054 printHex( argSet[0] );
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1055 print(" - ");
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1056 printHex( argSet[1] );
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1057 print(" - ");
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1058 printHex( argSet[2] );
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1059 print( "..." NL );
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1060
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1061 void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1062 capability( argSet[0], argSet[1], &argSet[2] );
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1063 }
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1064 }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1065 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1066
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1067 void cliFunc_keyHold( char* args )
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1068 {
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1069 // Parse codes from arguments
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1070 char* curArgs;
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1071 char* arg1Ptr;
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1072 char* arg2Ptr = args;
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1073
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1074 // Process all args
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1075 for ( ;; )
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1076 {
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1077 curArgs = arg2Ptr;
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1078 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1079
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1080 // Stop processing args if no more are found
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1081 if ( *arg1Ptr == '\0' )
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1082 break;
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1083
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1084 // Ignore non-Scancode numbers
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1085 switch ( arg1Ptr[0] )
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1086 {
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1087 // Scancode
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1088 case 'S':
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1089 Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x02 ); // Hold scancode
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1090 break;
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1091 }
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1092 }
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1093 }
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1094
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1095 void cliFunc_keyPress( char* args )
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1096 {
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1097 // Parse codes from arguments
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1098 char* curArgs;
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1099 char* arg1Ptr;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1100 char* arg2Ptr = args;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1101
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1102 // Process all args
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1103 for ( ;; )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1104 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1105 curArgs = arg2Ptr;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1106 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1107
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1108 // Stop processing args if no more are found
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1109 if ( *arg1Ptr == '\0' )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1110 break;
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1111
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1112 // Ignore non-Scancode numbers
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1113 switch ( arg1Ptr[0] )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1114 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1115 // Scancode
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1116 case 'S':
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1117 Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x01 ); // Press scancode
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1118 break;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1119 }
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1120 }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1121 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1122
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1123 void cliFunc_keyRelease( char* args )
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1124 {
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1125 // Parse codes from arguments
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1126 char* curArgs;
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1127 char* arg1Ptr;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1128 char* arg2Ptr = args;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1129
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1130 // Process all args
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1131 for ( ;; )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1132 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1133 curArgs = arg2Ptr;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1134 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1135
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1136 // Stop processing args if no more are found
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1137 if ( *arg1Ptr == '\0' )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1138 break;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1139
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1140 // Ignore non-Scancode numbers
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1141 switch ( arg1Ptr[0] )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1142 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1143 // Scancode
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1144 case 'S':
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1145 Macro_keyState( (uint8_t)numToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1146 break;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1147 }
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1148 }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1149 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1150
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1151 void cliFunc_layerList( char* args )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1152 {
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1153 print( NL );
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1154 info_msg("Layer List");
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1155
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1156 // Iterate through all of the layers and display them
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1157 for ( uint16_t layer = 0; layer < LayerNum; layer++ )
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1158 {
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1159 print( NL "\t" );
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1160 printHex( layer );
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1161 print(" - ");
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1162
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1163 // Display layer name
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1164 dPrint( (char*)LayerIndex[ layer ].name );
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1165
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1166 // Default map
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1167 if ( layer == 0 )
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1168 print(" \033[1m(default)\033[0m");
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1169
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1170 // Layer State
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1171 print( NL "\t\t Layer State: " );
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
1172 printHex( LayerState[ layer ] );
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1173
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
1174 // First -> Last Indices
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
1175 print(" First -> Last Indices: ");
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
1176 printHex( LayerIndex[ layer ].first );
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
1177 print(" -> ");
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
1178 printHex( LayerIndex[ layer ].last );
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1179 }
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1180 }
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1181
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1182 void cliFunc_layerState( char* args )
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1183 {
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1184 // Parse codes from arguments
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1185 char* curArgs;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1186 char* arg1Ptr;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1187 char* arg2Ptr = args;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1188
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1189 uint8_t arg1 = 0;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1190 uint8_t arg2 = 0;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1191
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1192 // Process first two args
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1193 for ( uint8_t c = 0; c < 2; c++ )
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1194 {
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1195 curArgs = arg2Ptr;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1196 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1197
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1198 // Stop processing args if no more are found
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1199 if ( *arg1Ptr == '\0' )
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1200 break;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1201
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1202 switch ( c )
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1203 {
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1204 // First argument (e.g. L1)
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1205 case 0:
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1206 if ( arg1Ptr[0] != 'L' )
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1207 return;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1208
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1209 arg1 = (uint8_t)numToInt( &arg1Ptr[1] );
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1210 break;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1211 // Second argument (e.g. 4)
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1212 case 1:
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1213 arg2 = (uint8_t)numToInt( arg1Ptr );
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1214
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1215 // Display operation (to indicate that it worked)
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1216 print( NL );
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1217 info_msg("Setting Layer L");
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1218 printInt8( arg1 );
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1219 print(" to - ");
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1220 printHex( arg2 );
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1221
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1222 // Set the layer state
214
5a5404338b9f Adding support for layer packing
Jacob Alexander <haata@kiibohd.com>
parents: 205
diff changeset
1223 LayerState[ arg1 ] = arg2;
183
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1224 break;
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1225 }
bb96551a3065 Added layerList and layerState functions
Jacob Alexander <haata@kiibohd.com>
parents: 182
diff changeset
1226 }
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1227 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1228
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1229 void cliFunc_macroDebug( char* args )
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1230 {
126
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1231 // Toggle macro debug mode
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1232 macroDebugMode = macroDebugMode ? 0 : 1;
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1233
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1234 print( NL );
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1235 info_msg("Macro Debug Mode: ");
670fc9c3a739 Added CLI DefaultMap lookup command.
Jacob Alexander <haata@kiibohd.com>
parents: 125
diff changeset
1236 printInt8( macroDebugMode );
125
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1237 }
8dab4014c398 Major code cleanup and preparation for PartialMap Macro Module
Jacob Alexander <haata@kiibohd.com>
parents:
diff changeset
1238
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1239 void cliFunc_macroList( char* args )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1240 {
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1241 // Show pending key events
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1242 print( NL );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1243 info_msg("Pending Key Events: ");
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1244 printInt16( (uint16_t)macroTriggerListBufferSize );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1245 print(" : ");
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1246 for ( uint8_t key = 0; key < macroTriggerListBufferSize; key++ )
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1247 {
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1248 printHex( macroTriggerListBuffer[ key ].scanCode );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1249 print(" ");
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1250 }
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1251
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1252 // Show pending trigger macros
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1253 print( NL );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1254 info_msg("Pending Trigger Macros: ");
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1255 printInt16( (uint16_t)macroTriggerMacroPendingListSize );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1256 print(" : ");
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1257 for ( var_uint_t macro = 0; macro < macroTriggerMacroPendingListSize; macro++ )
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1258 {
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1259 printHex( macroTriggerMacroPendingList[ macro ] );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1260 print(" ");
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1261 }
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1262
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1263 // Show pending result macros
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1264 print( NL );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1265 info_msg("Pending Result Macros: ");
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1266 printInt16( (uint16_t)macroResultMacroPendingListSize );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1267 print(" : ");
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1268 for ( var_uint_t macro = 0; macro < macroResultMacroPendingListSize; macro++ )
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1269 {
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1270 printHex( macroResultMacroPendingList[ macro ] );
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1271 print(" ");
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1272 }
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1273
181
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1274 // Show available trigger macro indices
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1275 print( NL );
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1276 info_msg("Trigger Macros Range: T0 -> T");
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1277 printInt16( (uint16_t)TriggerMacroNum - 1 ); // Hopefully large enough :P (can't assume 32-bit)
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1278
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1279 // Show available result macro indices
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1280 print( NL );
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1281 info_msg("Result Macros Range: R0 -> R");
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1282 printInt16( (uint16_t)ResultMacroNum - 1 ); // Hopefully large enough :P (can't assume 32-bit)
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1283
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1284 // Show Trigger to Result Macro Links
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1285 print( NL );
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1286 info_msg("Trigger : Result Macro Pairs");
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1287 for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
181
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1288 {
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1289 print( NL );
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1290 print("\tT");
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1291 printInt16( (uint16_t)macro ); // Hopefully large enough :P (can't assume 32-bit)
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1292 print(" : R");
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1293 printInt16( (uint16_t)TriggerMacroList[ macro ].result ); // Hopefully large enough :P (can't assume 32-bit)
80a44dcdafaf Adding macroList debug function
Jacob Alexander <haata@kiibohd.com>
parents: 180
diff changeset
1294 }
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1295 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1296
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1297 void cliFunc_macroProc( char* args )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1298 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1299 // Toggle macro pause mode
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1300 macroPauseMode = macroPauseMode ? 0 : 1;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1301
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1302 print( NL );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1303 info_msg("Macro Processing Mode: ");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1304 printInt8( macroPauseMode );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1305 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1306
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1307 void macroDebugShowTrigger( var_uint_t index )
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1308 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1309 // Only proceed if the macro exists
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1310 if ( index >= TriggerMacroNum )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1311 return;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1312
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1313 // Trigger Macro Show
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1314 TriggerMacro *macro = &TriggerMacroList[ index ];
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1315
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1316 print( NL );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1317 info_msg("Trigger Macro Index: ");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1318 printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit)
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1319 print( NL );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1320
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1321 // Read the comboLength for combo in the sequence (sequence of combos)
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1322 var_uint_t pos = 0;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1323 uint8_t comboLength = macro->guide[ pos ];
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1324
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1325 // Iterate through and interpret the guide
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1326 while ( comboLength != 0 )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1327 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1328 // Initial position of the combo
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1329 var_uint_t comboPos = ++pos;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1330
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1331 // Iterate through the combo
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1332 while ( pos < comboLength * TriggerGuideSize + comboPos )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1333 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1334 // Assign TriggerGuide element (key type, state and scancode)
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1335 TriggerGuide *guide = (TriggerGuide*)(&macro->guide[ pos ]);
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1336
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1337 // Display guide information about trigger key
184
f9ef267ccc8b Adding layer fall-through lookup
Jacob Alexander <haata@kiibohd.com>
parents: 183
diff changeset
1338 printHex( guide->scanCode );
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1339 print("|");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1340 printHex( guide->type );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1341 print("|");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1342 printHex( guide->state );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1343
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1344 // Increment position
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1345 pos += TriggerGuideSize;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1346
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1347 // Only show combo separator if there are combos left in the sequence element
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1348 if ( pos < comboLength * TriggerGuideSize + comboPos )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1349 print("+");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1350 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1351
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1352 // Read the next comboLength
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1353 comboLength = macro->guide[ pos ];
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1354
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1355 // Only show sequence separator if there is another combo to process
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1356 if ( comboLength != 0 )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1357 print(";");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1358 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1359
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1360 // Display current position
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1361 print( NL "Position: " );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1362 printInt16( (uint16_t)macro->pos ); // Hopefully large enough :P (can't assume 32-bit)
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1363
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1364 // Display result macro index
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1365 print( NL "Result Macro Index: " );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1366 printInt16( (uint16_t)macro->result ); // Hopefully large enough :P (can't assume 32-bit)
196
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1367
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1368 // Display trigger macro state
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1369 print( NL "Trigger Macro State: " );
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1370 switch ( macro->state )
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1371 {
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1372 case TriggerMacro_Press: print("Press"); break;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1373 case TriggerMacro_Release: print("Release"); break;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1374 case TriggerMacro_Waiting: print("Waiting"); break;
8ecfdaa27234 Basic Trigger and Result Macros are now working.
Jacob Alexander <haata@kiibohd.com>
parents: 195
diff changeset
1375 }
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1376 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1377
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1378 void macroDebugShowResult( var_uint_t index )
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1379 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1380 // Only proceed if the macro exists
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1381 if ( index >= ResultMacroNum )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1382 return;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1383
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1384 // Trigger Macro Show
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1385 ResultMacro *macro = &ResultMacroList[ index ];
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1386
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1387 print( NL );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1388 info_msg("Result Macro Index: ");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1389 printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit)
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1390 print( NL );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1391
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1392 // Read the comboLength for combo in the sequence (sequence of combos)
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1393 var_uint_t pos = 0;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1394 uint8_t comboLength = macro->guide[ pos++ ];
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1395
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1396 // Iterate through and interpret the guide
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1397 while ( comboLength != 0 )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1398 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1399 // Function Counter, used to keep track of the combos processed
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1400 var_uint_t funcCount = 0;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1401
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1402 // Iterate through the combo
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1403 while ( funcCount < comboLength )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1404 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1405 // Assign TriggerGuide element (key type, state and scancode)
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1406 ResultGuide *guide = (ResultGuide*)(&macro->guide[ pos ]);
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1407
180
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
1408 // Display Function Index
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
1409 printHex( guide->index );
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
1410 print("|");
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
1411
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1412 // Display Function Ptr Address
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1413 printHex( (nat_ptr_t)CapabilitiesList[ guide->index ].func );
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1414 print("|");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1415
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1416 // Display/Lookup Capability Name (utilize debug mode of capability)
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1417 void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func);
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1418 capability( 0xFF, 0xFF, 0 );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1419
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1420 // Display Argument(s)
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1421 print("(");
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1422 for ( var_uint_t arg = 0; arg < CapabilitiesList[ guide->index ].argCount; arg++ )
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1423 {
180
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
1424 // Arguments are only 8 bit values
ed56f7873645 Added capabilities list debug option
Jacob Alexander <haata@kiibohd.com>
parents: 179
diff changeset
1425 printHex( (&guide->args)[ arg ] );
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1426
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1427 // Only show arg separator if there are args left
182
880c33236cd1 Added capSelect function that can arbitrary run a keyboard capability
Jacob Alexander <haata@kiibohd.com>
parents: 181
diff changeset
1428 if ( arg + 1 < CapabilitiesList[ guide->index ].argCount )
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1429 print(",");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1430 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1431 print(")");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1432
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1433 // Increment position
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1434 pos += ResultGuideSize( guide );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1435
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1436 // Increment function count
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1437 funcCount++;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1438
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1439 // Only show combo separator if there are combos left in the sequence element
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1440 if ( funcCount < comboLength )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1441 print("+");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1442 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1443
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1444 // Read the next comboLength
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1445 comboLength = macro->guide[ pos++ ];
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1446
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1447 // Only show sequence separator if there is another combo to process
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1448 if ( comboLength != 0 )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1449 print(";");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1450 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1451
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1452 // Display current position
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1453 print( NL "Position: " );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1454 printInt16( (uint16_t)macro->pos ); // Hopefully large enough :P (can't assume 32-bit)
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1455
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1456 // Display final trigger state/type
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1457 print( NL "Final Trigger State (State/Type): " );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1458 printHex( macro->state );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1459 print("/");
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1460 printHex( macro->stateType );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1461 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1462
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1463 void cliFunc_macroShow( char* args )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1464 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1465 // Parse codes from arguments
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1466 char* curArgs;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1467 char* arg1Ptr;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1468 char* arg2Ptr = args;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1469
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1470 // Process all args
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1471 for ( ;; )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1472 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1473 curArgs = arg2Ptr;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1474 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1475
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1476 // Stop processing args if no more are found
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1477 if ( *arg1Ptr == '\0' )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1478 break;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1479
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1480 // Ignore invalid codes
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1481 switch ( arg1Ptr[0] )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1482 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1483 // Indexed Trigger Macro
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1484 case 'T':
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1485 macroDebugShowTrigger( numToInt( &arg1Ptr[1] ) );
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1486 break;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1487 // Indexed Result Macro
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1488 case 'R':
195
58cfcb7bac88 Changing decToInt to numToInt (adds support for Hex number interpreter)
Jacob Alexander <haata@kiibohd.com>
parents: 192
diff changeset
1489 macroDebugShowResult( numToInt( &arg1Ptr[1] ) );
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1490 break;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1491 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1492 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1493 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1494
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1495 void cliFunc_macroStep( char* args )
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1496 {
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1497 // Parse number from argument
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1498 // NOTE: Only first argument is used
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1499 char* arg1Ptr;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1500 char* arg2Ptr;
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1501 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1502
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1503 // Default to 1, if no argument given
204
b718fdb741c3 Updating PartialLayer code to support varying counter widths.
Jacob Alexander <haata@kiibohd.com>
parents: 202
diff changeset
1504 var_uint_t count = (var_uint_t)numToInt( arg1Ptr );
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1505
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1506 if ( count == 0 )
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1507 count = 1;
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1508
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1509 // Set the macro step counter, negative int's are cast to uint
192
6ac92b8614c0 Fixing RAM calculator and reduced actual SRAM usage
Jacob Alexander <haata@kiibohd.com>
parents: 191
diff changeset
1510 macroStepCounter = count;
179
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1511 }
e5cf79b516e4 Basic debug trigger/result macro viewer
Jacob Alexander <haata@kiibohd.com>
parents: 176
diff changeset
1512