Use loops

This commit is contained in:
ABelliqueux 2024-02-16 18:16:03 +01:00
commit 1bf89da3e8
11 changed files with 427 additions and 0 deletions

73
code.py Normal file
View File

@ -0,0 +1,73 @@
# Raspberry Pi Pico Stopmo pad
#
# Using CircuitPython : https://circuitpython.org/board/raspberry_pi_pico/
# Using Adafruit USB_HID Library : https://github.com/adafruit/Adafruit_CircuitPython_HID/releases
#
# Buttons default mapping
# Red = F
# Green = G
# Blue = H
# Black = I
#
# Yellow on : multimedia mode
#
# Forked from
# DroneBot Workshop 2021
# https://dronebotworkshop.com
import time
import board
import digitalio
import usb_hid
# Regulare keys
from adafruit_hid.keyboard import Keyboard
from keyboard_layout_win_fr import KeyboardLayout
from keycode_win_fr import Keycode
# multimedia keys
# ~ from adafruit_hid.consumer_control import ConsumerControl
# ~ from adafruit_hid.consumer_control_code import ConsumerControlCode
# ~ cc = ConsumerControl(usb_hid.devices)
# KB setup
keyboard = Keyboard(usb_hid.devices)
keyboard_layout = KeyboardLayout(keyboard)
# Buttons setup
# Change GPIOs according to HW
buttons_gpio = {
# name GPIO Keycode State DigitalIO (switch)
"red" : dict(gpio=board.GP18, keycode=Keycode.G, state=False, DIO=None),
"green" : dict(gpio=board.GP19, keycode=Keycode.H, state=False, DIO=None),
"blue" : dict(gpio=board.GP16, keycode=Keycode.I, state=False, DIO=None),
"black" : dict(gpio=board.GP20, keycode=Keycode.J, state=False, DIO=None),
"yellow": dict(gpio=board.GP17, keycode=Keycode.K, state=False, DIO=None),
"switch": dict(gpio=board.GP21, keycode=Keycode.LEFT_SHIFT, state=False, DIO=None, switch_setup=dict(gpio=board.GP7, DIO=None))
}
# GPIO setup
for btn in buttons_gpio:
buttons_gpio[btn]['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['gpio'])
buttons_gpio[btn]['DIO'].direction = digitalio.Direction.INPUT
buttons_gpio[btn]['DIO'].pull = digitalio.Pull.DOWN
# Switch setup
if 'switch_setup' in buttons_gpio[btn]:
buttons_gpio[btn]['switch_setup']['DIO'] = digitalio.DigitalInOut(buttons_gpio[btn]['switch_setup']['gpio'])
buttons_gpio[btn]['switch_setup']['DIO'].direction = digitalio.Direction.OUTPUT
btn_scan_delay = 1/200
while True:
for btn in buttons_gpio:
if buttons_gpio[btn]['DIO'].value and not buttons_gpio[btn]['state']:
keyboard.press(buttons_gpio[btn]['keycode'])
buttons_gpio[btn]['state'] = not buttons_gpio[btn]['state']
if 'switch_setup' in buttons_gpio[btn]:
buttons_gpio[btn]['switch_setup']['DIO'].value = True
if not buttons_gpio[btn]['DIO'].value and buttons_gpio[btn]['state']:
keyboard.release(buttons_gpio[btn]['keycode'])
buttons_gpio[btn]['state'] = not buttons_gpio[btn]['state']
if 'switch_setup' in buttons_gpio[btn]:
buttons_gpio[btn]['switch_setup']['DIO'].value = False
time.sleep(btn_scan_delay)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
lib/adafruit_hid/mouse.mpy Normal file

Binary file not shown.

View File

@ -0,0 +1,202 @@
# SPDX-FileCopyrightText: 2021 Neradoc NeraOnGit@ri1.fr
#
# SPDX-License-Identifier: MIT
"""
This file was automatically generated using Circuitpython_Keyboard_Layouts
"""
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
from adafruit_hid.keyboard_layout_base import KeyboardLayoutBase
class KeyboardLayout(KeyboardLayoutBase):
ASCII_TO_KEYCODE = (
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x2a' # BACKSPACE
b'\x2b' # '\t'
b'\x28' # '\n'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x29' # ESC
b'\x00'
b'\x00'
b'\x00'
b'\x00'
b'\x2c' # ' '
b'\x38' # '!'
b'\x20' # '"'
b'\x20' # '#'
b'\x30' # '$'
b'\xb4' # '%'
b'\x1e' # '&'
b'\x21' # "'"
b'\x22' # '('
b'\x2d' # ')'
b'\x31' # '*'
b'\xae' # '+'
b'\x10' # ','
b'\x23' # '-'
b'\xb6' # '.'
b'\xb7' # '/'
b'\xa7' # '0'
b'\x9e' # '1'
b'\x9f' # '2'
b'\xa0' # '3'
b'\xa1' # '4'
b'\xa2' # '5'
b'\xa3' # '6'
b'\xa4' # '7'
b'\xa5' # '8'
b'\xa6' # '9'
b'\x37' # ':'
b'\x36' # ';'
b'\x64' # '<'
b'\x2e' # '='
b'\xe4' # '>'
b'\x90' # '?'
b'\x27' # '@'
b'\x94' # 'A'
b'\x85' # 'B'
b'\x86' # 'C'
b'\x87' # 'D'
b'\x88' # 'E'
b'\x89' # 'F'
b'\x8a' # 'G'
b'\x8b' # 'H'
b'\x8c' # 'I'
b'\x8d' # 'J'
b'\x8e' # 'K'
b'\x8f' # 'L'
b'\xb3' # 'M'
b'\x91' # 'N'
b'\x92' # 'O'
b'\x93' # 'P'
b'\x84' # 'Q'
b'\x95' # 'R'
b'\x96' # 'S'
b'\x97' # 'T'
b'\x98' # 'U'
b'\x99' # 'V'
b'\x9d' # 'W'
b'\x9b' # 'X'
b'\x9c' # 'Y'
b'\x9a' # 'Z'
b'\x22' # '['
b'\x25' # '\\'
b'\x2d' # ']'
b'\x26' # '^'
b'\x25' # '_'
b'\x00' # '`' (Dead key)
b'\x14' # 'a'
b'\x05' # 'b'
b'\x06' # 'c'
b'\x07' # 'd'
b'\x08' # 'e'
b'\x09' # 'f'
b'\x0a' # 'g'
b'\x0b' # 'h'
b'\x0c' # 'i'
b'\x0d' # 'j'
b'\x0e' # 'k'
b'\x0f' # 'l'
b'\x33' # 'm'
b'\x11' # 'n'
b'\x12' # 'o'
b'\x13' # 'p'
b'\x04' # 'q'
b'\x15' # 'r'
b'\x16' # 's'
b'\x17' # 't'
b'\x18' # 'u'
b'\x19' # 'v'
b'\x1d' # 'w'
b'\x1b' # 'x'
b'\x1c' # 'y'
b'\x1a' # 'z'
b'\x21' # '{'
b'\x23' # '|'
b'\x2e' # '}'
b'\x00' # '~' (Dead key)
b'\x00'
)
NEED_ALTGR = '#@[\\]^{|}¤€'
HIGHER_ASCII = {
0xe9: 0x1f, # 'é'
0xe8: 0x24, # 'è'
0xe7: 0x26, # 'ç'
0xe0: 0x27, # 'à'
0xb0: 0xad, # '°'
0x20ac: 0x08, # '€'
0xa3: 0xb0, # '£'
0xa4: 0x30, # '¤'
0xf9: 0x34, # 'ù'
0xb2: 0x35, # '²'
0xb5: 0xb1, # 'µ'
0xa7: 0xb8, # '§'
}
COMBINED_KEYS = {
0xe3: 0x1fe1, # 'ã'
0xc3: 0x1fc1, # 'Ã'
0xf1: 0x1fee, # 'ñ'
0xd1: 0x1fce, # 'Ñ'
0xf5: 0x1fef, # 'õ'
0xd5: 0x1fcf, # 'Õ'
0x7e: 0x1fa0, # '~'
0xe0: 0x24e1, # 'à'
0xe8: 0x24e5, # 'è'
0xec: 0x24e9, # 'ì'
0xf2: 0x24ef, # 'ò'
0xf9: 0x24f5, # 'ù'
0xc0: 0x24c1, # 'À'
0xc8: 0x24c5, # 'È'
0xcc: 0x24c9, # 'Ì'
0xd2: 0x24cf, # 'Ò'
0xd9: 0x24d5, # 'Ù'
0x60: 0x24a0, # '`'
0xe2: 0x2f61, # 'â'
0xea: 0x2f65, # 'ê'
0xee: 0x2f69, # 'î'
0xf4: 0x2f6f, # 'ô'
0xfb: 0x2f75, # 'û'
0xc2: 0x2f41, # 'Â'
0xca: 0x2f45, # 'Ê'
0xce: 0x2f49, # 'Î'
0xd4: 0x2f4f, # 'Ô'
0xdb: 0x2f55, # 'Û'
0x5e: 0x2f20, # '^'
0xe4: 0xaf61, # 'ä'
0xeb: 0xaf65, # 'ë'
0xef: 0xaf69, # 'ï'
0xf6: 0xaf6f, # 'ö'
0xfc: 0xaf75, # 'ü'
0xff: 0xaf79, # 'ÿ'
0xc4: 0xaf41, # 'Ä'
0xcb: 0xaf45, # 'Ë'
0xcf: 0xaf49, # 'Ï'
0xd6: 0xaf4f, # 'Ö'
0xdc: 0xaf55, # 'Ü'
0xa8: 0xaf20, # '¨'
}

152
lib/keycode_win_fr.py Normal file
View File

@ -0,0 +1,152 @@
# SPDX-FileCopyrightText: 2021 Neradoc NeraOnGit@ri1.fr
#
# SPDX-License-Identifier: MIT
"""
This file was automatically generated using Circuitpython_Keyboard_Layouts
"""
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/Neradoc/Circuitpython_Keyboard_Layouts.git"
class Keycode:
A = 0x14
B = 0x05
C = 0x06
D = 0x07
E = 0x08
F = 0x09
G = 0x0a
H = 0x0b
I = 0x0c
J = 0x0d
K = 0x0e
L = 0x0f
M = 0x33
N = 0x11
O = 0x12
P = 0x13
Q = 0x04
R = 0x15
S = 0x16
T = 0x17
U = 0x18
V = 0x19
W = 0x1d
X = 0x1b
Y = 0x1c
Z = 0x1a
ALT = 0xe2
END = 0x4d
F1 = 0x3a
F2 = 0x3b
F3 = 0x3c
F4 = 0x3d
F5 = 0x3e
F6 = 0x3f
F7 = 0x40
F8 = 0x41
F9 = 0x42
F10 = 0x43
F11 = 0x44
F12 = 0x45
F13 = 0x68
F14 = 0x69
F15 = 0x6a
F16 = 0x6b
F17 = 0x6c
F18 = 0x6d
F19 = 0x6e
F20 = 0x6f
F21 = 0x70
F22 = 0x71
F23 = 0x72
F24 = 0x73
GUI = 0xe3
ONE = 0x1e
SIX = 0x23
TAB = 0x2b
TWO = 0x1f
FIVE = 0x22
FOUR = 0x21
HOME = 0x4a
NINE = 0x26
ZERO = 0x27
ALTGR = 0xe6
COMMA = 0x10
EIGHT = 0x25
ENTER = 0x28
GRAVE = 0x24
OEM_8 = 0x38
PAUSE = 0x48
QUOTE = 0x35
SEVEN = 0x24
SHIFT = 0xe1
SPACE = 0x2c
THREE = 0x20
TILDE = 0x1f
TREMA = 0x2f
ACCENT_CIRCONFLEXE = 0x2f
APPLICATION = 0x65
BACKSLASH = 0x31
BACKSPACE = 0x2a
CAPS_LOCK = 0x39
COMMAND = 0xe3
CONTROL = 0xe0
DELETE = 0x4c
DOWN_ARROW = 0x51
EQUALS = 0x2e
ESCAPE = 0x29
FORWARD_SLASH = 0x37
GRAVE_ACCENT = 0x34
INSERT = 0x49
KEYPAD_ASTERISK = 0x55
KEYPAD_EIGHT = 0x60
KEYPAD_FIVE = 0x5d
KEYPAD_FORWARD_SLASH = 0x54
KEYPAD_FOUR = 0x5c
KEYPAD_MINUS = 0x56
KEYPAD_NINE = 0x61
KEYPAD_NUMLOCK = 0x53
KEYPAD_ONE = 0x59
KEYPAD_PERIOD = 0x63
KEYPAD_PLUS = 0x57
KEYPAD_SEVEN = 0x5f
KEYPAD_SIX = 0x5e
KEYPAD_THREE = 0x5b
KEYPAD_TWO = 0x5a
KEYPAD_ZERO = 0x62
LEFT_ALT = 0xe2
LEFT_ARROW = 0x50
LEFT_BRACKET = 0x2d
LEFT_CONTROL = 0xe0
LEFT_GUI = 0xe3
LEFT_SHIFT = 0xe1
OEM_102 = 0x64
OPTION = 0xe2
PAGE_DOWN = 0x4e
PAGE_UP = 0x4b
PERIOD = 0x36
PRINT_SCREEN = 0x46
RETURN = 0x28
RIGHT_ALT = 0xe6
RIGHT_ARROW = 0x4f
RIGHT_BRACKET = 0x2f
RIGHT_CONTROL = 0xe4
RIGHT_GUI = 0xe7
RIGHT_SHIFT = 0xe5
SCROLL_LOCK = 0x47
SEMICOLON = 0x30
SPACEBAR = 0x2c
UP_ARROW = 0x52
WINDOWS = 0xe3
@classmethod
def modifier_bit(cls, keycode):
"""Return the modifer bit to be set in an HID keycode report if this is a
modifier key; otherwise return 0."""
return (
1 << (keycode - 0xE0) if cls.LEFT_CONTROL <= keycode <= cls.RIGHT_GUI else 0
)