Mercurial > louis > kiibohd-controller
comparison Output/pjrcUSB/output_com.c @ 309:4f47971c45c2
Merge remote-tracking branch 'upstream/master'
author | Rowan Decker <Smasher816@gmail.com> |
---|---|
date | Sun, 08 Mar 2015 20:17:39 -0700 |
parents | ab4515606277 9c04b0253707 |
children | a6bafeb5fecf |
comparison
equal
deleted
inserted
replaced
308:ab4515606277 | 309:4f47971c45c2 |
---|---|
59 | 59 |
60 | 60 |
61 // ----- Function Declarations ----- | 61 // ----- Function Declarations ----- |
62 | 62 |
63 void cliFunc_kbdProtocol( char* args ); | 63 void cliFunc_kbdProtocol( char* args ); |
64 void cliFunc_outputDebug( char* args ); | |
64 void cliFunc_readLEDs ( char* args ); | 65 void cliFunc_readLEDs ( char* args ); |
65 void cliFunc_sendKeys ( char* args ); | 66 void cliFunc_sendKeys ( char* args ); |
66 void cliFunc_setKeys ( char* args ); | 67 void cliFunc_setKeys ( char* args ); |
67 void cliFunc_setMod ( char* args ); | 68 void cliFunc_setMod ( char* args ); |
68 | 69 |
70 | 71 |
71 // ----- Variables ----- | 72 // ----- Variables ----- |
72 | 73 |
73 // Output Module command dictionary | 74 // Output Module command dictionary |
74 CLIDict_Entry( kbdProtocol, "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode" ); | 75 CLIDict_Entry( kbdProtocol, "Keyboard Protocol Mode: 0 - Boot, 1 - OS/NKRO Mode" ); |
76 CLIDict_Entry( outputDebug, "Toggle Output Debug mode." ); | |
75 CLIDict_Entry( readLEDs, "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc." ); | 77 CLIDict_Entry( readLEDs, "Read LED byte:" NL "\t\t1 NumLck, 2 CapsLck, 4 ScrlLck, 16 Kana, etc." ); |
76 CLIDict_Entry( sendKeys, "Send the prepared list of USB codes and modifier byte." ); | 78 CLIDict_Entry( sendKeys, "Send the prepared list of USB codes and modifier byte." ); |
77 CLIDict_Entry( setKeys, "Prepare a space separated list of USB codes (decimal). Waits until \033[35msendKeys\033[0m." ); | 79 CLIDict_Entry( setKeys, "Prepare a space separated list of USB codes (decimal). Waits until \033[35msendKeys\033[0m." ); |
78 CLIDict_Entry( setMod, "Set the modfier byte:" NL "\t\t1 LCtrl, 2 LShft, 4 LAlt, 8 LGUI, 16 RCtrl, 32 RShft, 64 RAlt, 128 RGUI" ); | 80 CLIDict_Entry( setMod, "Set the modfier byte:" NL "\t\t1 LCtrl, 2 LShft, 4 LAlt, 8 LGUI, 16 RCtrl, 32 RShft, 64 RAlt, 128 RGUI" ); |
79 | 81 |
80 CLIDict_Def( outputCLIDict, "USB Module Commands" ) = { | 82 CLIDict_Def( outputCLIDict, "USB Module Commands" ) = { |
81 CLIDict_Item( kbdProtocol ), | 83 CLIDict_Item( kbdProtocol ), |
84 CLIDict_Item( outputDebug ), | |
82 CLIDict_Item( readLEDs ), | 85 CLIDict_Item( readLEDs ), |
83 CLIDict_Item( sendKeys ), | 86 CLIDict_Item( sendKeys ), |
84 CLIDict_Item( setKeys ), | 87 CLIDict_Item( setKeys ), |
85 CLIDict_Item( setMod ), | 88 CLIDict_Item( setMod ), |
86 { 0, 0, 0 } // Null entry for dictionary end | 89 { 0, 0, 0 } // Null entry for dictionary end |
127 // Indicates whether the Output module is fully functional | 130 // Indicates whether the Output module is fully functional |
128 // 0 - Not fully functional, 1 - Fully functional | 131 // 0 - Not fully functional, 1 - Fully functional |
129 // 0 is often used to show that a USB cable is not plugged in (but has power) | 132 // 0 is often used to show that a USB cable is not plugged in (but has power) |
130 uint8_t Output_Available = 0; | 133 uint8_t Output_Available = 0; |
131 | 134 |
135 // Debug control variable for Output modules | |
136 // 0 - Debug disabled (default) | |
137 // 1 - Debug enabled | |
138 uint8_t Output_DebugMode = 0; | |
139 | |
132 | 140 |
133 | 141 |
134 // ----- Capabilities ----- | 142 // ----- Capabilities ----- |
135 | 143 |
136 // Set Boot Keyboard Protocol | 144 // Set Boot Keyboard Protocol |
209 if ( state == 0x01 || state == 0x03 ) | 217 if ( state == 0x01 || state == 0x03 ) |
210 USBKeys_Changed |= USBKeyChangeState_Consumer; | 218 USBKeys_Changed |= USBKeyChangeState_Consumer; |
211 | 219 |
212 // Only send keypresses if press or hold state | 220 // Only send keypresses if press or hold state |
213 if ( stateType == 0x00 && state == 0x03 ) // Release state | 221 if ( stateType == 0x00 && state == 0x03 ) // Release state |
214 return; | 222 { |
223 USBKeys_ConsCtrl = 0; | |
224 return; | |
225 } | |
215 | 226 |
216 // Set consumer control code | 227 // Set consumer control code |
217 USBKeys_ConsCtrl = *(uint16_t*)(&args[0]); | 228 USBKeys_ConsCtrl = *(uint16_t*)(&args[0]); |
218 } | 229 } |
219 | 230 |
240 if ( state == 0x01 || state == 0x03 ) | 251 if ( state == 0x01 || state == 0x03 ) |
241 USBKeys_Changed |= USBKeyChangeState_System; | 252 USBKeys_Changed |= USBKeyChangeState_System; |
242 | 253 |
243 // Only send keypresses if press or hold state | 254 // Only send keypresses if press or hold state |
244 if ( stateType == 0x00 && state == 0x03 ) // Release state | 255 if ( stateType == 0x00 && state == 0x03 ) // Release state |
245 return; | 256 { |
257 USBKeys_SysCtrl = 0; | |
258 return; | |
259 } | |
246 | 260 |
247 // Set system control code | 261 // Set system control code |
248 USBKeys_SysCtrl = args[0]; | 262 USBKeys_SysCtrl = args[0]; |
249 } | 263 } |
250 | 264 |
582 info_msg("Keyboard Protocol: "); | 596 info_msg("Keyboard Protocol: "); |
583 printInt8( USBKeys_Protocol ); | 597 printInt8( USBKeys_Protocol ); |
584 } | 598 } |
585 | 599 |
586 | 600 |
587 void cliFunc_readLEDs( char* args ) | 601 void cliFunc_outputDebug( char* args ) |
588 { | |
589 print( NL ); | |
590 info_msg("LED State: "); | |
591 printInt8( USBKeys_LEDs ); | |
592 } | |
593 | |
594 | |
595 void cliFunc_sendKeys( char* args ) | |
596 { | |
597 // Copy USBKeys_KeysCLI to USBKeys_Keys | |
598 for ( uint8_t key = 0; key < USBKeys_SentCLI; ++key ) | |
599 { | |
600 // TODO | |
601 //USBKeys_Keys[key] = USBKeys_KeysCLI[key]; | |
602 } | |
603 USBKeys_Sent = USBKeys_SentCLI; | |
604 | |
605 // Set modifier byte | |
606 USBKeys_Modifiers = USBKeys_ModifiersCLI; | |
607 } | |
608 | |
609 | |
610 void cliFunc_setKeys( char* args ) | |
611 { | |
612 char* curArgs; | |
613 char* arg1Ptr; | |
614 char* arg2Ptr = args; | |
615 | |
616 // Parse up to USBKeys_MaxSize args (whichever is least) | |
617 for ( USBKeys_SentCLI = 0; USBKeys_SentCLI < USB_BOOT_MAX_KEYS; ++USBKeys_SentCLI ) | |
618 { | |
619 curArgs = arg2Ptr; | |
620 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
621 | |
622 // Stop processing args if no more are found | |
623 if ( *arg1Ptr == '\0' ) | |
624 break; | |
625 | |
626 // Add the USB code to be sent | |
627 // TODO | |
628 //USBKeys_KeysCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); | |
629 } | |
630 } | |
631 | |
632 | |
633 void cliFunc_setMod( char* args ) | |
634 { | 602 { |
635 // Parse number from argument | 603 // Parse number from argument |
636 // NOTE: Only first argument is used | 604 // NOTE: Only first argument is used |
637 char* arg1Ptr; | 605 char* arg1Ptr; |
638 char* arg2Ptr; | 606 char* arg2Ptr; |
639 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | 607 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); |
640 | 608 |
609 // Default to 1 if no argument is given | |
610 Output_DebugMode = 1; | |
611 | |
612 if ( arg1Ptr[0] != '\0' ) | |
613 { | |
614 Output_DebugMode = (uint16_t)numToInt( arg1Ptr ); | |
615 } | |
616 } | |
617 | |
618 | |
619 void cliFunc_readLEDs( char* args ) | |
620 { | |
621 print( NL ); | |
622 info_msg("LED State: "); | |
623 printInt8( USBKeys_LEDs ); | |
624 } | |
625 | |
626 | |
627 void cliFunc_sendKeys( char* args ) | |
628 { | |
629 // Copy USBKeys_KeysCLI to USBKeys_Keys | |
630 for ( uint8_t key = 0; key < USBKeys_SentCLI; ++key ) | |
631 { | |
632 // TODO | |
633 //USBKeys_Keys[key] = USBKeys_KeysCLI[key]; | |
634 } | |
635 USBKeys_Sent = USBKeys_SentCLI; | |
636 | |
637 // Set modifier byte | |
638 USBKeys_Modifiers = USBKeys_ModifiersCLI; | |
639 } | |
640 | |
641 | |
642 void cliFunc_setKeys( char* args ) | |
643 { | |
644 char* curArgs; | |
645 char* arg1Ptr; | |
646 char* arg2Ptr = args; | |
647 | |
648 // Parse up to USBKeys_MaxSize args (whichever is least) | |
649 for ( USBKeys_SentCLI = 0; USBKeys_SentCLI < USB_BOOT_MAX_KEYS; ++USBKeys_SentCLI ) | |
650 { | |
651 curArgs = arg2Ptr; | |
652 CLI_argumentIsolation( curArgs, &arg1Ptr, &arg2Ptr ); | |
653 | |
654 // Stop processing args if no more are found | |
655 if ( *arg1Ptr == '\0' ) | |
656 break; | |
657 | |
658 // Add the USB code to be sent | |
659 // TODO | |
660 //USBKeys_KeysCLI[USBKeys_SentCLI] = numToInt( arg1Ptr ); | |
661 } | |
662 } | |
663 | |
664 | |
665 void cliFunc_setMod( char* args ) | |
666 { | |
667 // Parse number from argument | |
668 // NOTE: Only first argument is used | |
669 char* arg1Ptr; | |
670 char* arg2Ptr; | |
671 CLI_argumentIsolation( args, &arg1Ptr, &arg2Ptr ); | |
672 | |
641 USBKeys_ModifiersCLI = numToInt( arg1Ptr ); | 673 USBKeys_ModifiersCLI = numToInt( arg1Ptr ); |
642 } | 674 } |
643 | 675 |