Mercurial > louis > kiibohd-kll
changeset 7:8104b5dd54c4
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
author | Jacob Alexander <haata@kiibohd.com> |
---|---|
date | Sun, 07 Sep 2014 23:22:07 -0700 |
parents | fbd991c7542d |
children | a2598221d010 |
files | backends/kiibohd.py examples/colemak.kll examples/hhkbpro2.kll examples/md1Map.kll kll.py kll_lib/containers.py |
diffstat | 6 files changed, 108 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/backends/kiibohd.py Sun Sep 07 21:32:36 2014 -0700 +++ b/backends/kiibohd.py Sun Sep 07 23:22:07 2014 -0700 @@ -178,20 +178,36 @@ 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 ) + + # 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 ] ) ) - ## Partial Layer Scan Maps ## - self.fill_dict['PartialLayerScanMaps'] = "" - # TODO - #print( self.fill_dict['PartialLayerScanMaps'] ) + # 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 @@ # 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 ):
--- a/examples/colemak.kll Sun Sep 07 21:32:36 2014 -0700 +++ b/examples/colemak.kll Sun Sep 07 23:22:07 2014 -0700 @@ -6,7 +6,7 @@ # Modified Date Date = 2014-09-07; -# Top row +# Top Row 'e' : 'f'; 'r' : 'p'; 't' : 'g';
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/hhkbpro2.kll Sun Sep 07 23:22:07 2014 -0700 @@ -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 +
--- a/examples/md1Map.kll Sun Sep 07 21:32:36 2014 -0700 +++ b/examples/md1Map.kll Sun Sep 07 23:22:07 2014 -0700 @@ -40,7 +40,7 @@ S0x18 : U"P"; S0x19 : U"LBrace"; S0x1A : U"RBrace"; -S0x1B : U"Delete"; +S0x1B : U"Backspace"; S0x1C : U"Ctrl"; S0x1D : U"A"; S0x1E : U"S";
--- a/kll.py Sun Sep 07 21:32:36 2014 -0700 +++ b/kll.py Sun Sep 07 23:22:07 2014 -0700 @@ -507,6 +507,18 @@ +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 @@ 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()
--- a/kll_lib/containers.py Sun Sep 07 21:32:36 2014 -0700 +++ b/kll_lib/containers.py Sun Sep 07 23:22:07 2014 -0700 @@ -100,8 +100,10 @@ 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 ):