-
Notifications
You must be signed in to change notification settings - Fork 8
/
emp_boot.py
76 lines (62 loc) · 2.21 KB
/
emp_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
74
75
76
from emp_utils import rainbow
from emp_utils import print_as_a_list_item
from emp_utils import selection
from emp_utils import _const
from emp_utils import config_path
import os
import machine
BOOT_MODE = _const()
BOOT_MODE.WITH_NOTHING = 0
BOOT_MODE.WITH_WIFI_STARTUP = 1
BOOT_MODE.EASY_DEVELOP = 2
BOOT_MODE.WITH_WIFI_STARTUP_CODE = '''from emp_wifi import Wifi
if __name__ == '__main__':
Wifi.connect()'''
BOOT_MODE.EASY_DEVELOP_CODE = '''from emp_wifi import Wifi
from emp_webrepl import WebREPL
from emp_utils import webrepl_pass
from emp_utils import post_ip
if __name__ == '__main__':
Wifi.connect()
try:
post_ip(Wifi.ifconfig()[0][0])
except ImportError:
pass
WebREPL.start(password=webrepl_pass())
from emp_ide import *'''
def reboot():
print(rainbow('Reboot', color='red'))
machine.reset()
def set_boot_mode():
print(
print_as_a_list_item(
0, 'Boot with nothing',
'attention: this option will clear up boot.py, careful!'))
print(
print_as_a_list_item(
1, 'Boot with wifi startup',
'this mode will auto start wifi connect program.'))
print(
print_as_a_list_item(
2, 'Easy to develop',
'this mode is for developers.In this mode you can develop much easier via EMP-IDE(emp.1zlab.com)'
))
mode = selection('Please input your choice [0-2]: ', 2)
with open('boot.py', 'w') as f:
if mode == BOOT_MODE.WITH_NOTHING:
boot_code = ''
f.write(boot_code)
print(rainbow('Boot mode set to WITH_NOTHING', color='green'))
elif mode == BOOT_MODE.WITH_WIFI_STARTUP:
boot_code = BOOT_MODE.WITH_WIFI_STARTUP_CODE
f.write(boot_code)
print(rainbow('Boot mode set to WITH_WIFI_STARTUP', color='green'))
elif mode == BOOT_MODE.EASY_DEVELOP:
config_path()
if not 'webrepl.pass' in os.listdir('config'):
with open('config/webrepl.pass', 'w') as c:
c.write('1zlab')
boot_code = BOOT_MODE.EASY_DEVELOP_CODE
f.write(boot_code)
print(rainbow('Boot mode set to EASY_DEVELOP', color='green'))
reboot()