Adding full partial layer support.
- Layers never worked previously due to backend bug - Added base configuration which is automatically clone for replacement, then subtracted for layers if scancode is unused (this allows for partial layer functionality) - Added default map argument to define a combined map that is different than the typical ANSI map that is used for the base configuration
This commit is contained in:
parent
e8d498a0d6
commit
bbf2c3ffaf
@ -193,13 +193,13 @@ class Backend:
|
|||||||
# Iterate over triggerList and generate a C trigger array for the layer
|
# Iterate over triggerList and generate a C trigger array for the layer
|
||||||
for triggerList in range( 0, len( macros.triggerList[ layer ] ) ):
|
for triggerList in range( 0, len( macros.triggerList[ layer ] ) ):
|
||||||
# Generate ScanCode index and triggerList length
|
# Generate ScanCode index and triggerList length
|
||||||
self.fill_dict['PartialLayerTriggerLists'] += "Define_TL( layer{0}, 0x{1:02X} ) = {{ {2}".format( layer, triggerList, len( macros.triggerList[ 0 ][ triggerList ] ) )
|
self.fill_dict['PartialLayerTriggerLists'] += "Define_TL( layer{0}, 0x{1:02X} ) = {{ {2}".format( layer, triggerList, len( macros.triggerList[ layer ][ triggerList ] ) )
|
||||||
|
|
||||||
# Add scanCode trigger list to Default Layer Scan Map
|
# Add scanCode trigger list to Default Layer Scan Map
|
||||||
self.fill_dict['PartialLayerScanMaps'] += "layer{0}_tl_0x{1:02X}, ".format( layer, triggerList )
|
self.fill_dict['PartialLayerScanMaps'] += "layer{0}_tl_0x{1:02X}, ".format( layer, triggerList )
|
||||||
|
|
||||||
# Add each item of the trigger list
|
# Add each item of the trigger list
|
||||||
for trigger in macros.triggerList[ 0 ][ triggerList ]:
|
for trigger in macros.triggerList[ layer ][ triggerList ]:
|
||||||
self.fill_dict['PartialLayerTriggerLists'] += ", {0}".format( trigger )
|
self.fill_dict['PartialLayerTriggerLists'] += ", {0}".format( trigger )
|
||||||
|
|
||||||
self.fill_dict['PartialLayerTriggerLists'] += " };\n"
|
self.fill_dict['PartialLayerTriggerLists'] += " };\n"
|
||||||
|
44
kll.py
44
kll.py
@ -61,12 +61,17 @@ argparse._ = textFormatter_gettext
|
|||||||
|
|
||||||
### Argument Parsing ###
|
### Argument Parsing ###
|
||||||
|
|
||||||
|
def checkFileExists( filename ):
|
||||||
|
if not os.path.isfile( filename ):
|
||||||
|
print ( "{0} {1} does not exist...".format( ERROR, filename ) )
|
||||||
|
sys.exit( 1 )
|
||||||
|
|
||||||
def processCommandLineArgs():
|
def processCommandLineArgs():
|
||||||
# Setup argument processor
|
# Setup argument processor
|
||||||
pArgs = argparse.ArgumentParser(
|
pArgs = argparse.ArgumentParser(
|
||||||
usage="%(prog)s [options] <file1>...",
|
usage="%(prog)s [options] <file1>...",
|
||||||
description="Generates .h file state tables and pointer indices from KLL .kll files.",
|
description="Generates .h file state tables and pointer indices from KLL .kll files.",
|
||||||
epilog="Example: {0} TODO".format( os.path.basename( sys.argv[0] ) ),
|
epilog="Example: {0} mykeyboard.kll -d colemak.kll -p hhkbpro2.kll -p symbols.kll".format( os.path.basename( sys.argv[0] ) ),
|
||||||
formatter_class=argparse.RawTextHelpFormatter,
|
formatter_class=argparse.RawTextHelpFormatter,
|
||||||
add_help=False,
|
add_help=False,
|
||||||
)
|
)
|
||||||
@ -79,6 +84,8 @@ def processCommandLineArgs():
|
|||||||
pArgs.add_argument( '-b', '--backend', type=str, default="kiibohd",
|
pArgs.add_argument( '-b', '--backend', type=str, default="kiibohd",
|
||||||
help="Specify target backend for the KLL compiler.\n"
|
help="Specify target backend for the KLL compiler.\n"
|
||||||
"Default: kiibohd" )
|
"Default: kiibohd" )
|
||||||
|
pArgs.add_argument( '-d', '--default', type=str, nargs='+',
|
||||||
|
help="Specify .kll files to layer on top of the default map to create a combined map." )
|
||||||
pArgs.add_argument( '-p', '--partial', type=str, nargs='+', action='append',
|
pArgs.add_argument( '-p', '--partial', type=str, nargs='+', action='append',
|
||||||
help="Specify .kll files to generate partial map, multiple files per flag.\n"
|
help="Specify .kll files to generate partial map, multiple files per flag.\n"
|
||||||
"Each -p defines another partial map.\n"
|
"Each -p defines another partial map.\n"
|
||||||
@ -96,24 +103,26 @@ def processCommandLineArgs():
|
|||||||
args = pArgs.parse_args()
|
args = pArgs.parse_args()
|
||||||
|
|
||||||
# Parameters
|
# Parameters
|
||||||
defaultFiles = args.files
|
baseFiles = args.files
|
||||||
|
defaultFiles = args.default
|
||||||
partialFileSets = args.partial
|
partialFileSets = args.partial
|
||||||
|
if defaultFiles is None:
|
||||||
|
partialFileSets = []
|
||||||
if partialFileSets is None:
|
if partialFileSets is None:
|
||||||
partialFileSets = [[]]
|
partialFileSets = [[]]
|
||||||
|
|
||||||
# Check file existance
|
# Check file existance
|
||||||
|
for filename in baseFiles:
|
||||||
|
checkFileExists( filename )
|
||||||
|
|
||||||
for filename in defaultFiles:
|
for filename in defaultFiles:
|
||||||
if not os.path.isfile( filename ):
|
checkFileExists( filename )
|
||||||
print ( "{0} {1} does not exist...".format( ERROR, filename ) )
|
|
||||||
sys.exit( 1 )
|
|
||||||
|
|
||||||
for partial in partialFileSets:
|
for partial in partialFileSets:
|
||||||
for filename in partial:
|
for filename in partial:
|
||||||
if not os.path.isfile( filename ):
|
checkFileExists( filename )
|
||||||
print ( "{0} {1} does not exist...".format( ERROR, filename ) )
|
|
||||||
sys.exit( 1 )
|
|
||||||
|
|
||||||
return (defaultFiles, partialFileSets, args.backend, args.template, args.output)
|
return (baseFiles, defaultFiles, partialFileSets, args.backend, args.template, args.output)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -514,33 +523,40 @@ def processKLLFile( filename ):
|
|||||||
#print ( pformat( tokenSequence ) ) # Display tokenization
|
#print ( pformat( tokenSequence ) ) # Display tokenization
|
||||||
tree = parse( tokenSequence )
|
tree = parse( tokenSequence )
|
||||||
|
|
||||||
# Apply assignment cache, see 5.1.2 USB Codes for why this is necessary
|
|
||||||
macros_map.replayCachedAssignments()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Main Entry Point ###
|
### Main Entry Point ###
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
(defaultFiles, partialFileSets, backend_name, template, output) = processCommandLineArgs()
|
(baseFiles, defaultFiles, partialFileSets, backend_name, template, output) = processCommandLineArgs()
|
||||||
|
|
||||||
# Load backend module
|
# Load backend module
|
||||||
global backend
|
global backend
|
||||||
backend_import = importlib.import_module( "backends.{0}".format( backend_name ) )
|
backend_import = importlib.import_module( "backends.{0}".format( backend_name ) )
|
||||||
backend = backend_import.Backend( template )
|
backend = backend_import.Backend( template )
|
||||||
|
|
||||||
|
# Process base layout files
|
||||||
|
for filename in baseFiles:
|
||||||
|
processKLLFile( filename )
|
||||||
|
macros_map.completeBaseLayout() # Indicates to macros_map that the base layout is complete
|
||||||
|
|
||||||
# Default combined layer
|
# Default combined layer
|
||||||
for filename in defaultFiles:
|
for filename in defaultFiles:
|
||||||
processKLLFile( filename )
|
processKLLFile( filename )
|
||||||
|
# Apply assignment cache, see 5.1.2 USB Codes for why this is necessary
|
||||||
|
macros_map.replayCachedAssignments()
|
||||||
|
|
||||||
# Iterate through additional layers
|
# Iterate through additional layers
|
||||||
for partial in partialFileSets:
|
for partial in partialFileSets:
|
||||||
# Increment layer for each -p option
|
# Increment layer for each -p option
|
||||||
macros_map.addLayer()
|
macros_map.addLayer()
|
||||||
|
|
||||||
# Iterate and process each of the file in the layer
|
# Iterate and process each of the file in the layer
|
||||||
for filename in partial:
|
for filename in partial:
|
||||||
processKLLFile( filename )
|
processKLLFile( filename )
|
||||||
|
# Apply assignment cache, see 5.1.2 USB Codes for why this is necessary
|
||||||
|
macros_map.replayCachedAssignments()
|
||||||
|
# Remove un-marked keys to complete the partial layer
|
||||||
|
macros_map.removeUnmarked()
|
||||||
|
|
||||||
# Do macro correlation and transformation
|
# Do macro correlation and transformation
|
||||||
macros_map.generate()
|
macros_map.generate()
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
|
|
||||||
### Imports ###
|
### Imports ###
|
||||||
|
|
||||||
|
import copy
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Decorators ###
|
### Decorators ###
|
||||||
@ -86,6 +88,10 @@ class Macros:
|
|||||||
# Macro Storage
|
# Macro Storage
|
||||||
self.macros = [ dict() ]
|
self.macros = [ dict() ]
|
||||||
|
|
||||||
|
# Base Layout Storage
|
||||||
|
self.baseLayout = None
|
||||||
|
self.layerLayoutMarkers = []
|
||||||
|
|
||||||
# Correlated Macro Data
|
# Correlated Macro Data
|
||||||
self.resultsIndex = dict()
|
self.resultsIndex = dict()
|
||||||
self.triggersIndex = dict()
|
self.triggersIndex = dict()
|
||||||
@ -100,10 +106,23 @@ class Macros:
|
|||||||
def __repr__( self ):
|
def __repr__( self ):
|
||||||
return "{0}".format( self.macros )
|
return "{0}".format( self.macros )
|
||||||
|
|
||||||
|
def completeBaseLayout( self ):
|
||||||
|
# Copy base layout for later use when creating partial layers and add marker
|
||||||
|
self.baseLayout = copy.deepcopy( self.macros[ 0 ] )
|
||||||
|
self.layerLayoutMarkers.append( copy.deepcopy( self.baseLayout ) ) # Not used for default layer, just simplifies coding
|
||||||
|
|
||||||
|
def removeUnmarked( self ):
|
||||||
|
# Remove all of the unmarked mappings from the partial layer
|
||||||
|
for trigger in self.layerLayoutMarkers[ self.layer ].keys():
|
||||||
|
del self.macros[ self.layer ][ trigger ]
|
||||||
|
|
||||||
def addLayer( self ):
|
def addLayer( self ):
|
||||||
# Increment layer count, and append another macros dictionary
|
# Increment layer count, and append another macros dictionary
|
||||||
self.layer += 1
|
self.layer += 1
|
||||||
self.macros.append( dict() )
|
self.macros.append( copy.deepcopy( self.baseLayout ) )
|
||||||
|
|
||||||
|
# Add a layout marker for each layer
|
||||||
|
self.layerLayoutMarkers.append( copy.deepcopy( self.baseLayout ) )
|
||||||
|
|
||||||
# Use for ScanCode trigger macros
|
# Use for ScanCode trigger macros
|
||||||
def appendScanCode( self, trigger, result ):
|
def appendScanCode( self, trigger, result ):
|
||||||
@ -123,6 +142,10 @@ class Macros:
|
|||||||
def replaceScanCode( self, trigger, result ):
|
def replaceScanCode( self, trigger, result ):
|
||||||
self.macros[ self.layer ][ trigger ] = [ result ]
|
self.macros[ self.layer ][ trigger ] = [ result ]
|
||||||
|
|
||||||
|
# Mark layer scan code, so it won't be removed later
|
||||||
|
if not self.baseLayout is None:
|
||||||
|
del self.layerLayoutMarkers[ self.layer ][ trigger ]
|
||||||
|
|
||||||
# Return a list of ScanCode triggers with the given USB Code trigger
|
# Return a list of ScanCode triggers with the given USB Code trigger
|
||||||
def lookupUSBCodes( self, usbCode ):
|
def lookupUSBCodes( self, usbCode ):
|
||||||
scanCodeList = []
|
scanCodeList = []
|
||||||
|
Reference in New Issue
Block a user