Skip to content

Commit bc9df03

Browse files
authored
This commit is partialy functional. I think there are some files that are probably missing. This is a very significant update so expect things to look very different.
Known issues: - GUI freezes when searching for a network. - Timezone set interface is very basic and probably not functional for now. - Set volume doesn't work yet - App store doesn't work yet other than the No WiFi connection page. And probably more! This was just a first significant update with LVGL. I do still need to make an installer but since the file structure is constantly changing, and there are potential other files that may need to be added, I may wait until the project is more stable.
1 parent b2c4dc3 commit bc9df03

22 files changed

+1259
-826
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
## MicroOS
22

3-
Our attempt at creating an operating system like program for the [LilyGo T-Deck](https://lilygo.cc/products/t-deck) (Only that board officialy supported for now but we will add more soon).
3+
Our attempt at creating an operating system like program for the [LilyGo T-Deck](https://lilygo.cc/products/t-deck) (Only that board officialy supported for now but we will add more soon and some may already work).
44

5-
We are currently working on switching to [LVGL](https://github.com/lvgl-micropython/lvgl_micropython) as our graphics driver so some of the commits we are going to be releasing will most likely be non-functional for a while.
5+
We are currently working on switching to [LVGL](https://github.com/lvgl-micropython/lvgl_micropython) as our graphics driver so some of the commits we are going to be releasing will most likely be non-functional or partialy functional for a while.

boot.py

Lines changed: 51 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,96 @@
1+
import lvgl as lv
12
import os
2-
os.chdir('/system')
33
import machine
44
import time
5-
from sound import playsound
65
import network
76
from micropython import const
87
import sys
98
import random
10-
import vga1_8x8 as font
11-
import vga1_bold_16x32 as fontlarge
129
import urequests as requests
13-
import _thread as thread
10+
import _thread as threading
1411
import json
1512
import random
1613
import string
14+
import ntptime
15+
import fs_driver
1716

18-
os.chdir('drivers')
17+
os.chdir('/system/drivers')
1918

2019
index=open('drivers.conf', 'r')
2120
conf = json.load(index)
2221

2322
LOADEDDRIVERS = []
2423
basedrivers = ['display', 'direction', 'storage', 'keyboard']
2524

25+
def loadDriver(key):
26+
if not conf[key] == None:
27+
execfile(conf[key])
28+
LOADEDDRIVERS.append(key)
29+
2630
# Load base drivers
2731
try:
28-
execfile(conf['display'])
29-
LOADEDDRIVERS.append('display')
30-
except:
31-
print('Could not initialize a driver for display.')
32+
loadDriver('direction')
33+
except Exception as e:
34+
print('Could not initialize a driver for directional control:\n'+str(e))
3235

3336
try:
34-
execfile(conf['direction'])
35-
LOADEDDRIVERS.append('direction')
36-
except:
37-
print('Could not initialize a driver for directional control.')
37+
loadDriver('storage')
38+
except Exception as e:
39+
print('Could not initialize a driver for external storage:\n'+str(e))
3840

3941
try:
40-
execfile(conf['storage'])
41-
LOADEDDRIVERS.append('storage')
42-
except:
43-
print('Could not initialize a driver for external storage.')
42+
loadDriver('display')
43+
except Exception as e:
44+
print('Could not initialize driver for display:\n'+str(e))
4445

4546
try:
46-
execfile(conf['keyboard'])
47-
LOADEDDRIVERS.append('keyboard')
48-
except:
49-
print('Could not initialize driver for keyboard input')
47+
loadDriver('keyboard')
48+
except Exception as e:
49+
print('Could not initialize a driver for keyboard input:\n'+str(e))
5050

5151
# Load optional drivers
5252
for i in conf:
5353
if not i in basedrivers:
5454
if conf[i][0] == True:
55-
execfile(conf[i][1])
56-
LOADEDDRIVERS.append(i)
55+
try:
56+
execfile(conf[i][1])
57+
LOADEDDRIVERS.append(i)
58+
except Exception as e:
59+
print('Could not initialize the '+str(conf[i][0])+' driver:\n'+str(e))
5760

5861
print('Drivers initialized')
5962

6063
os.chdir('/')
6164

62-
execfile('system/appRefresh.py')
65+
# Register filesystem for importing fonts
66+
fs_drv = lv.fs_drv_t()
67+
68+
fs_driver.fs_register(fs_drv, 'D')
69+
70+
# Define function for importing .bin fonts made by https://lvgl.io/tools/fontconverter
71+
def importfont(filename):
72+
return lv.binfont_create('D:'+filename)
73+
74+
font = importfont('/system/fonts/jetbrains_mono_8.bin')
75+
fontlarge = importfont('/system/fonts/jetbrains_mono_16.bin')
6376

6477
LOGGING = True
6578
LOGFILENAME = ''
79+
PRINTTRACES = True
6680

81+
# Define the loging function so that the OS can tell us if there is a problem
82+
# If a SD card is mounted, we write to a file, otherwise, simply print
6783
def log(text):
84+
text = str(time.localtime()[3])+':'+str(time.localtime()[4])+':'+str(time.localtime()[5])+': '+str(text)
6885
if LOGGING:
6986
logfile=open('/sd/.logs/'+LOGFILENAME+'.log', 'a')
7087
logfile.write('\n')
71-
logfile.write(str(time.localtime()[3])+':'+str(time.localtime()[4])+'.'+str(time.localtime()[5])+': '+str(text))
88+
logfile.write(text)
7289
logfile.close()
7390
else:
74-
print(str(time.localtime()[3])+':'+str(time.localtime()[4])+':'+str(time.localtime()[5])+': '+str(text))
91+
print(text)
7592

93+
# Only start the OS if the button is not pressed
7694
if not pressed():
7795
try:
7896
logs=os.listdir('/sd/.logs')
@@ -83,7 +101,10 @@ def log(text):
83101
LOGFILENAME='log_0'
84102
except:
85103
LOGGING = False
86-
try:
104+
if PRINTTRACES == True:
87105
execfile('/system/microOS.py')
88-
except Exception as e:
89-
log('An error occurred in the system.\nError:\n'+str(e)+'\nPlease refer to the instructions at https://github.com/asherevan/microOS/wiki/Reporting%E2%80%90bugs to report this bug.')
106+
else:
107+
try:
108+
execfile('/system/microOS.py')
109+
except Exception as e:
110+
log('An error occurred in the system.\nError:\n'+str(e)+'\nPlease refer to the instructions at https://github.com/MicroOS-Project/microOS/wiki/Reporting%E2%80%90bugs to report this bug.')

drivers/drivers.conf

Lines changed: 0 additions & 1 deletion
This file was deleted.

system/drivers/I2Saudio.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from i2saudio import TDeckAudioI2S
2+
3+
player = TDeckAudioI2S(0, pins={'sck': 7, 'ws': 5, 'sd': 6})
4+
5+
def playWav(filename, volume=0.5):
6+
player.reinitialize_i2s()
7+
player.play_wav(filename, volume=volume)

system/drivers/SDreader.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import sdcard
2+
3+
sdspi=machine.SoftSPI(-1, sck=machine.Pin(40), mosi=machine.Pin(41), miso=machine.Pin(38, machine.Pin.IN))
4+
sd = sdcard.SDCard(sdspi, machine.Pin(39))
5+
os.mount(sd, '/sd')
6+
print('SD card mounted.')

system/drivers/T-keyboard.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import machine
2+
from machine import Pin
3+
4+
_buf = bytearray(1)
5+
_mv = memoryview(_buf)
6+
7+
# i2c = machine.SoftI2C(scl=machine.Pin(8), sda=machine.Pin(18), freq=400000, timeout=50000)
8+
9+
time.sleep(.5)
10+
11+
def get_key():
12+
keyboard_device.read(buf=_mv)
13+
return chr(_buf[0])
14+
15+
def keyboard():
16+
display.fill(0)
17+
display.rect(20, 2, width-40, 15, st7789.WHITE)
18+
buffer = bytearray()
19+
while True:
20+
k = get_key()
21+
22+
if k != b'\x00':
23+
if k == b'\x08':
24+
buffer=buffer[:-1]
25+
print(buffer.decode())
26+
display.text(font, clear, 24, 5, st7789.BLACK)
27+
display.text(font, buffer.decode(), 25, 5, st7789.YELLOW)
28+
else:
29+
buffer += k
30+
print(buffer.decode())
31+
display.text(font, clear, 24, 5, st7789.BLACK)
32+
display.text(font, buffer.decode(), 25, 5, st7789.YELLOW)
33+
34+
if k == b'\r':
35+
return buffer.decode().strip('\r')

system/drivers/battery.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
bat = machine.ADC(machine.Pin(4))
2+
bat.width(machine.ADC.WIDTH_12BIT)
3+
bat.atten(machine.ADC.ATTN_11DB)
4+
5+
voltagefull = 3.91
6+
voltagecharging = 4.1
7+
8+
def readvoltage():
9+
return ((bat.read_u16() * 3.3) / 65535)/ (100/200)
10+
11+
def calcPercentage():
12+
voltage = readvoltage()
13+
diff = voltagefull-voltage
14+
if voltage >= voltagecharging:
15+
percent = 'CH'
16+
else:
17+
percent = str(100-round(diff/voltagefull*100))
18+
try:
19+
# Determines if the percentage is less than 10% and if so, log that the battery is low
20+
if int(percent) < 10:
21+
log('Battery is low! (Less than 10%)')
22+
except:
23+
# The percent is "CH" so it cannot convert to int and returns a error
24+
pass
25+
return percent

system/drivers/drivers.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"direction": "T-deck/trackball.py", "display": "T-deck/everything.py", "storage": null, "keyboard": null, "battery": [true, "T-deck/battery.py"], "audio": [true, "T-deck/I2Saudio.py"]}

system/drivers/everything.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
os.chdir('/')
2+
execfile('/display.py')
3+
os.chdir('/system/drivers')
4+
5+
width = 320
6+
height = 240

0 commit comments

Comments
 (0)