Skip to content

Commit

Permalink
[for ftp]
Browse files Browse the repository at this point in the history
  • Loading branch information
junhuanchen committed Jan 25, 2024
1 parent 23d09fb commit b5f50c4
Show file tree
Hide file tree
Showing 6 changed files with 358 additions and 306 deletions.
277 changes: 140 additions & 137 deletions components/micropython/port/builtin_py/_boot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,153 +3,156 @@
sys.path.append('')
sys.path.append('.')

# chdir to "/sd" or "/flash"
devices = os.listdir("/")
if "sd" in devices:
os.chdir("/sd")
sys.path.append('/sd')
else:
os.chdir("/flash")
os.chdir("/flash")
sys.path.append('/flash')
del devices

print("[MaixPy] init end") # for IDE
for i in range(200):
time.sleep_ms(1) # wait for key interrupt(for maixpy ide)
del i
# chdir to "/sd" or "/flash"
# devices = os.listdir("/")
# if "sd" in devices:
# os.chdir("/sd")
# sys.path.append('/sd')
# else:
# os.chdir("/flash")
# sys.path.append('/flash')
# del devices

# print("[MaixPy] init end") # for IDE
# for i in range(200):
# time.sleep_ms(1) # wait for key interrupt(for maixpy ide)
# del i

# check IDE mode
ide_mode_conf = "/flash/ide_mode.conf"
ide = True
try:
f = open(ide_mode_conf)
f.close()
del f
except Exception:
ide = False
# # check IDE mode
# ide_mode_conf = "/flash/ide_mode.conf"
# ide = True
# try:
# f = open(ide_mode_conf)
# f.close()
# del f
# except Exception:
# ide = False

if ide:
os.remove(ide_mode_conf)
from machine import UART
import lcd
lcd.init(color=lcd.PINK)
repl = UART.repl_uart()
repl.init(1500000, 8, None, 1, read_buf_len=2048, ide=True, from_ide=False)
sys.exit()
del ide, ide_mode_conf
# if ide:
# os.remove(ide_mode_conf)
# from machine import UART
# import lcd
# lcd.init(color=lcd.PINK)
# repl = UART.repl_uart()
# repl.init(1500000, 8, None, 1, read_buf_len=2048, ide=True, from_ide=False)
# sys.exit()
# del ide, ide_mode_conf

# detect boot.py
main_py = '''
try:
import gc, lcd, image, sys, os
from Maix import GPIO
from fpioa_manager import fm
test_pin=16
fm.fpioa.set_function(test_pin,fm.fpioa.GPIO7)
test_gpio=GPIO(GPIO.GPIO7,GPIO.IN,GPIO.PULL_UP)
fm.fpioa.set_function(17,fm.fpioa.GPIO0)
lcd_en = GPIO(GPIO.GPIO0,GPIO.OUT)
lcd_en.value(0)
lcd.init()
lcd.clear(color=(255,0,0))
lcd.draw_string(lcd.width()//2-68,lcd.height()//2-4, "Welcome to ", lcd.WHITE, lcd.RED)
if test_gpio.value() == 0:
print('PIN 16 pulled down, enter test mode')
lcd.clear(lcd.PINK)
lcd.draw_string(lcd.width()//2-68,lcd.height()//2-4, "Test Mode, wait ...", lcd.WHITE, lcd.PINK)
import sensor
import image
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.run(1)
lcd.freq(16000000)
while True:
img=sensor.snapshot()
lcd.display(img)
# # detect boot.py
# main_py = '''
# try:
# import gc, lcd, image, sys, os
# from Maix import GPIO
# from fpioa_manager import fm
# test_pin=16
# fm.fpioa.set_function(test_pin,fm.fpioa.GPIO7)
# test_gpio=GPIO(GPIO.GPIO7,GPIO.IN,GPIO.PULL_UP)
# fm.fpioa.set_function(17,fm.fpioa.GPIO0)
# lcd_en = GPIO(GPIO.GPIO0,GPIO.OUT)
# lcd_en.value(0)
# lcd.init()
# lcd.clear(color=(255,0,0))
# lcd.draw_string(lcd.width()//2-68,lcd.height()//2-4, "Welcome to ", lcd.WHITE, lcd.RED)
# if test_gpio.value() == 0:
# print('PIN 16 pulled down, enter test mode')
# lcd.clear(lcd.PINK)
# lcd.draw_string(lcd.width()//2-68,lcd.height()//2-4, "Test Mode, wait ...", lcd.WHITE, lcd.PINK)
# import sensor
# import image
# sensor.reset()
# sensor.set_pixformat(sensor.RGB565)
# sensor.set_framesize(sensor.QVGA)
# sensor.run(1)
# lcd.freq(16000000)
# while True:
# img=sensor.snapshot()
# lcd.display(img)

loading = image.Image(size=(lcd.width(), lcd.height()))
loading.draw_rectangle((0, 0, lcd.width(), lcd.height()), fill=True, color=(255, 0, 0))
info = "Welcome to MaixPy"
loading.draw_string(int(lcd.width()//2 - len(info) * 5), (lcd.height())//4, info, color=(255, 255, 255), scale=2, mono_space=0)
v = sys.implementation.version
vers = 'V{}.{}.{} : maixpy.sipeed.com'.format(v[0],v[1],v[2])
loading.draw_string(int(lcd.width()//2 - len(info) * 6), (lcd.height())//3 + 20, vers, color=(255, 255, 255), scale=1, mono_space=1)
lcd.display(loading)
tf = None
try:
os.listdir("/sd/.")
except Exception as e:
tf ="SDcard not mount,use flash!"
loading.draw_string(int(lcd.width()//2 - len(info) * 7), (lcd.height())//2 + 10, tf, color=(255, 255, 255), scale=1, mono_space=1)
if not tf:
tf ="SDcard is mount,use SD!"
loading.draw_string(int(lcd.width()//2 - len(info) * 6), (lcd.height())//2 + 10, tf, color=(255, 255, 255), scale=1, mono_space=1)
lcd.display(loading)
del loading, v, info, vers
gc.collect()
finally:
gc.collect()
'''
# loading = image.Image(size=(lcd.width(), lcd.height()))
# loading.draw_rectangle((0, 0, lcd.width(), lcd.height()), fill=True, color=(255, 0, 0))
# info = "Welcome to MaixPy"
# loading.draw_string(int(lcd.width()//2 - len(info) * 5), (lcd.height())//4, info, color=(255, 255, 255), scale=2, mono_space=0)
# v = sys.implementation.version
# vers = 'V{}.{}.{} : maixpy.sipeed.com'.format(v[0],v[1],v[2])
# loading.draw_string(int(lcd.width()//2 - len(info) * 6), (lcd.height())//3 + 20, vers, color=(255, 255, 255), scale=1, mono_space=1)
# lcd.display(loading)
# tf = None
# try:
# os.listdir("/sd/.")
# except Exception as e:
# tf ="SDcard not mount,use flash!"
# loading.draw_string(int(lcd.width()//2 - len(info) * 7), (lcd.height())//2 + 10, tf, color=(255, 255, 255), scale=1, mono_space=1)
# if not tf:
# tf ="SDcard is mount,use SD!"
# loading.draw_string(int(lcd.width()//2 - len(info) * 6), (lcd.height())//2 + 10, tf, color=(255, 255, 255), scale=1, mono_space=1)
# lcd.display(loading)
# del loading, v, info, vers
# gc.collect()
# finally:
# gc.collect()
# '''

flash_ls = os.listdir()
if not "main.py" in flash_ls:
f = open("main.py", "wb")
f.write(main_py)
f.close()
del f
del main_py
# flash_ls = os.listdir()
# if not "main.py" in flash_ls:
# f = open("main.py", "wb")
# f.write(main_py)
# f.close()
# del f
# del main_py

flash_ls = os.listdir("/flash")
try:
sd_ls = os.listdir("/sd")
except Exception:
sd_ls = []
if "cover.boot.py" in sd_ls:
code0 = ""
if "boot.py" in flash_ls:
with open("/flash/boot.py") as f:
code0 = f.read()
with open("/sd/cover.boot.py") as f:
code=f.read()
if code0 != code:
with open("/flash/boot.py", "w") as f:
f.write(code)
import machine
machine.reset()
# flash_ls = os.listdir("/flash")
# try:
# sd_ls = os.listdir("/sd")
# except Exception:
# sd_ls = []
# if "cover.boot.py" in sd_ls:
# code0 = ""
# if "boot.py" in flash_ls:
# with open("/flash/boot.py") as f:
# code0 = f.read()
# with open("/sd/cover.boot.py") as f:
# code=f.read()
# if code0 != code:
# with open("/flash/boot.py", "w") as f:
# f.write(code)
# import machine
# machine.reset()

if "cover.main.py" in sd_ls:
code0 = ""
if "main.py" in flash_ls:
with open("/flash/main.py") as f:
code0 = f.read()
with open("/sd/cover.main.py") as f:
code = f.read()
if code0 != code:
with open("/flash/main.py", "w") as f:
f.write(code)
import machine
machine.reset()
# if "cover.main.py" in sd_ls:
# code0 = ""
# if "main.py" in flash_ls:
# with open("/flash/main.py") as f:
# code0 = f.read()
# with open("/sd/cover.main.py") as f:
# code = f.read()
# if code0 != code:
# with open("/flash/main.py", "w") as f:
# f.write(code)
# import machine
# machine.reset()

try:
del flash_ls
del sd_ls
del code0
del code
except Exception:
pass
# try:
# del flash_ls
# del sd_ls
# del code0
# del code
# except Exception:
# pass

banner = '''
__ __ _____ __ __ _____ __ __
| \/ | /\ |_ _| \ \ / / | __ \ \ \ / /
| \ / | / \ | | \ V / | |__) | \ \_/ /
| |\/| | / /\ \ | | > < | ___/ \ /
| | | | / ____ \ _| |_ / . \ | | | |
|_| |_| /_/ \_\ |_____| /_/ \_\ |_| |_|
# banner = '''
# __ __ _____ __ __ _____ __ __
# | \/ | /\ |_ _| \ \ / / | __ \ \ \ / /
# | \ / | / \ | | \ V / | |__) | \ \_/ /
# | |\/| | / /\ \ | | > < | ___/ \ /
# | | | | / ____ \ _| |_ / . \ | | | |
# |_| |_| /_/ \_\ |_____| /_/ \_\ |_| |_|

Official Site : https://www.sipeed.com
Wiki : https://maixpy.sipeed.com
'''
print(banner)
del banner
# Official Site : https://www.sipeed.com
# Wiki : https://maixpy.sipeed.com
# '''
# print(banner)
# del banner

Loading

0 comments on commit b5f50c4

Please sign in to comment.