]> git.donarmstrong.com Git - kiibohd-controller.git/commitdiff
Adding layer rotation (next/prev) capability
authorJacob Alexander <haata@kiibohd.com>
Tue, 29 Sep 2015 02:58:39 +0000 (19:58 -0700)
committerJacob Alexander <haata@kiibohd.com>
Tue, 29 Sep 2015 02:58:39 +0000 (19:58 -0700)
- Requires kll update
- Including udev id update

98-kiibohd.rules
Macro/PartialMap/capabilities.kll
Macro/PartialMap/macro.c
Scan/STLcd/lcd_scan.c

index 5e28301444fdd2e24b7fa3ec5a2bc22299d91b9e..d00a8b2c81495d9bdf4b44bc0f6fd708628fc3cf 100644 (file)
@@ -5,6 +5,7 @@ SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", MODE:=
 # Kiibohd Serial Interface
 KERNEL=="ttyACM*", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="04[789]?", MODE:="0666"
 KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b04d", MODE:="0666"
+KERNEL=="ttyACM*", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="f05c", MODE:="0666"
 # Kiibohd Device
 SUBSYSTEMS=="usb", ATTRS{idVendor}=="1c11", ATTRS{idProduct}=="b04d", MODE:="0666"
 # DFU Bootloader (MCHCK)
index 4572c055478f27de0e6c8d88dc5d8178545f2b8e..09ac6a29c24c6ee64542f98974008f83efd7eac1 100644 (file)
@@ -1,17 +1,22 @@
 Name = PartialMapCapabilities;
-Version = 0.1;
-Author = "HaaTa (Jacob Alexander) 2014";
-KLL = 0.3a;
+Version = 0.2;
+Author = "HaaTa (Jacob Alexander) 2014-2015";
+KLL = 0.3b;
 
 # Modified Date
-Date = 2014-11-21;
+Date = 2015-09-24;
 
 
 # Capabilties available to the PartialMap module
-layerState => Macro_layerState_capability( layer : 2, state : 1 );
-layerLatch => Macro_layerLatch_capability( layer : 2 );
-layerLock  => Macro_layerLock_capability( layer : 2 );
-layerShift => Macro_layerShift_capability( layer : 2 );
+layerState  => Macro_layerState_capability( layer : 2, state : 1 );
+layerLatch  => Macro_layerLatch_capability( layer : 2 );
+layerLock   => Macro_layerLock_capability( layer : 2 );
+layerShift  => Macro_layerShift_capability( layer : 2 );
+# By default, rotate to the next layer
+# The current rotating layer is stored separately to the layer stack
+# But still sets the layer stack using the layerLock/unlock mechanism
+# Argument 0 -> Next, 1 -> Previous
+layerRotate => Macro_layerRotate_capability( previous : 1 );
 
 # Defines available to the PartialMap module
 stateWordSize => StateWordSize_define;
index 7161fbf9e495d92eb9ec5d6c42f50afae355555a..690231cc889628b158ca6dac33ab86be0509318b 100644 (file)
@@ -170,8 +170,8 @@ uint8_t macroInterconnectCacheSize = 0;
 // Sets the given layer with the specified layerState
 void Macro_layerState( uint8_t state, uint8_t stateType, uint16_t layer, uint8_t layerState )
 {
-       // Ignore if layer does not exist
-       if ( layer >= LayerNum )
+       // Ignore if layer does not exist or trying to manipulate layer 0/Default layer
+       if ( layer >= LayerNum || layer == 0 )
                return;
 
        // Is layer in the LayerIndexStack?
@@ -350,6 +350,58 @@ void Macro_layerShift_capability( uint8_t state, uint8_t stateType, uint8_t *arg
 }
 
 
+// Rotate layer to next/previous
+// Uses state variable to keep track of the current layer position
+// Layers are still evaluated using the layer stack
+uint16_t Macro_rotationLayer;
+void Macro_layerRotate_capability( uint8_t state, uint8_t stateType, uint8_t *args )
+{
+       // Display capability name
+       if ( stateType == 0xFF && state == 0xFF )
+       {
+               print("Macro_layerRotate(previous)");
+               return;
+       }
+
+       // Only use capability on press
+       // TODO Analog
+       // XXX Could also be on release, but that's sorta dumb -HaaTa
+       if ( stateType == 0x00 && state != 0x01 ) // All normal key conditions except press
+               return;
+
+       // Unset previous rotation layer if not 0
+       if ( Macro_rotationLayer != 0 )
+       {
+               Macro_layerState( state, stateType, Macro_rotationLayer, 0x04 );
+       }
+
+       // Get direction of rotation, 0, next, non-zero previous
+       uint8_t direction = *args;
+
+       // Next
+       if ( !direction )
+       {
+               Macro_rotationLayer++;
+
+               // Invalid layer
+               if ( Macro_rotationLayer >= LayerNum )
+                       Macro_rotationLayer = 0;
+       }
+       // Previous
+       else
+       {
+               Macro_rotationLayer--;
+
+               // Layer wrap
+               if ( Macro_rotationLayer >= LayerNum )
+                       Macro_rotationLayer = LayerNum - 1;
+       }
+
+       // Toggle the computed layer rotation
+       Macro_layerState( state, stateType, Macro_rotationLayer, 0x04 );
+}
+
+
 
 // ----- Functions -----
 
@@ -398,9 +450,9 @@ nat_ptr_t *Macro_layerLookup( TriggerGuide *guide, uint8_t latch_expire )
                        // Determine if layer has key defined
                        // Make sure scanCode is between layer first and last scancodes
                        if ( map != 0
-                         && scanCode <= layer->last
-                         && scanCode >= layer->first
-                         && *map[ scanCode - layer->first ] != 0 )
+                               && scanCode <= layer->last
+                               && scanCode >= layer->first
+                               && *map[ scanCode - layer->first ] != 0 )
                        {
                                // Set the layer cache
                                macroTriggerListLayerCache[ scanCode ] = macroLayerIndexStack[ layerIndex ];
@@ -418,9 +470,9 @@ nat_ptr_t *Macro_layerLookup( TriggerGuide *guide, uint8_t latch_expire )
 
        // Make sure scanCode is between layer first and last scancodes
        if ( map != 0
-         && scanCode <= layer->last
-         && scanCode >= layer->first
-         && *map[ scanCode - layer->first ] != 0 )
+               && scanCode <= layer->last
+               && scanCode >= layer->first
+               && *map[ scanCode - layer->first ] != 0 )
        {
                // Set the layer cache to default map
                macroTriggerListLayerCache[ scanCode ] = 0;
@@ -892,7 +944,7 @@ TriggerMacroEval Macro_evalTriggerMacro( var_uint_t triggerMacroIndex )
        }
        // If passing and in Waiting state, set macro state to Press
        else if ( overallVote & TriggerMacroVote_Pass
-            && ( record->state == TriggerMacro_Waiting || record->state == TriggerMacro_Press ) )
+               && ( record->state == TriggerMacro_Waiting || record->state == TriggerMacro_Press ) )
        {
                record->state = TriggerMacro_Press;
 
@@ -1212,6 +1264,9 @@ inline void Macro_setup()
        // Make sure macro trigger buffer is empty
        macroTriggerListBufferSize = 0;
 
+       // Set the current rotated layer to 0
+       Macro_rotationLayer = 0;
+
        // Initialize TriggerMacro states
        for ( var_uint_t macro = 0; macro < TriggerMacroNum; macro++ )
        {
index fcd487e9c8bb71f441a23e360bceaa727ba0235c..74c6763ba523d723de846fe8cd58608fc4e53bbc 100644 (file)
@@ -345,6 +345,7 @@ inline uint8_t LCD_scan()
 // ----- Capabilities -----
 
 uint16_t LCD_layerStack_prevSize = 0;
+uint16_t LCD_layerStack_prevTop  = 0;
 void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args )
 {
        // Display capability name
@@ -358,12 +359,14 @@ void LCD_layerStack_capability( uint8_t state, uint8_t stateType, uint8_t *args
        extern uint16_t macroLayerIndexStack[];
        extern uint16_t macroLayerIndexStackSize;
 
-       // Only process if the stack size has changed
-       if ( macroLayerIndexStackSize == LCD_layerStack_prevSize )
+       // Ignore if the stack size hasn't changed and the top of the stack is the same
+       if ( macroLayerIndexStackSize == LCD_layerStack_prevSize
+               && macroLayerIndexStack[macroLayerIndexStackSize - 1] == LCD_layerStack_prevTop )
        {
                return;
        }
        LCD_layerStack_prevSize = macroLayerIndexStackSize;
+       LCD_layerStack_prevTop  = macroLayerIndexStack[macroLayerIndexStackSize - 1];
 
        // Number data for LCD
        const uint8_t numbers[10][128] = {