Skip to content

Commit 0efe996

Browse files
committed
update for MicroHydra v1.0
1 parent ea8b8ef commit 0efe996

File tree

14 files changed

+2947
-1487
lines changed

14 files changed

+2947
-1487
lines changed

ports/esp32/boards/MICROHYDRA/launcher/HyDE.py

Lines changed: 219 additions & 68 deletions
Large diffs are not rendered by default.

ports/esp32/boards/MICROHYDRA/launcher/files.py

Lines changed: 83 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from lib import st7789fbuf, mhconfig, mhoverlay, keyboard
1+
from lib import st7789fbuf, mhconfig, mhoverlay, smartkeyboard, beeper
22
from font import vga2_16x32 as font
33
import os, machine, time, math
44

@@ -29,8 +29,6 @@
2929

3030

3131

32-
kb = keyboard.KeyBoard()
33-
3432
tft = st7789fbuf.ST7789(
3533
machine.SPI(
3634
1,baudrate=40000000,sck=machine.Pin(36),mosi=machine.Pin(35),miso=None),
@@ -45,10 +43,15 @@
4543
)
4644

4745
config = mhconfig.Config()
46+
kb = smartkeyboard.KeyBoard(config=config)
4847
overlay = mhoverlay.UI_Overlay(config, kb, display_fbuf=tft)
48+
beep = beeper.Beeper()
4949

5050
sd = None
5151

52+
# copied_file = None
53+
clipboard = None
54+
5255
def mount_sd():
5356
global sd
5457
# sd needs to be mounted for any files in /sd
@@ -188,47 +191,92 @@ def parse_files():
188191
def ext_options(overlay):
189192
"""Create popup with options for new file or directory."""
190193
cwd = os.getcwd()
191-
option = overlay.popup_options(("New Directory", "New File", "Refresh"), title=f"{cwd}:")
194+
195+
options = ["Paste", "New Directory", "New File", "Refresh", "Exit to launcher"]
196+
197+
if clipboard == None:
198+
# dont give the paste option if there's nothing to paste.
199+
options.pop(0)
200+
201+
option = overlay.popup_options(options, title=f"{cwd}:")
192202
if option == "New Directory":
203+
play_sound(("D3"), 30)
193204
name = overlay.text_entry(title="Directory name:", blackout_bg=True)
205+
play_sound(("G3"), 30)
194206
try:
195207
os.mkdir(name)
196208
except Exception as e:
197209
overlay.error(e)
210+
198211
elif option == "New File":
212+
play_sound(("B3"), 30)
199213
name = overlay.text_entry(title="File name:", blackout_bg=True)
214+
play_sound(("G3"), 30)
200215
try:
201216
with open(name, "w") as newfile:
202217
newfile.write("")
203218
except Exception as e:
204219
overlay.error(e)
220+
205221
elif option == "Refresh":
206-
os.sync()
222+
play_sound(("B3","G3","D3"), 30)
207223
mount_sd()
224+
os.sync()
225+
226+
elif option == "Paste":
227+
play_sound(("D3","G3","D3"), 30)
228+
229+
source_path, file_name = clipboard
230+
231+
source = f"{source_path}/{file_name}".replace('//','/')
232+
dest = f"{cwd}/{file_name}".replace('//','/')
233+
234+
with open(source,"rb") as old_file:
235+
with open(dest, "wb") as new_file:
236+
while True:
237+
l = old_file.read(512)
238+
if not l: break
239+
new_file.write(l)
240+
241+
elif option == "Exit to launcher":
242+
overlay.draw_textbox("Exiting...", _DISPLAY_WIDTH//2, _DISPLAY_HEIGHT//2)
243+
tft.show()
244+
rtc = machine.RTC()
245+
rtc.memory('')
246+
machine.reset()
208247

209248
def file_options(file, overlay):
210249
"""Create popup with file options for given file."""
250+
global clipboard
251+
211252
options = ("open", "copy", "rename", "delete")
212253
option = overlay.popup_options(options, title=f'"{file}":')
213254

214255
if option == "open":
256+
play_sound(("G3"), 30)
215257
open_file(file)
216258
elif option == "copy":
217-
new_name = overlay.text_entry(start_value=file, title=f"Rename '{file}':", blackout_bg=True)
218-
with open(file,"rb") as source:
219-
with open(new_name, "wb") as dest:
220-
while True:
221-
l = source.read(512)
222-
if not l: break
223-
dest.write(l)
259+
# store copied file to clipboard
260+
clipboard = (os.getcwd(), file)
261+
# new_name = overlay.text_entry(start_value=file, title=f"Rename '{file}':", blackout_bg=True)
262+
play_sound(("D3","G3","D3"), 30)
263+
# with open(file,"rb") as source:
264+
# with open(new_name, "wb") as dest:
265+
# while True:
266+
# l = source.read(512)
267+
# if not l: break
268+
# dest.write(l)
224269

225270
elif option == "rename":
271+
play_sound(("B3"), 30)
226272
new_name = overlay.text_entry(start_value=file, title=f"Rename '{file}':", blackout_bg=True)
227273
os.rename(file,new_name)
228274

229275
elif option == "delete":
276+
play_sound(("D3"), 30)
230277
confirm = overlay.popup_options(("cancel", "confirm"), title=f'Delete "{file}"?', extended_border=True)
231278
if confirm == "confirm":
279+
play_sound(("D3","B3","G3","G3"), 30)
232280
os.remove(file)
233281

234282

@@ -254,6 +302,10 @@ def open_file(file):
254302
rtc.memory(full_path)
255303
time.sleep_ms(10)
256304
machine.reset()
305+
306+
def play_sound(notes, time_ms=30):
307+
if config['ui_sound']:
308+
beep.play(notes, time_ms, config['volume'])
257309

258310
def main_loop(tft, kb, config, overlay):
259311

@@ -268,9 +320,12 @@ def main_loop(tft, kb, config, overlay):
268320
for key in new_keys:
269321
if key == ";":
270322
view.up()
323+
play_sound(("G3","B3"), 30)
271324
elif key == ".":
272325
view.down()
273-
elif key == "ENT" or key == "GO":
326+
play_sound(("D3","B3"), 30)
327+
elif key == "ENT" or key == "SPC":
328+
play_sound(("G3","B3","D3"), 30)
274329
selection_name = file_list[view.cursor_index]
275330
if selection_name == "/.../": # new file
276331
ext_options(overlay)
@@ -296,16 +351,24 @@ def main_loop(tft, kb, config, overlay):
296351
view.clamp_cursor()
297352

298353
elif key == "BSPC" or key == "`":
299-
# previous directory
300-
if os.getcwd() == "/sd":
301-
os.chdir("/")
302-
else:
303-
os.chdir("..")
354+
play_sound(("D3","B3","G3"), 30)
355+
# previous directory
356+
if os.getcwd() == "/sd":
357+
os.chdir("/")
358+
else:
359+
os.chdir("..")
360+
file_list, dir_dict = parse_files()
361+
view.items = file_list
362+
view.dir_dict = dir_dict
363+
view.cursor_index = 0
364+
view.view_index = 0
365+
366+
elif key == "GO":
367+
ext_options(overlay)
304368
file_list, dir_dict = parse_files()
305369
view.items = file_list
306370
view.dir_dict = dir_dict
307-
view.cursor_index = 0
308-
view.view_index = 0
371+
view.clamp_cursor()
309372

310373
view.draw()
311374
tft.show()

ports/esp32/boards/MICROHYDRA/launcher/icons/icons.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)