66import glob
77import serial
88import time
9- from uPyIDE import esptool
9+ import uPy_IDE . esptool as esptool
1010
1111def serial_ports ():
1212 if sys .platform .startswith ('win' ):
@@ -35,55 +35,65 @@ def startup(self):
3535 self .main_window = toga .MainWindow (title = self .name ,size = (640 ,400 ))
3636
3737 label_style = Pack (flex = 1 ,padding_right = 24 )
38- box_style = Pack (direction = ROW ,padding = 10 )
38+ box_style_horiz = Pack (direction = ROW ,padding = 15 )
39+ box_style_verti = Pack (direction = COLUMN ,padding = 15 )
3940
41+ #selections
4042 self .portselect = toga .Selection (items = serial_ports ())
4143 self .chipselect = toga .Selection (items = ["ESP8266" ,"ESP32" ], on_select = self .update_selections )
4244 self .verselect = toga .Selection (items = ["v1.8.7" ,"v1.9.0" ,"v1.9.1" ,"v1.9.2" ,"v1.9.3" ,"v1.9.4" ,"v1.10.0" ])
4345
44- self .filelabel = toga .Label ("No ha seleccionado ningun archivo" )
46+ #switchs
47+ self .switchdio = toga .Switch ('DIO' , is_on = False , style = Pack (padding_left = 10 ,padding_top = 5 ))
48+
49+ self .filelabel = toga .Label ("No ha seleccionado ningun archivo" , style = Pack (padding = 2 ))
4550 self .fname = None
4651 self .main_window .content = toga .Box (
4752 children = [
48-
49- toga .Box (style = box_style , children = [
50- self .portselect ,
51- self .chipselect ,
52- self .verselect
53+ toga .Box (style = box_style_verti , children = [
54+
55+ toga .Box (style = Pack (direction = ROW ,padding_left = 25 ), children = [
56+ self .portselect ,
57+ self .chipselect ,
58+ self .verselect ,
59+ self .switchdio
60+ ]),
61+
62+ toga .Box (style = Pack (direction = COLUMN ,padding_top = 7 ), children = [
63+ toga .Button ("Seleccionar archivo" , on_press = self .action_open_file_dialog , style = Pack (padding_top = 15 ,padding_left = 2 )),
64+ self .filelabel ,
65+ toga .Button ("Grabar archivo en ESP" , on_press = self .save_to_esp , style = Pack (padding = 2 ))
66+ ])
5367 ]),
54-
55- toga .Box (style = box_style , children = [
68+ toga .Box (style = box_style_verti , children = [
5669 toga .Button ("Flashear" ,on_press = self .flash ),
5770 toga .Button ("Borrar flash/firmware" ,on_press = self .eraseflash ),
5871 toga .Button ("Actualizar puertos" ,on_press = self .update_ports )
59- ]),
60-
61- toga .Box (style = box_style , children = [
62- toga .Button ("Seleccionar archivo" ,on_press = self .action_open_file_dialog ),
63- self .filelabel ,
64- toga .Button ("Grabar archivo en ESP" , on_press = self .save_esp )
6572 ])
6673 ])
74+
6775 self .main_window .show ()
6876
6977
70- def save_esp (self , button ):
71- command = "python3.6 cli.py -p " + self .portselect .value + " put " + fname
72- os .system (command )
78+ def save_to_esp (self , button ):
79+ from uPy_IDE .pyboard import Pyboard
80+ from uPy_IDE import cli
81+ eboard = Pyboard (self .portselect .value )
82+ cli .put (self .fname ,board = eboard )
7383
7484
7585 def flash (self ,button ):
76- import os
7786 port = self .portselect .value
7887 chip = self .chipselect .value
7988 ver = self .verselect .value
8089
8190 if chip == "ESP32" :
82- command = 'python3.6 esptool.py --chip esp32 --port ' + port + ' write_flash -z 0x1000 esp32/' + ver + '.bin'
83- os .system (command )
91+ esptool .main (["--chip" ,"esp32" ,"--port" ,self .portselect .value ,"write_flash" ,"-z" ,"0x1000" ,"esp32/" + ver + '.bin' ])
8492 elif chip == "ESP8266" :
85- command = 'python3.6 esptool.py --port ' + port + ' --baud 460800 write_flash --flash_size=detect 0 esp8266/' + ver + '.bin'
86- os .system (command )
93+ if self .switchdio .get_is_on :
94+ esptool .main (["--port" ,self .portselect .value ,"--baud" ,"460800" ,"write_flash" ,"--flash_size=detect" ,"0" ,"uPy_IDE/esp8266/" + ver + '.bin' ])
95+ else :
96+ esptool .main (["--port" ,self .portselect .value ,"--baud" ,"460800" ,"write_flash" ,"--flash_size=detect" ,"-fm" ,"dio" ,"0" ,"uPy_IDE/esp8266/" + ver + '.bin' ])
8797
8898 def update_ports (self , button ):
8999 portlist = serial_ports ()
@@ -104,15 +114,13 @@ def update_selections(self,button):
104114
105115
106116 def eraseflash (self ,button ):
107- import os
117+
108118 port = self .portselect .value
109119 chip = self .chipselect .value
110120 if chip == 'ESP32' :
111- command = 'python3.6 esptool.py --chip esp32 erase_flash'
112- os .system (command )
121+ esptool .main (["-p" ,self .portselect .value ,"erase_flash" ])
113122 elif chip == 'ESP8266' :
114- command = 'python3.6 esptool.py --port ' + port + ' erase_flash'
115- os .system (command )
123+ esptool .main (["-p" ,self .portselect .value ,"erase_flash" ])
116124
117125 def action_open_file_dialog (self , widget ):
118126 try :
0 commit comments