+// 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 );
+}
+
+