- Not yet complete - Partial layers are not compiling properly (adding too many macros, wasting memory) - Adding example hhkb layout to try out as a layersimple
self.fill_dict['DefaultLayerScanMap'] = self.fill_dict['DefaultLayerScanMap'][:-2] # Remove last comma and space | self.fill_dict['DefaultLayerScanMap'] = self.fill_dict['DefaultLayerScanMap'][:-2] # Remove last comma and space | ||||
self.fill_dict['DefaultLayerScanMap'] += "\n};" | self.fill_dict['DefaultLayerScanMap'] += "\n};" | ||||
#print( self.fill_dict['DefaultLayerTriggerList'] ) | |||||
#print( self.fill_dict['DefaultLayerScanMap'] ) | |||||
## Partial Layers ## | |||||
## Partial Layers and Partial Layer Scan Maps ## | |||||
self.fill_dict['PartialLayerTriggerLists'] = "" | self.fill_dict['PartialLayerTriggerLists'] = "" | ||||
# TODO | |||||
#print( self.fill_dict['PartialLayerTriggerLists'] ) | |||||
self.fill_dict['PartialLayerScanMaps'] = "" | |||||
# Iterate over each of the layers, excluding the default layer | |||||
for layer in range( 1, len( macros.triggerList ) ): | |||||
# Prepare each layer | |||||
self.fill_dict['PartialLayerScanMaps'] += "// Partial Layer {0}\n".format( layer ) | |||||
self.fill_dict['PartialLayerScanMaps'] += "const unsigned int *layer{0}_scanMap[] = {{\n".format( layer ) | |||||
self.fill_dict['PartialLayerTriggerLists'] += "// Partial Layer {0}\n".format( layer ) | |||||
## Partial Layer Scan Maps ## | |||||
self.fill_dict['PartialLayerScanMaps'] = "" | |||||
# TODO | |||||
#print( self.fill_dict['PartialLayerScanMaps'] ) | |||||
# 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 ] ) ) | |||||
# 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 ]: | |||||
self.fill_dict['PartialLayerTriggerLists'] += ", {0}".format( trigger ) | |||||
self.fill_dict['PartialLayerTriggerLists'] += " };\n" | |||||
self.fill_dict['PartialLayerTriggerLists'] += "\n" | |||||
self.fill_dict['PartialLayerScanMaps'] = self.fill_dict['PartialLayerScanMaps'][:-2] # Remove last comma and space | |||||
self.fill_dict['PartialLayerScanMaps'] += "\n};\n\n" | |||||
self.fill_dict['PartialLayerTriggerLists'] = self.fill_dict['PartialLayerTriggerLists'][:-2] # Remove last 2 newlines | |||||
self.fill_dict['PartialLayerScanMaps'] = self.fill_dict['PartialLayerScanMaps'][:-2] # Remove last 2 newlines | |||||
## Layer Index List ## | ## Layer Index List ## | ||||
# Iterate over each layer, adding it to the list | # Iterate over each layer, adding it to the list | ||||
for layer in range( 0, len( macros.triggerList ) ): | for layer in range( 0, len( macros.triggerList ) ): | ||||
# Default map is a special case, always the first index | # Default map is a special case, always the first index | ||||
# TODO Fix names | |||||
if layer == 0: | if layer == 0: | ||||
self.fill_dict['LayerIndexList'] += '\tLayer_IN( default_scanMap, "DefaultMap" ),\n' | self.fill_dict['LayerIndexList'] += '\tLayer_IN( default_scanMap, "DefaultMap" ),\n' | ||||
else: | else: | ||||
# TODO Partial Layer | |||||
pass | |||||
self.fill_dict['LayerIndexList'] += '\tLayer_IN( layer{0}_scanMap, "Layer {0}" ),\n'.format( layer ) | |||||
self.fill_dict['LayerIndexList'] += "};" | self.fill_dict['LayerIndexList'] += "};" | ||||
#print( self.fill_dict['LayerIndexList'] ) | |||||
# Generates the output keymap with fill tags filled | # Generates the output keymap with fill tags filled | ||||
def generate( self, filepath ): | def generate( self, filepath ): |
# Modified Date | # Modified Date | ||||
Date = 2014-09-07; | Date = 2014-09-07; | ||||
# Top row | |||||
# Top Row | |||||
'e' : 'f'; | 'e' : 'f'; | ||||
'r' : 'p'; | 'r' : 'p'; | ||||
't' : 'g'; | 't' : 'g'; |
Name = hhkbpro2; | |||||
Version = 0.1; | |||||
Author = "HaaTa (Jacob Alexander) 2014"; | |||||
KLL = 0.3; | |||||
# Modified Date | |||||
Date = 2014-09-07; | |||||
# Number Row | |||||
U"1" : U"F1"; | |||||
U"2" : U"F2"; | |||||
U"3" : U"F3"; | |||||
U"4" : U"F4"; | |||||
U"5" : U"F5"; | |||||
U"6" : U"F6"; | |||||
U"7" : U"F7"; | |||||
U"8" : U"F8"; | |||||
U"9" : U"F9"; | |||||
U"0" : U"F10"; | |||||
U"-" : U"F11"; | |||||
U"=" : U"F12"; | |||||
U"Backslash" : U"Insert"; | |||||
U"Backtick" : U"Delete"; | |||||
# Top Row | |||||
U"Tab" : U"Capslock"; | |||||
U"I" : U"PrintScreen"; | |||||
U"O" : U"ScrollLock"; | |||||
U"P" : U"Pause"; | |||||
U"{" : U"Up"; | |||||
# Middle Row | |||||
U"A" : U"VolumeDown"; | |||||
U"S" : U"VolumeUp"; | |||||
U"D" : U"Mute"; | |||||
#U"F" : U"Eject"; # TODO Requires additional firmware support for media keys -HaaTa | |||||
U"H" : U"Keypad Asterix"; | |||||
U"J" : U"Keypad Slash"; | |||||
U"K" : U"Home"; | |||||
U"L" : U"PageUp"; | |||||
U";" : U"Left"; | |||||
U"Quote" : U"Right"; | |||||
# Bottom Row | |||||
U"N" : U"Keypad Plus"; | |||||
U"M" : U"Keypad Minus"; | |||||
U"Comma" : U"End"; | |||||
U"Period" : U"PageDown"; | |||||
U"Slash" : U"Down"; | |||||
# Space Row | |||||
# N/A | |||||
S0x18 : U"P"; | S0x18 : U"P"; | ||||
S0x19 : U"LBrace"; | S0x19 : U"LBrace"; | ||||
S0x1A : U"RBrace"; | S0x1A : U"RBrace"; | ||||
S0x1B : U"Delete"; | |||||
S0x1B : U"Backspace"; | |||||
S0x1C : U"Ctrl"; | S0x1C : U"Ctrl"; | ||||
S0x1D : U"A"; | S0x1D : U"A"; | ||||
S0x1E : U"S"; | S0x1E : U"S"; |
def processKLLFile( filename ): | |||||
with open( filename ) as file: | |||||
data = file.read() | |||||
tokenSequence = tokenize( data ) | |||||
#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 ### | ### Main Entry Point ### | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
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 ) | ||||
#TODO Move elsewhere | |||||
# Default combined layer | |||||
for filename in defaultFiles: | for filename in defaultFiles: | ||||
with open( filename ) as file: | |||||
data = file.read() | |||||
processKLLFile( filename ) | |||||
tokenSequence = tokenize( data ) | |||||
#print ( pformat( tokenSequence ) ) # Display tokenization | |||||
tree = parse( tokenSequence ) | |||||
# Iterate through additional layers | |||||
for partial in partialFileSets: | |||||
# Increment layer for each -p option | |||||
macros_map.addLayer() | |||||
# Apply assignment cache, see 5.1.2 USB Codes for why this is necessary | |||||
macros_map.replayCachedAssignments() | |||||
# Iterate and process each of the file in the layer | |||||
for filename in partial: | |||||
processKLLFile( filename ) | |||||
# Do macro correlation and transformation | # Do macro correlation and transformation | ||||
macros_map.generate() | macros_map.generate() |
def __repr__( self ): | def __repr__( self ): | ||||
return "{0}".format( self.macros ) | return "{0}".format( self.macros ) | ||||
def setLayer( self, layer ): | |||||
self.layer = layer | |||||
def addLayer( self ): | |||||
# Increment layer count, and append another macros dictionary | |||||
self.layer += 1 | |||||
self.macros.append( dict() ) | |||||
# Use for ScanCode trigger macros | # Use for ScanCode trigger macros | ||||
def appendScanCode( self, trigger, result ): | def appendScanCode( self, trigger, result ): |