-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.py
266 lines (193 loc) · 6.34 KB
/
code.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#import os
import gc
import time
import busio
import digitalio
import board
import displayio
import terminalio
import adafruit_displayio_ssd1306
from adafruit_display_text import label
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
gc.collect()
WIDTH = 128
HEIGHT = 64
CENTER_X = int(WIDTH/2)
CENTER_Y = int(HEIGHT/2)
displayio.release_displays()
SDA = board.GP0
SCL = board.GP1
i2c = busio.I2C(SCL, SDA)
if(i2c.try_lock()):
i2c.unlock()
display_bus = displayio.I2CDisplay(i2c, device_address=60)
display = adafruit_displayio_ssd1306.SSD1306(display_bus, width=128, height=64)
time.sleep(0.5)
####
buttonOne = digitalio.DigitalInOut(board.GP17)
buttonOne.direction = digitalio.Direction.OUTPUT
buttonTwo = digitalio.DigitalInOut(board.GP16)
buttonTwo.direction = digitalio.Direction.OUTPUT
buttonThree = digitalio.DigitalInOut(board.GP18)
buttonThree.direction = digitalio.Direction.OUTPUT
buttonFour = digitalio.DigitalInOut(board.GP19)
buttonFour.direction = digitalio.Direction.OUTPUT
buttonFive = digitalio.DigitalInOut(board.GP20)
buttonFive.direction = digitalio.Direction.OUTPUT
# Classes ########
class keyMacroGroup:
def __init__(self, header, keyMacroList):
self.header = header
self.keyMacroList = keyMacroList
class keyMacro:
def __init__(self, label, action):
self.label = label
self.action = action
# Set up a keyboard device.
kbd = Keyboard(usb_hid.devices)
layout = KeyboardLayoutUS(kbd)
def printButtonPress(text):
global displayMenu
global displayio
global display
global splash
color_bitmap = displayio.Bitmap(WIDTH, HEIGHT, 1)
color_palette = displayio.Palette(1)
color_palette[0] = 0x000000 # Black
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
time.sleep(0.02)
text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00, x=0, y=4)
splash.append(text_area)
time.sleep(0.02)
bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
splash.append(bg_sprite)
displayMenu = 1
splash = displayio.Group()
display.show(splash)
time.sleep(0.02)
def displayMacroList():
global displayMenu
global macroDictionary
global displayio
global display
if (displayMenu):
text_area = label.Label(terminalio.FONT, text=macroDictionary[currentMacroPage].header, color=0xFFFF00, x=0, y=(0 * displayLineHeight) + 4)
splash.append(text_area)
for index in macroDictionary[currentMacroPage].keyMacroList:
macroText = str(index + 1) + ") " + macroDictionary[currentMacroPage].keyMacroList[index].label
text_area = label.Label(terminalio.FONT, text=macroText, color=0xFFFF00, x=0, y=(((index + 1) * displayLineHeight) + 4))
splash.append(text_area)
displayMenu = 0
gc.collect()
####
splash = displayio.Group()
display.show(splash)
### MACRO FUNCTIONS
windowsMode = 0
if (windowsMode):
Keycode.COMMAND = Keycode.CONTROL
# Google Meet
def googleMeetToggleMic():
global kbd
kbd.send(Keycode.COMMAND, Keycode.D)
def googleMeetToggleCam():
global kbd
kbd.send(Keycode.COMMAND, Keycode.E)
def googleMeetRaiseHand():
global kbd
kbd.press(Keycode.COMMAND)
kbd.press(0xE0)
kbd.press(Keycode.H)
kbd.release_all()
def googleMeetHangUp():
global kbd
kbd.send(Keycode.ALT, Keycode.LEFT_ARROW)
# VS Code
def vsCodeBookmarkToggle():
global kbd
kbd.send(Keycode.COMMAND, Keycode.ALT, Keycode.K)
def vsCodeBookmarkListAll():
global kbd
kbd.send(Keycode.COMMAND, Keycode.SHIFT, Keycode.ALT, Keycode.K)
def vsCodeBookmarkPrevious():
global kbd
kbd.send(Keycode.COMMAND, Keycode.ALT, Keycode.J)
def vsCodeBookmarkNext():
global kbd
kbd.send(Keycode.COMMAND, Keycode.ALT, Keycode.L)
# Discord
def discordServerPrevious():
global kbd
kbd.send(Keycode.COMMAND, Keycode.ALT, Keycode.UP_ARROW)
def discordServerNext():
global kbd
kbd.send(Keycode.COMMAND, Keycode.ALT, Keycode.DOWN_ARROW)
def discordChannelPrevious():
global kbd
kbd.send(Keycode.ALT, Keycode.UP_ARROW)
def discordChannelNext():
global kbd
kbd.send(Keycode.ALT, Keycode.DOWN_ARROW)
### RUNNING CODE
displayMenu = 1
currentMacroPage = 0
displayLineHeight = 12
macroDictionary = {
0: keyMacroGroup(
'Google Meet',
{
0: keyMacro('Microphone', googleMeetToggleMic),
1: keyMacro('Camera', googleMeetToggleCam),
2: keyMacro('Raise Hand', googleMeetRaiseHand),
3: keyMacro('Hang Up', googleMeetHangUp)
}
),
1: keyMacroGroup(
'VS Code: Bookmarks',
{
0: keyMacro('Toggle', vsCodeBookmarkToggle),
1: keyMacro('List All', vsCodeBookmarkListAll),
2: keyMacro('Previous', vsCodeBookmarkPrevious),
3: keyMacro('Next', vsCodeBookmarkNext)
}
),
2: keyMacroGroup(
'Discord: Servers',
{
0: keyMacro('Server <<', discordServerPrevious),
1: keyMacro('Server >>', discordServerNext),
2: keyMacro('Channel <<', discordChannelPrevious),
3: keyMacro('Channel >>', discordChannelNext)
}
)
}
while True:
if buttonOne.value:
macroDictionary[currentMacroPage].keyMacroList[0].action()
time.sleep(0.2)
elif buttonTwo.value:
macroDictionary[currentMacroPage].keyMacroList[1].action()
time.sleep(0.2)
elif buttonThree.value:
macroDictionary[currentMacroPage].keyMacroList[2].action()
time.sleep(0.2)
elif buttonFour.value:
macroDictionary[currentMacroPage].keyMacroList[3].action()
time.sleep(0.2)
elif buttonFive.value:
# Debugging memory
# printButtonPress(str(gc.mem_free()))
printButtonPress('')
if currentMacroPage == (len(macroDictionary) - 1):
currentMacroPage = 0
else:
currentMacroPage = currentMacroPage + 1
time.sleep(0.2)
else:
# Dispay the list of macros for the current page
displayMacroList()
time.sleep(0.01)