I have a functional working concept, it is dirty but it works for the most part. So far the biggest leap has been the when taking to a coworker about the best way to do a lookup table in python was not to but treat the keys as binary registers. Not sure if I will look at using the API for just controlling the LEDs or trying to bolt things on to the API but ether way. I’ve got some python learning to do. I may just forgo using the keybow.on functionality at all on just record keystrokes from the pins until all are true then output a value.
This started with me just looking at the keys.py in the example directory with no real plan on the process or logic I would use so some of the names are kinda random.
#!/usr/bin/env python
import keybow
import time
import operator
keybow.setup(keybow.MINI)
multikey = {}
multikeyoutput = {}
#print(keybow.pins)
def keycounter():
global multikeyoutput
buttons_list = []
compoundkey = None
for key in multikeyoutput.keys():
buttons_list.append (int(multikeyoutput.get(key)))
# print(buttons_list)
compoundkey = "".join(str(int((button))) for button in buttons_list)
print("KeyCode: {}".format (int((compoundkey),2)))
multikeyoutput = {}
multikey = {}
button = None
@keybow.on()
def handle_key(index, state):
global multikey
global multikeyoutput
for i in keybow.pins:
# print("i is: {}".format (i))
keystatus = 0
keystatus = int(operator.not_(keybow.GPIO.input(i)))
multikey[keybow.pins.index(i)] = int(bool(multikey.get(keybow.pins.index(i), 0) + keystatus) == True)
if state:
keybow.set_led(index, 255, 0, 0)
print("MultiKey while keys are down: {}".format (multikey))
multikeyoutput = multikey.copy()
multikey = {}
keystatus = None
else:
keybow.set_led(index, 0, 0, 0)
while True:
keybow.show()
if bool(multikeyoutput):
keycounter()
# else:
time.sleep(1.0 / 60.0)