-
Notifications
You must be signed in to change notification settings - Fork 0
/
boot.py
73 lines (61 loc) · 1.94 KB
/
boot.py
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
import os
os.chdir('/system')
import machine
import time
import st7789
from sound import playsound
import network
from micropython import const
import sys
import random
import vga1_8x8 as font
import vga1_bold_16x32 as fontlarge
import urequests as requests
import _thread as thread
import sdcard
execfile('appRefresh.py')
xa = machine.ADC(machine.Pin(36))
ya = machine.ADC(machine.Pin(39))
btn = machine.Pin(32, machine.Pin.IN, machine.Pin.PULL_UP)
sc = machine.Pin(22, machine.Pin.OUT)
sc.on()
xa.atten(xa.ATTN_11DB)
ya.atten(ya.ATTN_11DB)
minval = const(500)
maxval = const(2500)
upamount = 40
spi = machine.SPI(1, baudrate=40000000, polarity=1)
display = st7789.ST7789(spi, 240, 240, reset=machine.Pin(27, machine.Pin.OUT), dc=machine.Pin(26, machine.Pin.OUT), backlight=sc)
display.init()
os.chdir('/')
try:
sdspi=machine.SoftSPI(-1, sck=machine.Pin(18), mosi=machine.Pin(23), miso=machine.Pin(19))
sd = sdcard.SDCard(sdspi, machine.Pin(5))
os.mount(sd, '/sd')
print('SD card mounted.')
except Exception as e:
print('No SD card present.')
LOGGING = True
LOGFILENAME = ''
def log(text):
if LOGGING:
logfile=open('/sd/.logs/'+LOGFILENAME+'.log', 'a')
logfile.write('\n')
logfile.write(str(time.localtime()[3])+':'+str(time.localtime()[4])+':'+str(time.localtime()[5])+': '+str(text))
logfile.close()
else:
print(str(time.localtime()[3])+':'+str(time.localtime()[4])+': '+str(text))
if btn.value() == 0:
try:
logs=os.listdir('/sd/.logs')
logs.reverse()
try:
LOGFILENAME='log_'+str(int(logs[0].strip('log_').strip('.'))+1)
except:
LOGFILENAME='log_0'
except:
LOGGING = False
try:
execfile('/system/microOS.py')
except Exception as e:
log('An error ocurred 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.')