Hardware



Shell Lab K1 is programmable key/switch controller

Characteristic:

● 10 external key/switch inputs, 3 on-board keys
● built-in software debounce algorithm with configurable parameters
● support event message (on/off/long press) with timestamp, queue buffered
● support enable/disable for each channel
● at startup, parameters are auto configured by mode switch
● expand channels from extend socket
● USB powered, 2-meter cable length
● interactive serial console with ASCII command, online manual embedded
● programming language is not limited (Python recommended)
● quick test with Testbench App (with various demo codes)
● pip install mcush library (support windows/linux/mac) and write scripts easily

Use cases:

● manual intervention in step/cycle tests
● experiment progress control
● circumstances that front-end control (HID keyboard) is forbidden and backend control is MUST
● interactive game design
● educational experiment design
● outdoor case, manual control
● system integration for industrial equipment
● product prototype design
● art creativity

Customize:

● customized PCB size, channel number, input signal conditioning

Software

Serial Communication FAQ
C Programming FAQ

Serial command:

Key control command
=>k --help
usage: k [-c ] [-i ] [-v ]
options:
 -c/--cmd        state|E|(e)vent|(en|dis)able|inv|debounce_(on|off|long)|count
 -i/--idx        index param
 -v/--val        value param
=> 

Example:

query all channel state
=>k
0x00000009   #0/3 channels are pressed simutaneously
=> 
enable channel
=>k -c enable -i 3  enable #3 channel
=>k -c enable -v 0x18  enable #3/4 channels
=> 
disable channel
=>k -c disable -i 3  disable #3 channel
=>k -c disable -v 0xFFFFFFF0  disable all other channels except #0/1/2/3
=> 
key input signal invert
=>k -c inv  query invert setting
0x00000001     #0 channel input needs invert
=>k -c inv -v 0x18    set #3/4 channels to be inverted
=> 
query events buffer
=>k -c event  query all buffered events
46.888 + 0x2   #1 key is pressed (type: +pressed,-released,*long press)
47.380 - 0x2   #1 key is released
47.860 + 0x4   #2 key is pressed
48.112 - 0x4   #2 key is released
48.884 + 0x5   #1/2 keys are pressed simutaneously
49.204 - 0x5   #1/2 keys are released simutaneously
=>k -c E       query single event
59.888 + 0x2   #1 key pressed
=>k -c e -i 1  filter all events triggered by #1 channel
=>
=>k -c e -v 6  filter all events triggered by #1/2 channels
=>
software debounce algorithm
=>k -c debounce_on   query signal press stable time (in ms)
0 8     set to 8ms (default by mode switch: 8ms in fast mode and 200ms in slow mode)
1 8
2 8
3 8
4 8
5 8
6 8
7 8
8 8
9 8
10 8
11 8
12 8
=>k -c debounce_on -i 1 -v 200   modify #1 signal press stable time to 200ms
=>k -c debounce_off -i 1 -v 200   modify #1 signal release stable time to 200ms
=>k -c debounce_long -i 1 -v 5000  modify #1 signal long press stable time to 5000ms
=> 
events statistics
=>k -c count   query events statistics
0 6 6 0  #0 key has been pressed 6 times, released 6 times, no long press
1 5 5 0
2 7 7 0
3 0 0 0
4 0 0 0
5 0 0 0
6 0 0 0
7 0 0 0
8 0 0 0
9 0 0 0
10 0 0 0
11 0 0 0
12 0 0 0
=> 

Python API:

Install: sudo pip3 install mcush
Upgrade: sudo pip3 install -U mcush
class ShellLabKeySwitch(mcush.Mcush.Mcush):
    def key(self, cmd=None, idx=None, val=None):
        # lower level serial command

    def getInv( self ):
        # query invert setting

    def setInv( self, inv ):
        # modify invert setting
     
    def getState( self ):
        # query all channels state (bitmap)

    def getEvent( self, evt_index=None, evt_mask=None ):
        # query single event

    def getEvents( self, evt_index=None, evt_mask=None ):
        # query all buffered events

    def waitForEvent( self, evt_index=None, evt_mask=None, evt_type='on', timeout=30.0 ):
        # wait until specific event is triggered

    def enable( self, key_index=None, key_mask=None  ):
        # enable channel

    def disable( self, key_index=None, key_mask=None  ):
        # disable channel

    def getCount( self, key_index ):
        # query events statistics

    def setDebounce( self, index, on_ms=None, off_ms=None, long_ms=None ):
        # set debounce algorithm setting

Examples:

import mcush
from mcush.linkong.ShellLab import ShellLabKeySwitch
k = ShellLabKeySwitch('COM10')   # fill the actual serial port 
state = k.getState()  # query all keys state
while True:
    for a,b,c in k.getEvents():  # looply query all events and print
        print("%.3f %s 0x%X"% (a,b,c))  # timestamp + type + keys bitmap

Download:

Shell Lab Testbench Application


CH341 VCP Driver(Windows)


Application

Built-in script demo
# this script runs in ShellLab Testbench Application
k = ShellLabKeySwitch(PORT)

info('Press key0 to start ...')
if not k.waitForEvent(0):
    stop("Timeout, key0 not pressed")
k.beep()

p = getLogPanel(switch=True, clear=True)
info('Recording all key events ...')
logAdd( 'key state: 0x%08X'% k.getState() )
while True:
    #for a,b,c in k.getEvent():  # process event one by one, quicker
    for a,b,c in k.getEvents():  # process all events, slower
        logAdd("%.3f %s 0x%X"% (a,b,c))
        # stop when key0 is long pressed (>5s)
        if (b == '*') and (c & 0x01):
            k.beep(freq=1000, times=3)
            stop('key0 long pressed, stop')