X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=kll.py;h=e9ea19b6d26b4647f0829d6c63173610995240c6;hb=57d01ed8725f2d06bd157d2355bb149172708b3b;hp=95884da14990874b007527a6865d6dbe5b1d7630;hpb=d91c0fb23ffed0382bcd7e42874127f396627aee;p=kiibohd-kll.git diff --git a/kll.py b/kll.py index 95884da..e9ea19b 100755 --- a/kll.py +++ b/kll.py @@ -182,9 +182,10 @@ capabilities_dict = Capabilities() def make_scanCode( token ): scanCode = int( token[1:], 0 ) # Check size, to make sure it's valid - if scanCode > 0xFF: - print ( "{0} ScanCode value {1} is larger than 255".format( ERROR, scanCode ) ) - raise + # XXX Add better check that takes symbolic names into account (i.e. U"Latch5") + #if scanCode > 0xFF: + # print ( "{0} ScanCode value {1} is larger than 255".format( ERROR, scanCode ) ) + # raise return scanCode def make_hidCode( type, token ): @@ -214,9 +215,10 @@ def make_hidCode( type, token ): hidCode = int( token, 0 ) # Check size if a USB Code, to make sure it's valid - if type == 'USBCode' and hidCode > 0xFF: - print ( "{0} USBCode value {1} is larger than 255".format( ERROR, hidCode ) ) - raise + # XXX Add better check that takes symbolic names into account (i.e. U"Latch5") + #if type == 'USBCode' and hidCode > 0xFF: + # print ( "{0} USBCode value {1} is larger than 255".format( ERROR, hidCode ) ) + # raise # Return a tuple, identifying which type it is if type == 'USBCode': @@ -255,6 +257,10 @@ def make_consCode_number( token ): def make_sysCode_number( token ): return make_hidCode_number( 'SysCode', token ) + # Replace key-word with None specifier (which indicates a noneOut capability) +def make_none( token ): + return [[[('NONE', 0)]]] + def make_seqString( token ): # Shifted Characters, and amount to move by to get non-shifted version # US ANSI @@ -269,8 +275,7 @@ def make_seqString( token ): ( ":", 0x01 ), ( "^", -0x10 ), ( "_", -0x18 ), - ( "{}|", -0x1E ), - ( "~", -0x20 ), + ( "{}|~", -0x1E ), ( "@", -0x32 ), ( "?", -0x38 ), ) @@ -462,14 +467,27 @@ def hidCodeToCapability( items ): for sequence in range( 0, len( items[ variant ] ) ): for combo in range( 0, len( items[ variant ][ sequence ] ) ): if items[ variant ][ sequence ][ combo ][0] in backend.requiredCapabilities.keys(): - # Use backend capability name and a single argument - items[ variant ][ sequence ][ combo ] = tuple( - [ backend.capabilityLookup( items[ variant ][ sequence ][ combo ][0] ), - tuple( [ hid_lookup_dictionary[ items[ variant ][ sequence ][ combo ] ] ] ) ] - ) + try: + # Use backend capability name and a single argument + items[ variant ][ sequence ][ combo ] = tuple( + [ backend.capabilityLookup( items[ variant ][ sequence ][ combo ][0] ), + tuple( [ hid_lookup_dictionary[ items[ variant ][ sequence ][ combo ] ] ] ) ] + ) + except KeyError: + print ( "{0} {1} is an invalid HID lookup value".format( ERROR, items[ variant ][ sequence ][ combo ] ) ) + sys.exit( 1 ) return items +# Convert tuple of tuples to list of lists +def listit( t ): + return list( map( listit, t ) ) if isinstance( t, ( list, tuple ) ) else t + +# Convert list of lists to tuple of tuples +def tupleit( t ): + return tuple( map( tupleit, t ) ) if isinstance( t, ( tuple, list ) ) else t + + ## Evaluation Rules def eval_scanCode( triggers, operator, results ): @@ -478,8 +496,26 @@ def eval_scanCode( triggers, operator, results ): triggers = tuple( tuple( tuple( sequence ) for sequence in variant ) for variant in triggers ) results = tuple( tuple( tuple( sequence ) for sequence in variant ) for variant in results ) + # Lookup interconnect id (Current file scope) + # Default to 0 if not specified + if 'ConnectId' not in variables_dict.overallVariables.keys(): + id_num = 0 + else: + id_num = int( variables_dict.overallVariables['ConnectId'] ) + # Iterate over all combinations of triggers and results - for trigger in triggers: + for sequence in triggers: + # Convert tuple of tuples to list of lists so each element can be modified + trigger = listit( sequence ) + + # Create ScanCode entries for trigger + for seq_index, combo in enumerate( sequence ): + for com_index, scancode in enumerate( combo ): + trigger[ seq_index ][ com_index ] = macros_map.scanCodeStore.append( ScanCode( scancode, id_num ) ) + + # Convert back to a tuple of tuples + trigger = tupleit( trigger ) + for result in results: # Append Case if operator == ":+": @@ -535,6 +571,7 @@ usbCode = tokenType('USBCode') >> make_usbCode scanCode = tokenType('ScanCode') >> make_scanCode consCode = tokenType('ConsCode') >> make_consCode sysCode = tokenType('SysCode') >> make_sysCode +none = tokenType('None') >> make_none name = tokenType('Name') number = tokenType('Number') >> make_number comma = tokenType('Comma') @@ -603,7 +640,7 @@ capFunc_sequence = oneplus( ( capFunc_combo | seqString ) + skip( maybe( comma # Trigger / Result Codes triggerCode_outerList = scanCode_sequence >> optionExpansion triggerUSBCode_outerList = usbCode_sequence >> optionExpansion >> hidCodeToCapability -resultCode_outerList = capFunc_sequence >> optionExpansion >> hidCodeToCapability +resultCode_outerList = ( ( capFunc_sequence >> optionExpansion ) | none ) >> hidCodeToCapability ## Main Rules