Repository navigation
Expand file tree
/
Copy pathcode.py
More file actions
261 lines (206 loc) · 8.23 KB
/
Copy pathcode.py
File metadata and controls
261 lines (206 loc) · 8.23 KB
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
import board
import busio
import displayio
import os
import terminalio
import board
import busio
import time
import audiomp3
import audiopwmio
from usb_cdc import data
import kmk.utils
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from kmk.modules import Module
from kmk.modules.macros import Tap
# import adafruit_displayio_ssd1306
from kmk.modules.macros import Macros
from kmk.modules.layers import Layers
# from adafruit_display_text import label
from kmk.kmk_keyboard import KMKKeyboard
from kmk.keys import KC
from kmk.scanners import DiodeOrientation
kmk.utils._debug_enabled = False
import time
audio = audiopwmio.PWMAudioOut(board.GP27)
audio_file = None
decoder = None
#decoder = audiomp3.MP3Decoder(open("hora-do-shooow-porra.mp3", "rb"))
sda, scl = board.GP0, board.GP1
i2c = busio.I2C(scl, sda)
# If address 0x27 does not work try 0x3F
lcd = LCD(I2CPCF8574Interface(i2c, 0x27), num_rows=2, num_cols=16)
class NotificationDisplay(Module):
def __init__(self, display, width=16, scroll_interval=0.35):
self.display = display
self.width = width
self.scroll_interval = scroll_interval
self.buffer = bytearray()
self.lines = None
self.offset = 0
self.last_scroll = time.monotonic()
self.resume_at = 0
def during_bootup(self, keyboard):
return
def before_matrix_scan(self, keyboard):
return
def after_matrix_scan(self, keyboard):
return
def process_key(self, keyboard, key, is_pressed, int_coord):
return key
def before_hid_send(self, keyboard):
now = time.monotonic()
holding = now < self.resume_at
if self.resume_at and not holding:
self.resume_at = 0
if self.lines:
self.offset = 0
self.last_scroll = now
self._draw()
if (
self.lines
and not holding
and self.offset < self._max_offset()
and now - self.last_scroll >= self.scroll_interval
):
self.offset += 1
self.last_scroll = now
self._draw()
if not data:
return
waiting = data.in_waiting
if waiting == 0:
return
chunk = data.read(waiting)
self.buffer.extend(chunk)
while True:
index = self.buffer.find(b"\n")
if index == -1:
break
message = bytes(self.buffer[:index]).decode("ascii").rstrip("\r")
self.buffer = self.buffer[index + 1:]
self._show(message)
def _show(self, message):
parts = message.split("\t", 1)
title = parts[0].strip() or "Notificacao"
body = parts[1].strip() if len(parts) == 2 else ""
self.lines = (title, body)
self.offset = 0
self.last_scroll = time.monotonic()
if time.monotonic() >= self.resume_at:
self._draw()
data.write(b"OK\n")
def show_temporary(self, title, body="", duration=2.5):
self.resume_at = time.monotonic() + duration
self._draw((title, body), 0)
def _max_offset(self):
return max(0, max(len(self.lines[0]), len(self.lines[1])) - self.width)
def _window(self, text, offset):
if len(text) <= self.width:
return (text + " " * self.width)[:self.width]
start = min(offset, len(text) - self.width)
return text[start:start + self.width]
def _draw(self, lines=None, offset=None):
lines = self.lines if lines is None else lines
offset = self.offset if offset is None else offset
for row, text in enumerate(lines):
self.display.set_cursor_pos(row, 0)
self.display.print(self._window(text, offset))
def after_hid_send(self, keyboard):
return
def on_powersave_enable(self, keyboard):
return
def on_powersave_disable(self, keyboard):
return
lcd.set_cursor_pos(0, 0)
lcd.print("Starting........")
time.sleep(0.1)
#audio.play(decoder)
#while audio.playing:
# pass
lcd.clear()
lcd.print("End Start")
lcd.clear()
lcd.print("Hello World!")
lcd.set_cursor_pos(0, 0)
lcd.print("*****")
lcd.clear()
lcd.set_cursor_pos(0, 0)
lcd.print("HELLO KEYBOARD")
lcd.set_cursor_pos(0, 0)
# start_time = time.monotonic()
# 3
keyboard = KMKKeyboard()
macros = Macros()
keyboard.modules.append(macros)
notification_display = NotificationDisplay(lcd)
keyboard.modules.append(notification_display)
keyboard.row_pins = (board.GP25, board.GP24, board.GP23,
board.GP22, board.GP21,)
keyboard.col_pins = (board.GP2, board.GP3, board.GP4, board.GP5, board.GP6, board.GP7,
board.GP8, board.GP9, board.GP10, board.GP11, board.GP12, board.GP13, board.GP14,)
keyboard.modules.append(Layers())
def keys_pressed1(keyboard):
notification_display.show_temporary("Layer 1", "Ativada")
def keys_pressed2(keyboard):
notification_display.show_temporary("Layer 2", "Ativada")
def play_track(filename):
global audio_file, decoder
audio.stop()
if audio_file:
audio_file.close()
audio_file = open(filename, "rb")
decoder = audiomp3.MP3Decoder(audio_file)
audio.play(decoder)
def play_music(keyboard):
play_track("RB.mp3")
def play_music2(keyboard):
play_track("cafe.mp3")
def play_music3(keyboard):
play_track("hora-do-shooow-porra.mp3")
WOW = KC.MACRO(
"""⢀⡴⠑⡄⠀⠀⠀⠀⠀⠀⠀⣀⣀⣤⣤⣤⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠸⡇⠀⠿⡀⠀⠀⠀⣀⡴⢿⣿⣿⣿⣿⣿⣿⣿⣷⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠑⢄⣠⠾⠁⣀⣄⡈⠙⣿⣿⣿⣿⣿⣿⣿⣿⣆⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⢀⡀⠁⠀⠀⠈⠙⠛⠂⠈⣿⣿⣿⣿⣿⠿⡿⢿⣆⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢀⡾⣁⣀⠀⠴⠂⠙⣗⡀⠀⢻⣿⣿⠭⢤⣴⣦⣤⣹⠀⠀⠀⢀⢴⣶⣆
⠀⠀⢀⣾⣿⣿⣿⣷⣮⣽⣾⣿⣥⣴⣿⣿⡿⢂⠔⢚⡿⢿⣿⣦⣴⣾⠁⠸⣼⡿
⠀⢀⡞⠁⠙⠻⠿⠟⠉⠀⠛⢹⣿⣿⣿⣿⣿⣌⢤⣼⣿⣾⣿⡟⠉⠀⠀⠀⠀⠀
⠀⣾⣷⣶⠇⠀⠀⣤⣄⣀⡀⠈⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
⠀⠉⠈⠉⠀⠀⢦⡈⢻⣿⣿⣿⣶⣶⣶⣶⣤⣽⡹⣿⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠉⠲⣽⡻⢿⣿⣿⣿⣿⣿⣿⣷⣜⣿⣿⣿⡇⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢸⣿⣿⣷⣶⣮⣭⣽⣿⣿⣿⣿⣿⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣀⣀⣈⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠛⠻⠿⠿⠿⠿⠛⠉""")
LAYER_T1 = KC.TO(0)
LAYER_T2 = KC.TO(1)
KEY_M = KC.DOT
KEY_C = KC.C
KEY_H = KC.H
KEYS_PRESSED1 = KC.MACRO(keys_pressed1, Tap(LAYER_T1))
KEYS_PRESSED2 = KC.MACRO(keys_pressed2, Tap(LAYER_T2))
KEYS_PRESSED3 = KC.MACRO(play_music, Tap(KEY_M))
KEYS_PRESSED4 = KC.MACRO(play_music2, Tap(KEY_C))
KEYS_PRESSED5 = KC.MACRO(play_music3, Tap(KEY_H))
keyboard.diode_orientation = DiodeOrientation.COL2ROW
keyboard.keymap = [
[
KC.ESC, KC.N1, KC.N2, KC.N3, KC.N4, KC.N5, KC.N6, KC.N7, KC.N8, KC.N9, KC.N0, KC.MINUS, KC.BSPC,
KC.TAB, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.P, KC.LBRACKET, KC.RBRACKET,
KC.BSLASH, KC.A, KC.S, KC.D, KC.F, KC.G, KC.H, KC.J, KC.K, KC.L, KC.SCOLON, KC.QUOTE, KC.ENTER,
KC.LSHIFT, KC.Z, KC.X, KC.C, KC.V, KC.B, KC.N, KC.M, KC.COMM, KC.DOT, KC.SLSH, KC.UP, KEYS_PRESSED2,
KC.LCTL, KC.LGUI, KC.LALT, KC.SPC, KC.SPC, KC.F1, KC.F3, KC.F4, KC.F5, KC.EQUAL, KC.LEFT, KC.DOWN, KC.RIGHT,
],
[
KC.ESC, KC.F1, KC.F2, KC.F3, KC.F4, KC.F5, KC.F6, KC.F7, KC.F8, KC.F9, KC.F10, KC.F11, KC.F12,
KC.DEL, KC.Q, KC.W, KC.E, KC.R, KC.T, KC.Y, KC.U, KC.I, KC.O, KC.PSCR, KC.LBRACKET, KC.END,
KC.CAPS, KC.A, KC.S, KC.D, KC.F, KC.G, KEYS_PRESSED5, KC.J, KC.K, KC.L, KC.PGUP, KC.PGDOWN, KC.ENTER,
KC.LSHIFT, KC.Z, KC.X, KEYS_PRESSED4, KC.V, KC.B, KC.N, KEYS_PRESSED3, KC.COMM, KC.INSERT, KC.SLSH, KC.UP, KEYS_PRESSED1,
KC.LCTL, KC.LGUI, KC.LALT, KC.SPC, KC.SPC, KC.SPC, KC.SPC, KC.SPC, WOW, KC.PSCR, KC.HOME, KC.DOWN, KC.END,
],
]
if __name__ == '__main__':
keyboard.go()