forked from jfurcean/pyportal-app-launcher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyportal-app-launcher.py
114 lines (91 loc) · 3.89 KB
/
pyportal-app-launcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import time
import board
import adafruit_touchscreen
from adafruit_pyportal import PyPortal
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
keyboard_active = False
#Initiallize the Keyboard
try:
kbd = Keyboard(usb_hid.devices)
keyboard_active = True
except OSError:
keyboard_active = False
WIDTH = board.DISPLAY.width
HEIGHT = board.DISPLAY.height
# the current working directory (where this file is)
cwd = ("/"+__file__).rsplit('/', 1)[0]
#Initialize the Pyportal with the default_bg set to the BMP file with all your icons.
pyportal = PyPortal(url='',
json_path='',
status_neopixel=board.NEOPIXEL,
default_bg=cwd+"/button-template-6.BMP",
text_font=cwd+"/fonts/Collegiate-50.bdf",
text_position=((100, 129), (155, 180)),
text_color=(0x000000, 0x000000),
caption_text='',
caption_font=cwd+"/fonts/Collegiate-24.bdf",
caption_position=(40, 220),
caption_color=0x000000)
# These pins are used as both analog and digital! XL, XR and YU must be analog
# and digital capable. YD just need to be digital
ts = adafruit_touchscreen.Touchscreen(board.TOUCH_XL, board.TOUCH_XR,
board.TOUCH_YD, board.TOUCH_YU,
calibration=((5200, 59000), (5800, 57000)),
size=(WIDTH, HEIGHT))
p_list = []
while True :
# If the keyboard is active then we can use the PyPortal like a keyboard (USB HID)
if keyboard_active:
p = ts.touch_point
if p:
# append each touch connection to a list
# I had an issue with the first touch detected not being accurate
p_list.append(p)
#affter three trouch detections have occured.
if len(p_list) == 3:
#discard the first touch detection and average the other two get the x,y of the touch
x = (p_list[1][0]+p_list[2][0])/2
y = (p_list[1][1]+p_list[2][1])/2
print(x,y)
# I will refer the the icon/button matrix using the following grid.
# A1 is the icon/button in the top left corner looking at the PyPortal
# C2 is the icon/button in the bottom right corner
# +---+----+----+----+
# | | A | B | C |
# +---+----+----+----+
# | 1 | A1 | B1 | C1 |
# | 2 | A2 | B2 | C2 |
# +---+----+----+----+
# For each button/icon pressed we send a keyboard command using kbd.send
# this can send multiple key presses as if you were pressing them all at the same time
# using ALT+Control+Shift+Command+[some letter]
# Column A
if x > 22.5 and x < 147.5:
# Icon/Button A1 - Mute Teams
if y > 20 and y < 145:
kbd.send(Keycode.CONTROL,Keycode.SHIFT, Keycode.M)
# Icon/Button A2 - VS Code
elif y > 175 and y < 300:
kbd.send(Keycode.CONTROL,Keycode.SHIFT, Keycode.ALT, Keycode.C)
# Column B
elif x > 177.5 and x < 302.5:
# Icon/Button B1 - Jellyfin
if y > 20 and y < 145:
kbd.send(Keycode.CONTROL,Keycode.SHIFT, Keycode.ALT, Keycode.J)
# Icon/Button B2
elif y > 175 and y < 300:
kbd.send(Keycode.CONTROL,Keycode.ALT, Keycode.DELETE)
# Column C
elif x > 332.5 and x < 457.5:
# Icon/Button C1 - Prusa MK3 FlashAir Website
if y > 20 and y < 145:
kbd.send(Keycode.CONTROL, Keycode.SHIFT, Keycode.ALT, Keycode.P)
# Icon/Button C2 - Terminal
elif y > 175 and y < 300:
kbd.send(Keycode.CONTROL,Keycode.SHIFT, Keycode.ALT, Keycode.T)
# clear list for next detection
p_list = []
# sleap to avoid pressing two buttons on accident
time.sleep(.5)