]> git.donarmstrong.com Git - kiibohd-kll.git/commitdiff
Adding basic layer support
authorJacob Alexander <haata@kiibohd.com>
Mon, 8 Sep 2014 06:22:07 +0000 (23:22 -0700)
committerJacob Alexander <haata@kiibohd.com>
Mon, 8 Sep 2014 06:22:07 +0000 (23:22 -0700)
- 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

backends/kiibohd.py
examples/colemak.kll
examples/hhkbpro2.kll [new file with mode: 0644]
examples/md1Map.kll
kll.py
kll_lib/containers.py

index 47415a75a1f33b014c75b23692ae71b5c09a2153..e25c64c8b2058398fd093d1c1fd7b8912f1acd55 100644 (file)
@@ -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 ):
index 6500e3e10b72e5547642f7429d94dff9e86ace69..5353a3c6a27329ced25a80e4bddf2846704d988f 100644 (file)
@@ -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 (file)
index 0000000..6f99653
--- /dev/null
@@ -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
+
index 990d558d4c4a83619e7c002315ec6316bd44d7d6..901fccb3b55aab11e0aedafccb22c6ebe44a4713 100644 (file)
@@ -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 06ce83d91b91a6aae3641ec2c0e0c1a94b82f3de..ae96b2db5acbd39db9248bf8927921f5abfeb012 100755 (executable)
--- 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()
index 751f94947d9a224f788fa9ce1b8153e041a57e84..5bf9e70c9c771c78408aff146aa41c306b4f67aa 100644 (file)
@@ -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 ):