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
|
||||
for triggerList in range( 0, len( macros.triggerList[ layer ] ) ):
|
||||
# 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
|
||||
self.fill_dict['PartialLayerScanMaps'] += "layer{0}_tl_0x{1:02X}, ".format( layer, triggerList )
|
||||
|
||||
# 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'] += " };\n"
|
||||
|
44
kll.py
44
kll.py
@ -61,12 +61,17 @@ argparse._ = textFormatter_gettext
|
||||
|
||||
### 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():
|
||||
# Setup argument processor
|
||||
pArgs = argparse.ArgumentParser(
|
||||
usage="%(prog)s [options] <file1>...",
|
||||
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,
|
||||
add_help=False,
|
||||
)
|
||||
@ -79,6 +84,8 @@ def processCommandLineArgs():
|
||||
pArgs.add_argument( '-b', '--backend', type=str, default="kiibohd",
|
||||
help="Specify target backend for the KLL compiler.\n"
|
||||
"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',
|
||||
help="Specify .kll files to generate partial map, multiple files per flag.\n"
|
||||
"Each -p defines another partial map.\n"
|
||||
@ -96,24 +103,26 @@ def processCommandLineArgs():
|
||||
args = pArgs.parse_args()
|
||||
|
||||
# Parameters
|
||||
defaultFiles = args.files
|
||||
baseFiles = args.files
|
||||
defaultFiles = args.default
|
||||
partialFileSets = args.partial
|
||||
if defaultFiles is None:
|
||||
partialFileSets = []
|
||||
if partialFileSets is None:
|
||||
partialFileSets = [[]]
|
||||
|
||||
# Check file existance
|
||||
for filename in baseFiles:
|
||||
checkFileExists( filename )
|
||||
|
||||
for filename in defaultFiles:
|
||||
if not os.path.isfile( filename ):
|
||||
print ( "{0} {1} does not exist...".format( ERROR, filename ) )
|
||||
sys.exit( 1 )
|
||||
checkFileExists( filename )
|
||||
|
||||
for partial in partialFileSets:
|
||||
for filename in partial:
|
||||
if not os.path.isfile( filename ):
|
||||
print ( "{0} {1} does not exist...".format( ERROR, filename ) )
|
||||
sys.exit( 1 )
|
||||
checkFileExists( filename )
|
||||
|
||||
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
|
||||
tree = parse( tokenSequence )
|
||||
|
||||
# Apply assignment cache, see 5.1.2 USB Codes for why this is necessary
|
||||
macros_map.replayCachedAssignments()
|
||||
|
||||
|
||||
|
||||
### Main Entry Point ###
|
||||
|
||||
if __name__ == '__main__':
|
||||
(defaultFiles, partialFileSets, backend_name, template, output) = processCommandLineArgs()
|
||||
(baseFiles, defaultFiles, partialFileSets, backend_name, template, output) = processCommandLineArgs()
|
||||
|
||||
# Load backend module
|
||||
global backend
|
||||
backend_import = importlib.import_module( "backends.{0}".format( backend_name ) )
|
||||
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
|
||||
for filename in defaultFiles:
|
||||
processKLLFile( filename )
|
||||
# Apply assignment cache, see 5.1.2 USB Codes for why this is necessary
|
||||
macros_map.replayCachedAssignments()
|
||||
|
||||
# Iterate through additional layers
|
||||
for partial in partialFileSets:
|
||||
# Increment layer for each -p option
|
||||
macros_map.addLayer()
|
||||
|
||||
# Iterate and process each of the file in the layer
|
||||
for filename in partial:
|
||||
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
|
||||
macros_map.generate()
|
||||
|
@ -18,6 +18,8 @@
|
||||
|
||||
### Imports ###
|
||||
|
||||
import copy
|
||||
|
||||
|
||||
|
||||
### Decorators ###
|
||||
@ -86,6 +88,10 @@ class Macros:
|
||||
# Macro Storage
|
||||
self.macros = [ dict() ]
|
||||
|
||||
# Base Layout Storage
|
||||
self.baseLayout = None
|
||||
self.layerLayoutMarkers = []
|
||||
|
||||
# Correlated Macro Data
|
||||
self.resultsIndex = dict()
|
||||
self.triggersIndex = dict()
|
||||
@ -100,10 +106,23 @@ class Macros:
|
||||
def __repr__( self ):
|
||||
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 ):
|
||||
# Increment layer count, and append another macros dictionary
|
||||
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
|
||||
def appendScanCode( self, trigger, result ):
|
||||
@ -123,6 +142,10 @@ class Macros:
|
||||
def replaceScanCode( self, 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
|
||||
def lookupUSBCodes( self, usbCode ):
|
||||
scanCodeList = []
|
||||
|
Reference in New Issue
Block a user