52 lines
1.8 KiB
Python
Executable File
52 lines
1.8 KiB
Python
Executable File
import lvgl as lv
|
|
import espidf as esp
|
|
import os,machine,sdcard
|
|
import json
|
|
import time
|
|
|
|
DEVICE_MAX_WIDTH = 240
|
|
DEVICE_MAX_HEIGHT = 320
|
|
#Initialise hardware
|
|
lv.init()
|
|
from ili9XXX import ili9341
|
|
disp = ili9341(dc=21, miso=19, mosi=23, cs=5, clk=18, factor=16, double_buffer=True)
|
|
from xpt2046 import xpt2046
|
|
touch = xpt2046(cs=27, cal_x0=242, cal_x1=3300, cal_y0=3850, cal_y1=423)
|
|
sd = sdcard.SDCard(machine.SoftSPI(sck=machine.Pin(13),miso=machine.Pin(14),mosi=machine.Pin(15)), machine.Pin(25))
|
|
os.mount(sd,'/sd')
|
|
user_settings = {}
|
|
with open('sd/appdata/settings/settings.json') as json_file:
|
|
user_settings = json.load(json_file)
|
|
current_datetime = time.gmtime(int(user_settings["time"]))
|
|
rtc = machine.RTC()
|
|
rtc.datetime(current_datetime)
|
|
print(rtc.datetime())
|
|
#Launcher application
|
|
class Launcher():
|
|
def __init__(self):
|
|
self.objects = []
|
|
apps = ""
|
|
applist = os.listdir("/sd/apps")
|
|
print(applist[0]);
|
|
prev_btn_y = 0
|
|
scr = lv.scr_act()
|
|
for app in applist:
|
|
btn = lv.btn(lv.scr_act())
|
|
btn.align_to(lv.scr_act(), lv.ALIGN.TOP_LEFT, 0, prev_btn_y)
|
|
btn.add_event_cb(self.event_cb, lv.EVENT.CLICKED, None)
|
|
prev_btn_y += 40
|
|
label = lv.label(btn)
|
|
label.set_text(app)
|
|
self.objects.append(btn)
|
|
def event_cb(self, e):
|
|
self.btn = e.get_target()
|
|
label = self.btn.get_child(0)
|
|
print("Executing " + label.get_text())
|
|
exec(open("/sd/apps/"+ label.get_text()).read(), {'lv':lv, 'launcher': self, 'os':os, 'json':json, 'time':time, 'rtc':rtc, 'DEVICE_MAX_WIDTH':DEVICE_MAX_WIDTH, 'DEVICE_MAX_HEIGHT': DEVICE_MAX_HEIGHT}, {})
|
|
|
|
def destroy(self):
|
|
print("destroying launcher")
|
|
for obj in self.objects:
|
|
obj.delete()
|
|
launcher = Launcher()
|