Archived
1
0

Adding support for USB Code trigger assignment

- Added USBCode "cached assignment"
- Added ANSI -> Colemak USBCode assignment kll file
- Removed debug printing
This commit is contained in:
Jacob Alexander 2014-09-07 21:32:36 -07:00
parent 81231a708e
commit 0fe79f3418
4 changed files with 69 additions and 25 deletions

31
examples/colemak.kll Normal file
View File

@ -0,0 +1,31 @@
Name = colemak;
Version = 0.1;
Author = "HaaTa (Jacob Alexander) 2014";
KLL = 0.3;
# Modified Date
Date = 2014-09-07;
# Top row
'e' : 'f';
'r' : 'p';
't' : 'g';
'y' : 'j';
'u' : 'l';
'i' : 'u';
'o' : 'y';
'p' : ';';
# Middle Row
's' : 'r';
'd' : 's';
'f' : 't';
'g' : 'd';
'j' : 'n';
'k' : 'e';
'l' : 'i';
';' : 'o';
# Bottom Row
'n' : 'k';

View File

@ -4,11 +4,12 @@ Author = "HaaTa (Jacob Alexander) 2014";
KLL = 0.3; KLL = 0.3;
# Modified Date # Modified Date
Date = 2014-08-24; Date = 2014-09-07;
# MOVE THIS SECTION to another file # MOVE THIS SECTION to another file
usbKeyOut => Output_usbCodeSend_capability( usbCode : 1 ); usbKeyOut => Output_usbCodeSend_capability( usbCode : 1 );
layerState => Macro_layerState_capability( layer: 2, state : 1 );
# END SECTION # END SECTION

31
kll.py
View File

@ -397,9 +397,6 @@ def eval_scanCode( triggers, operator, results ):
elif operator == ":": elif operator == ":":
macros_map.replaceScanCode( trigger, result ) macros_map.replaceScanCode( trigger, result )
print ( triggers )
print ( results )
def eval_usbCode( triggers, operator, results ): def eval_usbCode( triggers, operator, results ):
# Convert to lists of lists of lists to tuples of tuples of tuples # Convert to lists of lists of lists to tuples of tuples of tuples
# Tuples are non-mutable, and can be used has index items # Tuples are non-mutable, and can be used has index items
@ -411,20 +408,8 @@ def eval_usbCode( triggers, operator, results ):
scanCodes = macros_map.lookupUSBCodes( trigger ) scanCodes = macros_map.lookupUSBCodes( trigger )
for scanCode in scanCodes: for scanCode in scanCodes:
for result in results: for result in results:
# Append Case # Cache assignment until file finishes processing
if operator == ":+": macros_map.cacheAssignment( operator, scanCode, result )
macros_map.appendScanCode( scanCode, result )
# Remove Case
elif operator == ":-":
macros_map.removeScanCode( scanCode, result )
# Replace Case
elif operator == ":":
macros_map.replaceScanCode( scanCode, result )
print ( triggers )
print ( results )
def eval_variable( name, content ): def eval_variable( name, content ):
# Content might be a concatenation of multiple data types, convert everything into a single string # Content might be a concatenation of multiple data types, convert everything into a single string
@ -506,8 +491,8 @@ capability_expression = name + skip( operator('=>') ) + name + skip( parenthesis
#| <trigger> : <result>; #| <trigger> : <result>;
operatorTriggerResult = operator(':') | operator(':+') | operator(':-') operatorTriggerResult = operator(':') | operator(':+') | operator(':-')
scanCode_expression = triggerCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) >> map_scanCode scanCode_expression = triggerCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) >> map_scanCode
usbCode_expression = triggerUSBCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) #>> map_usbCode usbCode_expression = triggerUSBCode_outerList + operatorTriggerResult + resultCode_outerList + skip( eol ) >> map_usbCode
def parse( tokenSequence ): def parse( tokenSequence ):
"""Sequence(Token) -> object""" """Sequence(Token) -> object"""
@ -538,11 +523,11 @@ if __name__ == '__main__':
data = file.read() data = file.read()
tokenSequence = tokenize( data ) tokenSequence = tokenize( data )
print ( pformat( tokenSequence ) ) # Display tokenization #print ( pformat( tokenSequence ) ) # Display tokenization
tree = parse( tokenSequence ) tree = parse( tokenSequence )
#print ( tree )
#print ( variable_dict ) # Apply assignment cache, see 5.1.2 USB Codes for why this is necessary
#print ( capabilities_dict ) macros_map.replayCachedAssignments()
# Do macro correlation and transformation # Do macro correlation and transformation
macros_map.generate() macros_map.generate()

View File

@ -94,6 +94,9 @@ class Macros:
self.triggerList = [] self.triggerList = []
self.maxScanCode = [] self.maxScanCode = []
# USBCode Assignment Cache
self.assignmentCache = []
def __repr__( self ): def __repr__( self ):
return "{0}".format( self.macros ) return "{0}".format( self.macros )
@ -124,11 +127,35 @@ class Macros:
# Scan current layer for USB Codes # Scan current layer for USB Codes
for macro in self.macros[ self.layer ].keys(): for macro in self.macros[ self.layer ].keys():
if usbCode == self.macros[ self.layer ][ macro ]: if usbCode in self.macros[ self.layer ][ macro ]:
scanCodeList.append( macro ) scanCodeList.append( macro )
return scanCodeList return scanCodeList
# Cache USBCode Assignment
def cacheAssignment( self, operator, scanCode, result ):
self.assignmentCache.append( [ operator, scanCode, result ] )
# Assign cached USBCode Assignments
def replayCachedAssignments( self ):
# Iterate over each item in the assignment cache
for item in self.assignmentCache:
# Check operator, and choose the specified assignment action
# Append Case
if item[0] == ":+":
self.appendScanCode( item[1], item[2] )
# Remove Case
elif item[0] == ":-":
self.removeScanCode( item[1], item[2] )
# Replace Case
elif item[0] == ":":
self.replaceScanCode( item[1], item[2] )
# Clear assignment cache
self.assignmentCache = []
# Generate/Correlate Layers # Generate/Correlate Layers
def generate( self ): def generate( self ):
self.generateIndices() self.generateIndices()