Kiibohd Controller
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

macro.c 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /* Copyright (C) 2014 by Jacob Alexander
  2. *
  3. * This file is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This file is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this file. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. // ----- Includes -----
  17. // Compiler Includes
  18. #include <Lib/MacroLib.h>
  19. // Project Includes
  20. #include <cli.h>
  21. #include <led.h>
  22. #include <print.h>
  23. #include <scan_loop.h>
  24. #include <output_com.h>
  25. // Keymaps
  26. #include "usb_hid.h"
  27. #include <defaultMap.h>
  28. #include "generatedKeymap.h" // TODO Use actual generated version
  29. // Local Includes
  30. #include "macro.h"
  31. // ----- Function Declarations -----
  32. void cliFunc_capList ( char* args );
  33. void cliFunc_capSelect ( char* args );
  34. void cliFunc_keyPress ( char* args );
  35. void cliFunc_keyRelease( char* args );
  36. void cliFunc_layerLatch( char* args );
  37. void cliFunc_layerList ( char* args );
  38. void cliFunc_layerLock ( char* args );
  39. void cliFunc_macroDebug( char* args );
  40. void cliFunc_macroList ( char* args );
  41. void cliFunc_macroProc ( char* args );
  42. void cliFunc_macroShow ( char* args );
  43. void cliFunc_macroStep ( char* args );
  44. // ----- Variables -----
  45. // Macro Module command dictionary
  46. char* macroCLIDictName = "Macro Module Commands";
  47. CLIDictItem macroCLIDict[] = {
  48. { "capList", "Prints an indexed list of all non USB keycode capabilities.", cliFunc_capList },
  49. { "capSelect", "Triggers the specified capabilities. First two args are state and stateType." NL "\t\t\033[35mK11\033[0m Keyboard Capability 0x0B", cliFunc_capSelect },
  50. { "keyPress", "Send key-presses to the macro module. Held until released. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyPress },
  51. { "keyRelease", "Release a key-press from the macro module. Duplicates have undefined behaviour." NL "\t\t\033[35mS10\033[0m Scancode 0x0A", cliFunc_keyRelease },
  52. { "layerLatch", "Latch the specified indexed layer." NL "\t\t\033[35mL15\033[0m Indexed Layer 0x0F", cliFunc_layerLatch },
  53. { "layerList", "List available layers.", cliFunc_layerList },
  54. { "layerLock", "Lock the specified indexed layer." NL "\t\t\033[35mL2\033[0m Indexed Layer 0x02", cliFunc_layerLock },
  55. { "macroDebug", "Disables/Enables sending USB keycodes to the Output Module and prints U/K codes.", cliFunc_macroDebug },
  56. { "macroList", "List the defined trigger and result macros.", cliFunc_macroList },
  57. { "macroProc", "Pause/Resume macro processing.", cliFunc_macroProc },
  58. { "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 },
  59. { "macroStep", "Do N macro processing steps. Defaults to 1.", cliFunc_macroStep },
  60. { 0, 0, 0 } // Null entry for dictionary end
  61. };
  62. // Macro debug flag - If set, clears the USB Buffers after signalling processing completion
  63. uint8_t macroDebugMode = 0;
  64. // Macro pause flag - If set, the macro module pauses processing, unless unset, or the step counter is non-zero
  65. uint8_t macroPauseMode = 0;
  66. // Macro step counter - If non-zero, the step counter counts down every time the macro module does one processing loop
  67. unsigned int macroStepCounter = 0;
  68. // Key Trigger List Buffer
  69. // * Item 1: scan code
  70. // * Item 2: state
  71. // ...
  72. uint8_t macroTriggerListBuffer[MaxScanCode * 2] = { 0 }; // Each key has a state to be cached
  73. uint8_t macroTriggerListBufferSize = 0;
  74. // TODO, figure out a good way to scale this array size without wasting too much memory, but not rejecting macros
  75. // Possibly could be calculated by the KLL compiler
  76. // XXX It may be possible to calculate the worst case using the KLL compiler
  77. TriggerMacro *triggerMacroPendingList[TriggerMacroNum];
  78. // ----- Functions -----
  79. // Looks up the trigger list for the given scan code (from the active layer)
  80. unsigned int *Macro_layerLookup( uint8_t scanCode )
  81. {
  82. // TODO - No layer fallthrough lookup
  83. return default_scanMap[ scanCode ];
  84. }
  85. // Update the scancode key state
  86. // States:
  87. // * 0x00 - Reserved
  88. // * 0x01 - Pressed
  89. // * 0x02 - Held
  90. // * 0x03 - Released
  91. // * 0x04 - Unpressed (this is currently ignored)
  92. inline void Macro_keyState( uint8_t scanCode, uint8_t state )
  93. {
  94. // Only add to macro trigger list if one of three states
  95. switch ( state )
  96. {
  97. case 0x01: // Pressed
  98. case 0x02: // Held
  99. case 0x03: // Released
  100. macroTriggerListBuffer[ macroTriggerListBufferSize++ ] = scanCode;
  101. macroTriggerListBuffer[ macroTriggerListBufferSize++ ] = state;
  102. break;
  103. }
  104. }
  105. // Update the scancode analog state
  106. // States:
  107. // * 0x00 - Reserved
  108. // * 0x01 - Released
  109. // * 0x02-0xFF - Analog value (low to high)
  110. inline void Macro_analogState( uint8_t scanCode, uint8_t state )
  111. {
  112. // TODO
  113. }
  114. // Update led state
  115. // States:
  116. // * 0x00 - Reserved
  117. // * 0x01 - On
  118. // * 0x02 - Off
  119. inline void Macro_ledState( uint8_t ledCode, uint8_t state )
  120. {
  121. // TODO
  122. }
  123. // Evaluate/Update the TriggerMacro
  124. void Macro_evalTriggerMacro( TriggerMacro *triggerMacro )
  125. {
  126. // Which combo in the sequence is being evaluated
  127. unsigned int comboPos = triggerMacro->pos;
  128. // If combo length is more than 1, cancel trigger macro if an incorrect key is found
  129. uint8_t comboLength = triggerMacro->guide[ comboPos ];
  130. // Iterate over list of keys currently pressed
  131. for ( uint8_t keyPressed = 0; keyPressed < macroTriggerListBufferSize; keyPressed += 2 )
  132. {
  133. // Compare with keys in combo
  134. for ( unsigned int comboKey = 0; comboKey < comboLength; comboKey++ )
  135. {
  136. // Lookup key in combo
  137. uint8_t guideKey = triggerMacro->guide[ comboPos + comboKey + 2 ]; // TODO Only Press/Hold/Release atm
  138. // Sequence Case
  139. if ( comboLength == 1 )
  140. {
  141. // If key matches and only 1 key pressed, increment the TriggerMacro combo position
  142. if ( guideKey == macroTriggerListBuffer[ keyPressed ] && macroTriggerListBufferSize == 1 )
  143. {
  144. triggerMacro->pos += comboLength * 2 + 1;
  145. // TODO check if TriggerMacro is finished, register ResultMacro
  146. return;
  147. }
  148. // If key does not match or more than 1 key pressed, reset the TriggerMacro combo position
  149. triggerMacro->pos = 0;
  150. return;
  151. }
  152. // Combo Case
  153. else
  154. {
  155. // TODO
  156. }
  157. }
  158. }
  159. }
  160. /*
  161. inline void Macro_bufferAdd( uint8_t byte )
  162. {
  163. // Make sure we haven't overflowed the key buffer
  164. // Default function for adding keys to the KeyIndex_Buffer, does a DefaultMap_Lookup
  165. if ( KeyIndex_BufferUsed < KEYBOARD_BUFFER )
  166. {
  167. uint8_t key = DefaultMap_Lookup[byte];
  168. for ( uint8_t c = 0; c < KeyIndex_BufferUsed; c++ )
  169. {
  170. // Key already in the buffer
  171. if ( KeyIndex_Buffer[c] == key )
  172. return;
  173. }
  174. // Add to the buffer
  175. KeyIndex_Buffer[KeyIndex_BufferUsed++] = key;
  176. }
  177. }
  178. inline void Macro_bufferRemove( uint8_t byte )
  179. {
  180. uint8_t key = DefaultMap_Lookup[byte];
  181. // Check for the released key, and shift the other keys lower on the buffer
  182. for ( uint8_t c = 0; c < KeyIndex_BufferUsed; c++ )
  183. {
  184. // Key to release found
  185. if ( KeyIndex_Buffer[c] == key )
  186. {
  187. // Shift keys from c position
  188. for ( uint8_t k = c; k < KeyIndex_BufferUsed - 1; k++ )
  189. KeyIndex_Buffer[k] = KeyIndex_Buffer[k + 1];
  190. // Decrement Buffer
  191. KeyIndex_BufferUsed--;
  192. return;
  193. }
  194. }
  195. // Error case (no key to release)
  196. erro_msg("Could not find key to release: ");
  197. printHex( key );
  198. }
  199. */
  200. inline void Macro_finishWithUSBBuffer( uint8_t sentKeys )
  201. {
  202. }
  203. inline void Macro_process()
  204. {
  205. // Only do one round of macro processing between Output Module timer sends
  206. if ( USBKeys_Sent != 0 )
  207. return;
  208. // If the pause flag is set, only process if the step counter is non-zero
  209. if ( macroPauseMode && macroStepCounter == 0 )
  210. {
  211. return;
  212. }
  213. // Proceed, decrementing the step counter
  214. else
  215. {
  216. macroStepCounter--;
  217. }
  218. // Loop through macro trigger buffer
  219. for ( uint8_t index = 0; index < macroTriggerListBufferSize; index += 2 )
  220. {
  221. // Get scanCode, first item of macroTriggerListBuffer pairs
  222. uint8_t scanCode = macroTriggerListBuffer[ index ];
  223. // Lookup trigger list for this key
  224. unsigned int *triggerList = Macro_layerLookup( scanCode );
  225. // The first element is the length of the trigger list
  226. unsigned int triggerListSize = triggerList[0];
  227. // Loop through the trigger list
  228. for ( unsigned int trigger = 0; trigger < triggerListSize; trigger++ )
  229. {
  230. // Lookup TriggerMacro
  231. TriggerMacro *triggerMacro = (TriggerMacro*)triggerList[ trigger + 1 ];
  232. // Get triggered state of scan code, second item of macroTriggerListBuffer pairs
  233. uint8_t state = macroTriggerListBuffer[ index + 1 ];
  234. // Evaluate Macro
  235. Macro_evalTriggerMacro( triggerMacro );
  236. }
  237. }
  238. /* TODO
  239. // Loop through input buffer
  240. for ( uint8_t index = 0; index < KeyIndex_BufferUsed && !macroDebugMode; index++ )
  241. {
  242. //print(" KEYS: ");
  243. //printInt8( KeyIndex_BufferUsed );
  244. // Get the keycode from the buffer
  245. uint8_t key = KeyIndex_Buffer[index];
  246. // Set the modifier bit if this key is a modifier
  247. if ( (key & KEY_LCTRL) == KEY_LCTRL ) // AND with 0xE0
  248. {
  249. USBKeys_Modifiers |= 1 << (key ^ KEY_LCTRL); // Left shift 1 by key XOR 0xE0
  250. // Modifier processed, move on to the next key
  251. continue;
  252. }
  253. // Too many keys
  254. if ( USBKeys_Sent >= USBKeys_MaxSize )
  255. {
  256. warn_msg("USB Key limit reached");
  257. errorLED( 1 );
  258. break;
  259. }
  260. // Allow ignoring keys with 0's
  261. if ( key != 0 )
  262. {
  263. USBKeys_Array[USBKeys_Sent++] = key;
  264. }
  265. else
  266. {
  267. // Key was not mapped
  268. erro_msg( "Key not mapped... - " );
  269. printHex( key );
  270. errorLED( 1 );
  271. }
  272. }
  273. */
  274. // Signal buffer that we've used it
  275. Scan_finishedWithBuffer( KeyIndex_BufferUsed );
  276. // If Macro debug mode is set, clear the USB Buffer
  277. if ( macroDebugMode )
  278. {
  279. USBKeys_Modifiers = 0;
  280. USBKeys_Sent = 0;
  281. }
  282. }
  283. inline void Macro_setup()
  284. {
  285. // Register Macro CLI dictionary
  286. CLI_registerDictionary( macroCLIDict, macroCLIDictName );
  287. // Disable Macro debug mode
  288. macroDebugMode = 0;
  289. // Disable Macro pause flag
  290. macroPauseMode = 0;
  291. // Set Macro step counter to zero
  292. macroStepCounter = 0;
  293. // Make sure macro trigger buffer is empty
  294. macroTriggerListBufferSize = 0;
  295. }
  296. // ----- CLI Command Functions -----
  297. void cliFunc_capList( char* args )
  298. {
  299. print( NL );
  300. info_msg("Capabilities List");
  301. // Iterate through all of the capabilities and display them
  302. for ( unsigned int cap = 0; cap < CapabilitiesNum; cap++ )
  303. {
  304. print( NL "\t" );
  305. printHex( cap );
  306. print(" - ");
  307. // Display/Lookup Capability Name (utilize debug mode of capability)
  308. void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
  309. capability( 0xFF, 0xFF, 0 );
  310. }
  311. }
  312. void cliFunc_capSelect( char* args )
  313. {
  314. // Parse code from argument
  315. char* curArgs;
  316. char* arg1Ptr;
  317. char* arg2Ptr = args;
  318. // Total number of args to scan (must do a lookup if a keyboard capability is selected)
  319. unsigned int totalArgs = 2; // Always at least two args
  320. unsigned int cap = 0;
  321. // Arguments used for keyboard capability function
  322. unsigned int argSetCount = 0;
  323. uint8_t *argSet = (uint8_t*)args;
  324. // Process all args
  325. for ( unsigned int c = 0; argSetCount < totalArgs; c++ )
  326. {
  327. curArgs = arg2Ptr;
  328. CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
  329. // Stop processing args if no more are found
  330. // Extra arguments are ignored
  331. if ( *arg1Ptr == '\0' )
  332. break;
  333. // For the first argument, choose the capability
  334. if ( c == 0 ) switch ( arg1Ptr[0] )
  335. {
  336. // Keyboard Capability
  337. case 'K':
  338. // Determine capability index
  339. cap = decToInt( &arg1Ptr[1] );
  340. // Lookup the number of args
  341. totalArgs += CapabilitiesList[ cap ].argCount;
  342. continue;
  343. }
  344. // Because allocating memory isn't doable, and the argument count is arbitrary
  345. // The argument pointer is repurposed as the argument list (much smaller anyways)
  346. argSet[ argSetCount++ ] = (uint8_t)decToInt( arg1Ptr );
  347. // Once all the arguments are prepared, call the keyboard capability function
  348. if ( argSetCount == totalArgs )
  349. {
  350. // Indicate that the capability was called
  351. print( NL );
  352. info_msg("K");
  353. printInt8( cap );
  354. print(" - ");
  355. printHex( argSet[0] );
  356. print(" - ");
  357. printHex( argSet[1] );
  358. print(" - ");
  359. printHex( argSet[2] );
  360. print( "..." NL );
  361. void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ cap ].func);
  362. capability( argSet[0], argSet[1], &argSet[2] );
  363. }
  364. }
  365. }
  366. void cliFunc_keyPress( char* args )
  367. {
  368. // Parse codes from arguments
  369. char* curArgs;
  370. char* arg1Ptr;
  371. char* arg2Ptr = args;
  372. // Process all args
  373. for ( ;; )
  374. {
  375. curArgs = arg2Ptr;
  376. CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
  377. // Stop processing args if no more are found
  378. if ( *arg1Ptr == '\0' )
  379. break;
  380. // Ignore non-Scancode numbers
  381. switch ( arg1Ptr[0] )
  382. {
  383. // Scancode
  384. case 'S':
  385. Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x01 ); // Press scancode
  386. break;
  387. }
  388. }
  389. }
  390. void cliFunc_keyRelease( char* args )
  391. {
  392. // Parse codes from arguments
  393. char* curArgs;
  394. char* arg1Ptr;
  395. char* arg2Ptr = args;
  396. // Process all args
  397. for ( ;; )
  398. {
  399. curArgs = arg2Ptr;
  400. CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
  401. // Stop processing args if no more are found
  402. if ( *arg1Ptr == '\0' )
  403. break;
  404. // Ignore non-Scancode numbers
  405. switch ( arg1Ptr[0] )
  406. {
  407. // Scancode
  408. case 'S':
  409. Macro_keyState( (uint8_t)decToInt( &arg1Ptr[1] ), 0x03 ); // Release scancode
  410. break;
  411. }
  412. }
  413. }
  414. void cliFunc_layerLatch( char* args )
  415. {
  416. // TODO
  417. }
  418. void cliFunc_layerList( char* args )
  419. {
  420. // TODO
  421. }
  422. void cliFunc_layerLock( char* args )
  423. {
  424. // TODO
  425. }
  426. void cliFunc_macroDebug( char* args )
  427. {
  428. // Toggle macro debug mode
  429. macroDebugMode = macroDebugMode ? 0 : 1;
  430. print( NL );
  431. info_msg("Macro Debug Mode: ");
  432. printInt8( macroDebugMode );
  433. }
  434. void cliFunc_macroList( char* args )
  435. {
  436. // Show available trigger macro indices
  437. print( NL );
  438. info_msg("Trigger Macros Range: T0 -> T");
  439. printInt16( (uint16_t)TriggerMacroNum - 1 ); // Hopefully large enough :P (can't assume 32-bit)
  440. // Show available result macro indices
  441. print( NL );
  442. info_msg("Result Macros Range: R0 -> R");
  443. printInt16( (uint16_t)ResultMacroNum - 1 ); // Hopefully large enough :P (can't assume 32-bit)
  444. // Show Trigger to Result Macro Links
  445. print( NL );
  446. info_msg("Trigger : Result Macro Pairs");
  447. for ( unsigned int macro = 0; macro < TriggerMacroNum; macro++ )
  448. {
  449. print( NL );
  450. print("\tT");
  451. printInt16( (uint16_t)macro ); // Hopefully large enough :P (can't assume 32-bit)
  452. print(" : R");
  453. printInt16( (uint16_t)TriggerMacroList[ macro ].result ); // Hopefully large enough :P (can't assume 32-bit)
  454. }
  455. }
  456. void cliFunc_macroProc( char* args )
  457. {
  458. // Toggle macro pause mode
  459. macroPauseMode = macroPauseMode ? 0 : 1;
  460. print( NL );
  461. info_msg("Macro Processing Mode: ");
  462. printInt8( macroPauseMode );
  463. }
  464. void macroDebugShowTrigger( unsigned int index )
  465. {
  466. // Only proceed if the macro exists
  467. if ( index >= TriggerMacroNum )
  468. return;
  469. // Trigger Macro Show
  470. TriggerMacro *macro = &TriggerMacroList[ index ];
  471. print( NL );
  472. info_msg("Trigger Macro Index: ");
  473. printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit)
  474. print( NL );
  475. // Read the comboLength for combo in the sequence (sequence of combos)
  476. unsigned int pos = 0;
  477. uint8_t comboLength = macro->guide[ pos ];
  478. // Iterate through and interpret the guide
  479. while ( comboLength != 0 )
  480. {
  481. // Initial position of the combo
  482. unsigned int comboPos = ++pos;
  483. // Iterate through the combo
  484. while ( pos < comboLength * TriggerGuideSize + comboPos )
  485. {
  486. // Assign TriggerGuide element (key type, state and scancode)
  487. TriggerGuide *guide = (TriggerGuide*)(&macro->guide[ pos ]);
  488. // Display guide information about trigger key
  489. printHex( guide->scancode );
  490. print("|");
  491. printHex( guide->type );
  492. print("|");
  493. printHex( guide->state );
  494. // Increment position
  495. pos += TriggerGuideSize;
  496. // Only show combo separator if there are combos left in the sequence element
  497. if ( pos < comboLength * TriggerGuideSize + comboPos )
  498. print("+");
  499. }
  500. // Read the next comboLength
  501. comboLength = macro->guide[ pos ];
  502. // Only show sequence separator if there is another combo to process
  503. if ( comboLength != 0 )
  504. print(";");
  505. }
  506. // Display current position
  507. print( NL "Position: " );
  508. printInt16( (uint16_t)macro->pos ); // Hopefully large enough :P (can't assume 32-bit)
  509. // Display result macro index
  510. print( NL "Result Macro Index: " );
  511. printInt16( (uint16_t)macro->result ); // Hopefully large enough :P (can't assume 32-bit)
  512. }
  513. void macroDebugShowResult( unsigned int index )
  514. {
  515. // Only proceed if the macro exists
  516. if ( index >= ResultMacroNum )
  517. return;
  518. // Trigger Macro Show
  519. ResultMacro *macro = &ResultMacroList[ index ];
  520. print( NL );
  521. info_msg("Result Macro Index: ");
  522. printInt16( (uint16_t)index ); // Hopefully large enough :P (can't assume 32-bit)
  523. print( NL );
  524. // Read the comboLength for combo in the sequence (sequence of combos)
  525. unsigned int pos = 0;
  526. uint8_t comboLength = macro->guide[ pos++ ];
  527. // Iterate through and interpret the guide
  528. while ( comboLength != 0 )
  529. {
  530. // Function Counter, used to keep track of the combos processed
  531. unsigned int funcCount = 0;
  532. // Iterate through the combo
  533. while ( funcCount < comboLength )
  534. {
  535. // Assign TriggerGuide element (key type, state and scancode)
  536. ResultGuide *guide = (ResultGuide*)(&macro->guide[ pos ]);
  537. // Display Function Index
  538. printHex( guide->index );
  539. print("|");
  540. // Display Function Ptr Address
  541. printHex( (unsigned int)CapabilitiesList[ guide->index ].func );
  542. print("|");
  543. // Display/Lookup Capability Name (utilize debug mode of capability)
  544. void (*capability)(uint8_t, uint8_t, uint8_t*) = (void(*)(uint8_t, uint8_t, uint8_t*))(CapabilitiesList[ guide->index ].func);
  545. capability( 0xFF, 0xFF, 0 );
  546. // Display Argument(s)
  547. print("(");
  548. for ( unsigned int arg = 0; arg < CapabilitiesList[ guide->index ].argCount; arg++ )
  549. {
  550. // Arguments are only 8 bit values
  551. printHex( (&guide->args)[ arg ] );
  552. // Only show arg separator if there are args left
  553. if ( arg + 1 < CapabilitiesList[ guide->index ].argCount )
  554. print(",");
  555. }
  556. print(")");
  557. // Increment position
  558. pos += ResultGuideSize( guide );
  559. // Increment function count
  560. funcCount++;
  561. // Only show combo separator if there are combos left in the sequence element
  562. if ( funcCount < comboLength )
  563. print("+");
  564. }
  565. // Read the next comboLength
  566. comboLength = macro->guide[ pos++ ];
  567. // Only show sequence separator if there is another combo to process
  568. if ( comboLength != 0 )
  569. print(";");
  570. }
  571. // Display current position
  572. print( NL "Position: " );
  573. printInt16( (uint16_t)macro->pos ); // Hopefully large enough :P (can't assume 32-bit)
  574. // Display final trigger state/type
  575. print( NL "Final Trigger State (State/Type): " );
  576. printHex( macro->state );
  577. print("/");
  578. printHex( macro->stateType );
  579. }
  580. void cliFunc_macroShow( char* args )
  581. {
  582. // Parse codes from arguments
  583. char* curArgs;
  584. char* arg1Ptr;
  585. char* arg2Ptr = args;
  586. // Process all args
  587. for ( ;; )
  588. {
  589. curArgs = arg2Ptr;
  590. CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr );
  591. // Stop processing args if no more are found
  592. if ( *arg1Ptr == '\0' )
  593. break;
  594. // Ignore invalid codes
  595. switch ( arg1Ptr[0] )
  596. {
  597. // Indexed Trigger Macro
  598. case 'T':
  599. macroDebugShowTrigger( decToInt( &arg1Ptr[1] ) );
  600. break;
  601. // Indexed Result Macro
  602. case 'R':
  603. macroDebugShowResult( decToInt( &arg1Ptr[1] ) );
  604. break;
  605. }
  606. }
  607. }
  608. void cliFunc_macroStep( char* args )
  609. {
  610. // Parse number from argument
  611. // NOTE: Only first argument is used
  612. char* arg1Ptr;
  613. char* arg2Ptr;
  614. CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr );
  615. // Set the macro step counter, negative int's are cast to uint
  616. macroStepCounter = (unsigned int)decToInt( arg1Ptr );
  617. }