How to use the interface.control.cmd function in Interface

To help you get started, we’ve selected a few Interface examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kiibohd / controller / Scan / TestIn / Tests / layers.py View on Github external
# Logger (current file and parent directory only)
logger = kiilogger.get_logger(os.path.join(os.path.split(__file__)[0], os.path.basename(__file__)))
logging.root.setLevel(logging.INFO)


# Reference to callback datastructure
data = i.control.data

# Enabled macro debug mode - Enabled USB Output, show debug
i.control.cmd('setMacroDebugMode')( 2 )

# Enabled vote debug mode
i.control.cmd('setVoteDebugMode')( 1 )

# Enable layer debug mode
i.control.cmd('setLayerDebugMode')(1)

# Enable pending trigger debug mode
i.control.cmd('setTriggerPendingDebugMode')(1)

# Enable output module debug mode
i.control.cmd('setOutputDebugMode')(2)



### Test ###

testrunner = KLLTestRunner([
    LayerTest(),
    #LayerTest(tests=20, test=1),
])
testrunner.run()
github kiibohd / controller / Scan / TestIn / Tests / common.py View on Github external
def clean_animation_stack(self):
        '''
        Clean animation stack (if necessary)

        Only runs if PixelMap module is compiled in.
        '''
        import interface

        if 'Pixel_MapEnabled' in self.klljson['Defines'] and int(self.klljson['Defines']['Pixel_MapEnabled']['value']) == 1:
            animation_stack = interface.control.cmd('animationStackInfo')()
            if animation_stack.size > 0:
                # Print out info on the current state of the stack
                logger.warning("Animation Stack is not empty! Cleaning... {} animations", animation_stack.size)
                for index in range(animation_stack.size):
                    elem = animation_stack.stack[0][index]
                    logger.warning("{} >> index={}, pos={}, subpos={}",
                        self.klljson['AnimationSettingsIndex'][elem.index]['name'],
                        elem.index,
                        elem.pos,
                        elem.subpos,
                    )

                # Set AnimationControl_Stop, update FrameState then run one loop to reset PixelMap state
                interface.control.cmd('setAnimationControl')(3) # AnimationControl_Stop
                interface.control.cmd('setFrameState')(2) # FrameState_Update
                interface.control.loop(1)
github kiibohd / controller / Scan / TestIn / Tests / common.py View on Github external
        @return: True if evaluated, False if not.
        '''
        # TODO (HaaTa) Handle scheduling
        import interface as i
        LayerStateType = i.control.scan.LayerStateType
        ScheduleState = i.control.scan.ScheduleState
        TriggerType = i.control.scan.TriggerType

        logger.debug("TriggerElem eval {} {}", self.elem, self.schedule)

        # Determine which kind trigger element
        # ScanCode
        if self.elem['type'] == 'ScanCode':
            # Press given ScanCode
            # TODO (HaaTa): Support uids greater than 255
            i.control.cmd('addScanCode')(self.elem['uid'], TriggerType.Switch1)

        # IndicatorCode
        elif self.elem['type'] == 'IndCode':
            # Activate Indicator
            i.control.cmd('addScanCode')(self.elem['uid'], TriggerType.LED1)

        # Layer
        elif self.elem['type'] in ['Layer', 'LayerShift', 'LayerLatch', 'LayerLock']:
            # Determine which layer type
            layer_state = LayerStateType.Shift
            if self.elem['type'] == 'LayerLatch':
                layer_state = LayerStateType.Latch
            elif self.elem['type'] == 'LayerLock':
                layer_state = LayerStateType.Lock

            # Activate layer
github kiibohd / controller / Scan / TestIn / Tests / layers.py View on Github external
'''
        for act in action:
            # Get current state
            prev_state = i.control.cmd('getLayerState')()

            if act == 'shift':
                # Determine if press or release for shift
                input_state = 0x1 # Press
                if prev_state.state[self.layer] & 0x1:
                    input_state = 0x3 # Release

                # Press/Release, Switch1
                i.control.cmd('capability')('layerShift', None, input_state, 0x0, [self.layer])

                # Make sure action ocurred
                new_state = i.control.cmd('getLayerState')()
                check(prev_state.state[self.layer] & 0x1 != new_state.state[self.layer] & 0x1)

            elif act == 'latch':
                # Release, Switch1
                i.control.cmd('capability')('layerLatch', None, 0x3, 0x0, [self.layer])

                # Make sure action ocurred
                new_state = i.control.cmd('getLayerState')()
                check(prev_state.state[self.layer] & 0x2 != new_state.state[self.layer] & 0x2)

            elif act == 'lock':
                # Press, Switch1
                i.control.cmd('capability')('layerLock', None, 0x1, 0x0, [self.layer])

                # Make sure action ocurred
                new_state = i.control.cmd('getLayerState')()
github kiibohd / controller / Scan / TestIn / Tests / layers.py View on Github external
def run_action(self, action):
        '''
        Process and monitor action

        Compares the layer state bit of each action to make sure the action resulted in the opposite reaction.

        @param action: Commands to run
        '''
        for act in action:
            # Get current state
            prev_state = i.control.cmd('getLayerState')()

            if act == 'shift':
                # Determine if press or release for shift
                input_state = 0x1 # Press
                if prev_state.state[self.layer] & 0x1:
                    input_state = 0x3 # Release

                # Press/Release, Switch1
                i.control.cmd('capability')('layerShift', None, input_state, 0x0, [self.layer])

                # Make sure action ocurred
                new_state = i.control.cmd('getLayerState')()
                check(prev_state.state[self.layer] & 0x1 != new_state.state[self.layer] & 0x1)

            elif act == 'latch':
                # Release, Switch1
github kiibohd / controller / Scan / TestIn / Tests / animation.py View on Github external
# Update FrameState and Loop again to clear the stack
i.control.cmd('setFrameState')(2)
i.control.loop(1)

# Read animation stack info
logger.info("Expecting Stack Size: 0 Got: {}", i.control.cmd('animationStackInfo')().size)
check( i.control.cmd('animationStackInfo')().size == 0 )


##### Next Test #####


logger.info(header("-Clear ScanCode Test-"))

# Add Animation, index 1, to Stack (clear_pixels)
i.control.cmd('addAnimation')(name='clear_pixels')

# Read animation stack info
logger.info("Expecting Stack Size: 1 Got: {}", i.control.cmd('animationStackInfo')().size)
check( i.control.cmd('animationStackInfo')().size == 1 )

# Loop once
i.control.cmd('setFrameState')(2)
i.control.loop(1)

# Show output
i.control.cmd('rectDisp')()

# TODO Check that pixels were cleared

# Update FrameState and Loop again to clear the stack
i.control.cmd('setFrameState')(2)
github kiibohd / controller / Scan / TestIn / Tests / common.py View on Github external
# Layer
        elif self.elem['type'] in ['Layer', 'LayerShift', 'LayerLatch', 'LayerLock']:
            # Determine which layer type
            layer_state = LayerStateType.Shift
            if self.elem['type'] == 'LayerLatch':
                layer_state = LayerStateType.Latch
            elif self.elem['type'] == 'LayerLock':
                layer_state = LayerStateType.Lock

            # Activate layer
            i.control.cmd('applyLayer')(ScheduleState.P, self.elem['uid'], layer_state)

        # Generic Trigger
        elif self.elem['type'] in ['GenericTrigger']:
            # Activate trigger
            i.control.cmd('setTriggerCode')(self.elem['uid'], self.elem['idcode'], self.elem['schedule'][0]['state'] )

        # Unknown TriggerElem
        else:
            logger.warning("Unknown TriggerElem {}", self.elem)

        return True
github kiibohd / controller / Scan / TestIn / Tests / hidio.py View on Github external
logger.info(header("Check buffers are empty"))

# Check contents of incoming buffer (should be empty)
logger.info("Incoming Buf: {}", data.rawio_incoming_buffer)
check( len( data.rawio_incoming_buffer ) == 0 )

# Check contents of outgoing buffer (should be empty)
logger.info("Outgoing Buf: {}", data.rawio_outgoing_buffer)
check( len( data.rawio_outgoing_buffer ) == 0 )



# Invalid Id Test
print("")
logger.info(header("- Invalid Id Test -"))
i.control.cmd('HIDIO_invalid_65535_request')()


# A single processing loop (receivves, then sends packets)
i.control.loop(1)
logger.info(header("Check data packet"))

# Check contents of incoming buffer (should be empty in loopback mode)
logger.info("Incoming Buf: {}", data.rawio_incoming_buffer)
check( len( data.rawio_incoming_buffer ) == 0 )

# Check contents of outgoing buffer (should have packet in loopback mode)
logger.info("Outgoing Buf: {}", data.rawio_outgoing_buffer)
check( len( data.rawio_outgoing_buffer ) == 1 )
check( data.rawio_outgoing_buffer[0][0].len == 2 )
check( data.rawio_outgoing_buffer[0][0].type == 0 )
check( data.rawio_outgoing_buffer[0][0].cont == 0 )
github kiibohd / controller / Scan / TestIn / Tests / common.py View on Github external
ScheduleState = i.control.scan.ScheduleState
        TriggerType = i.control.scan.TriggerType

        logger.debug("TriggerElem eval {} {}", self.elem, self.schedule)

        # Determine which kind trigger element
        # ScanCode
        if self.elem['type'] == 'ScanCode':
            # Press given ScanCode
            # TODO (HaaTa): Support uids greater than 255
            i.control.cmd('addScanCode')(self.elem['uid'], TriggerType.Switch1)

        # IndicatorCode
        elif self.elem['type'] == 'IndCode':
            # Activate Indicator
            i.control.cmd('addScanCode')(self.elem['uid'], TriggerType.LED1)

        # Layer
        elif self.elem['type'] in ['Layer', 'LayerShift', 'LayerLatch', 'LayerLock']:
            # Determine which layer type
            layer_state = LayerStateType.Shift
            if self.elem['type'] == 'LayerLatch':
                layer_state = LayerStateType.Latch
            elif self.elem['type'] == 'LayerLock':
                layer_state = LayerStateType.Lock

            # Activate layer
            i.control.cmd('applyLayer')(ScheduleState.P, self.elem['uid'], layer_state)

        # Generic Trigger
        elif self.elem['type'] in ['GenericTrigger']:
            # Activate trigger
github kiibohd / controller / Scan / TestIn / Tests / hidio.py View on Github external
# Reference to callback datastructure
data = i.control.data



### Test ###

# Drop to cli, type exit in the displayed terminal to continue
#i.control.cli()


## Loopback Tests ##
logger.info(header("-- RawIO Loopback tests --"))

i.control.cmd('setRawIOPacketSize')( 64 )
i.control.cmd('setRawIOLoopback')( True )

# Send basic test packet, 1 byte length, payload 0xAC
logger.info(header("- Single byte packet payload -"))
i.control.cmd('HIDIO_test_2_request')( 1, 0xAC )


# A single processing loop (receives, then sends packets)
i.control.loop(1)

# Check contents of incoming buffer (should be empty in loopback mode)
logger.info("Incoming Buf: {}", data.rawio_incoming_buffer)
check( len( data.rawio_incoming_buffer ) == 0 )

# Check contents of outgoing buffer (should have packet in loopback mode)
logger.info("Outgoing Buf: {}", data.rawio_outgoing_buffer)