Skip to content

Commit

Permalink
update for MicroHydra v1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
echo-lalia committed Apr 15, 2024
1 parent ea8b8ef commit 0efe996
Show file tree
Hide file tree
Showing 14 changed files with 2,947 additions and 1,487 deletions.
287 changes: 219 additions & 68 deletions ports/esp32/boards/MICROHYDRA/launcher/HyDE.py

Large diffs are not rendered by default.

103 changes: 83 additions & 20 deletions ports/esp32/boards/MICROHYDRA/launcher/files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from lib import st7789fbuf, mhconfig, mhoverlay, keyboard
from lib import st7789fbuf, mhconfig, mhoverlay, smartkeyboard, beeper
from font import vga2_16x32 as font
import os, machine, time, math

Expand Down Expand Up @@ -29,8 +29,6 @@



kb = keyboard.KeyBoard()

tft = st7789fbuf.ST7789(
machine.SPI(
1,baudrate=40000000,sck=machine.Pin(36),mosi=machine.Pin(35),miso=None),
Expand All @@ -45,10 +43,15 @@
)

config = mhconfig.Config()
kb = smartkeyboard.KeyBoard(config=config)
overlay = mhoverlay.UI_Overlay(config, kb, display_fbuf=tft)
beep = beeper.Beeper()

sd = None

# copied_file = None
clipboard = None

def mount_sd():
global sd
# sd needs to be mounted for any files in /sd
Expand Down Expand Up @@ -188,47 +191,92 @@ def parse_files():
def ext_options(overlay):
"""Create popup with options for new file or directory."""
cwd = os.getcwd()
option = overlay.popup_options(("New Directory", "New File", "Refresh"), title=f"{cwd}:")

options = ["Paste", "New Directory", "New File", "Refresh", "Exit to launcher"]

if clipboard == None:
# dont give the paste option if there's nothing to paste.
options.pop(0)

option = overlay.popup_options(options, title=f"{cwd}:")
if option == "New Directory":
play_sound(("D3"), 30)
name = overlay.text_entry(title="Directory name:", blackout_bg=True)
play_sound(("G3"), 30)
try:
os.mkdir(name)
except Exception as e:
overlay.error(e)

elif option == "New File":
play_sound(("B3"), 30)
name = overlay.text_entry(title="File name:", blackout_bg=True)
play_sound(("G3"), 30)
try:
with open(name, "w") as newfile:
newfile.write("")
except Exception as e:
overlay.error(e)

elif option == "Refresh":
os.sync()
play_sound(("B3","G3","D3"), 30)
mount_sd()
os.sync()

elif option == "Paste":
play_sound(("D3","G3","D3"), 30)

source_path, file_name = clipboard

source = f"{source_path}/{file_name}".replace('//','/')
dest = f"{cwd}/{file_name}".replace('//','/')

with open(source,"rb") as old_file:
with open(dest, "wb") as new_file:
while True:
l = old_file.read(512)
if not l: break
new_file.write(l)

elif option == "Exit to launcher":
overlay.draw_textbox("Exiting...", _DISPLAY_WIDTH//2, _DISPLAY_HEIGHT//2)
tft.show()
rtc = machine.RTC()
rtc.memory('')
machine.reset()

def file_options(file, overlay):
"""Create popup with file options for given file."""
global clipboard

options = ("open", "copy", "rename", "delete")
option = overlay.popup_options(options, title=f'"{file}":')

if option == "open":
play_sound(("G3"), 30)
open_file(file)
elif option == "copy":
new_name = overlay.text_entry(start_value=file, title=f"Rename '{file}':", blackout_bg=True)
with open(file,"rb") as source:
with open(new_name, "wb") as dest:
while True:
l = source.read(512)
if not l: break
dest.write(l)
# store copied file to clipboard
clipboard = (os.getcwd(), file)
# new_name = overlay.text_entry(start_value=file, title=f"Rename '{file}':", blackout_bg=True)
play_sound(("D3","G3","D3"), 30)
# with open(file,"rb") as source:
# with open(new_name, "wb") as dest:
# while True:
# l = source.read(512)
# if not l: break
# dest.write(l)

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

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


Expand All @@ -254,6 +302,10 @@ def open_file(file):
rtc.memory(full_path)
time.sleep_ms(10)
machine.reset()

def play_sound(notes, time_ms=30):
if config['ui_sound']:
beep.play(notes, time_ms, config['volume'])

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

Expand All @@ -268,9 +320,12 @@ def main_loop(tft, kb, config, overlay):
for key in new_keys:
if key == ";":
view.up()
play_sound(("G3","B3"), 30)
elif key == ".":
view.down()
elif key == "ENT" or key == "GO":
play_sound(("D3","B3"), 30)
elif key == "ENT" or key == "SPC":
play_sound(("G3","B3","D3"), 30)
selection_name = file_list[view.cursor_index]
if selection_name == "/.../": # new file
ext_options(overlay)
Expand All @@ -296,16 +351,24 @@ def main_loop(tft, kb, config, overlay):
view.clamp_cursor()

elif key == "BSPC" or key == "`":
# previous directory
if os.getcwd() == "/sd":
os.chdir("/")
else:
os.chdir("..")
play_sound(("D3","B3","G3"), 30)
# previous directory
if os.getcwd() == "/sd":
os.chdir("/")
else:
os.chdir("..")
file_list, dir_dict = parse_files()
view.items = file_list
view.dir_dict = dir_dict
view.cursor_index = 0
view.view_index = 0

elif key == "GO":
ext_options(overlay)
file_list, dir_dict = parse_files()
view.items = file_list
view.dir_dict = dir_dict
view.cursor_index = 0
view.view_index = 0
view.clamp_cursor()

view.draw()
tft.show()
Expand Down
82 changes: 0 additions & 82 deletions ports/esp32/boards/MICROHYDRA/launcher/icons/icons.py

This file was deleted.

Loading

0 comments on commit 0efe996

Please sign in to comment.