Use rot enc bush button for Q and S
This commit is contained in:
parent
88fb7d18db
commit
3cadd95e65
28
code.py
28
code.py
|
@ -30,6 +30,9 @@ from keycode_win_fr import Keycode
|
||||||
# Rotary encoder setup
|
# Rotary encoder setup
|
||||||
enc = rotaryio.IncrementalEncoder(board.GP0, board.GP1)
|
enc = rotaryio.IncrementalEncoder(board.GP0, board.GP1)
|
||||||
last_pos = 0
|
last_pos = 0
|
||||||
|
# Keys sent on rotary encoder rotation
|
||||||
|
rot_right = Keycode.A
|
||||||
|
rot_left = Keycode.Z
|
||||||
|
|
||||||
# When in ALT mode, buttons use an alternative keycode.
|
# When in ALT mode, buttons use an alternative keycode.
|
||||||
ALT = False
|
ALT = False
|
||||||
|
@ -49,8 +52,9 @@ buttons_gpio = {
|
||||||
"switch": dict(gpio=board.GP21, keycode_1=None, keycode_2=None, state=False, DIO=None, pullr=digitalio.Pull.DOWN, switch_setup=dict(gpio=board.GP7, state=False, DIO=None)),
|
"switch": dict(gpio=board.GP21, keycode_1=None, keycode_2=None, state=False, DIO=None, pullr=digitalio.Pull.DOWN, switch_setup=dict(gpio=board.GP7, state=False, DIO=None)),
|
||||||
"fn_1": dict(gpio=board.GP15, keycode_1=Keycode.W, keycode_2=Keycode.X, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
"fn_1": dict(gpio=board.GP15, keycode_1=Keycode.W, keycode_2=Keycode.X, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||||
"fn_2": dict(gpio=board.GP14, keycode_1=Keycode.L, keycode_2=Keycode.F, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
"fn_2": dict(gpio=board.GP14, keycode_1=Keycode.L, keycode_2=Keycode.F, state=False, DIO=None, pullr=digitalio.Pull.DOWN),
|
||||||
|
# This one is reversed (True when not pressed) so we need some logic to interpret a HIGH as False
|
||||||
|
"rot": dict(gpio=board.GP6, keycode_1=Keycode.Q, keycode_2=Keycode.S, state=False, DIO=None, pullr=digitalio.Pull.UP, reverse=True),
|
||||||
}
|
}
|
||||||
|
|
||||||
# GPIO setup
|
# GPIO setup
|
||||||
for btn in buttons_gpio:
|
for btn in buttons_gpio:
|
||||||
buttons_gpio[btn]['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['gpio'])
|
buttons_gpio[btn]['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['gpio'])
|
||||||
|
@ -61,12 +65,17 @@ for btn in buttons_gpio:
|
||||||
buttons_gpio[btn]['switch_setup']['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['switch_setup']['gpio'])
|
buttons_gpio[btn]['switch_setup']['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['switch_setup']['gpio'])
|
||||||
buttons_gpio[btn]['switch_setup']['DIO'].direction = digitalio.Direction.OUTPUT
|
buttons_gpio[btn]['switch_setup']['DIO'].direction = digitalio.Direction.OUTPUT
|
||||||
|
|
||||||
btn_scan_delay = 1/200
|
btn_scan_delay = 1.0/200
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
for btn in buttons_gpio:
|
for btn in buttons_gpio:
|
||||||
# If digital input is high and was not pressed previously
|
# Logic for switches that read True when not pressed
|
||||||
if buttons_gpio[btn]['DIO'].value and not buttons_gpio[btn]['state']:
|
if 'reverse' in buttons_gpio[btn]:
|
||||||
|
btn_value = not buttons_gpio[btn]['DIO'].value
|
||||||
|
else:
|
||||||
|
btn_value = buttons_gpio[btn]['DIO'].value
|
||||||
|
# If digital input is true and was not pressed previously
|
||||||
|
if btn_value and not buttons_gpio[btn]['state']:
|
||||||
if ALT:
|
if ALT:
|
||||||
if buttons_gpio[btn]['keycode_2'] is not None:
|
if buttons_gpio[btn]['keycode_2'] is not None:
|
||||||
keyboard.press(buttons_gpio[btn]['keycode_2'])
|
keyboard.press(buttons_gpio[btn]['keycode_2'])
|
||||||
|
@ -79,8 +88,8 @@ while True:
|
||||||
if not buttons_gpio[btn]['switch_setup']['DIO'].value:
|
if not buttons_gpio[btn]['switch_setup']['DIO'].value:
|
||||||
buttons_gpio[btn]['switch_setup']['DIO'].value = True
|
buttons_gpio[btn]['switch_setup']['DIO'].value = True
|
||||||
ALT = True
|
ALT = True
|
||||||
# If digital input is down and was pressed previously
|
# If digital input is false and was pressed previously
|
||||||
if not buttons_gpio[btn]['DIO'].value and buttons_gpio[btn]['state']:
|
if not btn_value and buttons_gpio[btn]['state']:
|
||||||
if ALT:
|
if ALT:
|
||||||
if buttons_gpio[btn]['keycode_2'] is not None:
|
if buttons_gpio[btn]['keycode_2'] is not None:
|
||||||
keyboard.release(buttons_gpio[btn]['keycode_2'])
|
keyboard.release(buttons_gpio[btn]['keycode_2'])
|
||||||
|
@ -95,11 +104,8 @@ while True:
|
||||||
ALT = False
|
ALT = False
|
||||||
pos = enc.position
|
pos = enc.position
|
||||||
if pos > last_pos:
|
if pos > last_pos:
|
||||||
if ALT:
|
keyboard.send(rot_right)
|
||||||
keyboard.send(Keycode.Q)
|
|
||||||
else:
|
|
||||||
keyboard.send(Keycode.A)
|
|
||||||
elif pos < last_pos:
|
elif pos < last_pos:
|
||||||
keyboard.send(Keycode.Z)
|
keyboard.send(rot_left)
|
||||||
last_pos = pos
|
last_pos = pos
|
||||||
time.sleep(btn_scan_delay)
|
time.sleep(btn_scan_delay)
|
||||||
|
|
Loading…
Reference in New Issue