From: Jacob Alexander Date: Mon, 8 Sep 2014 06:22:07 +0000 (-0700) Subject: Adding basic layer support X-Git-Url: https://git.donarmstrong.com/?p=kiibohd-kll.git;a=commitdiff_plain;h=ff6ba9198bf6e450988b00c73ae7e6fe074a1081 Adding basic layer support - Not yet complete - Partial layers are not compiling properly (adding too many macros, wasting memory) - Adding example hhkb layout to try out as a layer --- diff --git a/backends/kiibohd.py b/backends/kiibohd.py index 47415a7..e25c64c 100644 --- a/backends/kiibohd.py +++ b/backends/kiibohd.py @@ -178,20 +178,36 @@ class Backend: self.fill_dict['DefaultLayerScanMap'] = self.fill_dict['DefaultLayerScanMap'][:-2] # Remove last comma and space 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'] = "" - # 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 ## @@ -200,15 +216,13 @@ class Backend: # Iterate over each layer, adding it to the list for layer in range( 0, len( macros.triggerList ) ): # Default map is a special case, always the first index + # TODO Fix names if layer == 0: self.fill_dict['LayerIndexList'] += '\tLayer_IN( default_scanMap, "DefaultMap" ),\n' else: - # TODO Partial Layer - pass + self.fill_dict['LayerIndexList'] += '\tLayer_IN( layer{0}_scanMap, "Layer {0}" ),\n'.format( layer ) self.fill_dict['LayerIndexList'] += "};" - #print( self.fill_dict['LayerIndexList'] ) - # Generates the output keymap with fill tags filled def generate( self, filepath ): diff --git a/examples/colemak.kll b/examples/colemak.kll index 6500e3e..5353a3c 100644 --- a/examples/colemak.kll +++ b/examples/colemak.kll @@ -6,7 +6,7 @@ KLL = 0.3; # Modified Date Date = 2014-09-07; -# Top row +# Top Row 'e' : 'f'; 'r' : 'p'; 't' : 'g'; diff --git a/examples/hhkbpro2.kll b/examples/hhkbpro2.kll new file mode 100644 index 0000000..6f99653 --- /dev/null +++ b/examples/hhkbpro2.kll @@ -0,0 +1,53 @@ +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 + diff --git a/examples/md1Map.kll b/examples/md1Map.kll index 990d558..901fccb 100644 --- a/examples/md1Map.kll +++ b/examples/md1Map.kll @@ -40,7 +40,7 @@ S0x17 : U"O"; S0x18 : U"P"; S0x19 : U"LBrace"; S0x1A : U"RBrace"; -S0x1B : U"Delete"; +S0x1B : U"Backspace"; S0x1C : U"Ctrl"; S0x1D : U"A"; S0x1E : U"S"; diff --git a/kll.py b/kll.py index 06ce83d..ae96b2d 100755 --- a/kll.py +++ b/kll.py @@ -507,6 +507,18 @@ def parse( tokenSequence ): +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 ### if __name__ == '__main__': @@ -517,17 +529,18 @@ if __name__ == '__main__': backend_import = importlib.import_module( "backends.{0}".format( backend_name ) ) backend = backend_import.Backend( template ) - #TODO Move elsewhere + # Default combined layer 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 macros_map.generate() diff --git a/kll_lib/containers.py b/kll_lib/containers.py index 751f949..5bf9e70 100644 --- a/kll_lib/containers.py +++ b/kll_lib/containers.py @@ -100,8 +100,10 @@ class Macros: def __repr__( self ): 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 def appendScanCode( self, trigger, result ):