@@ -43,18 +43,27 @@ def startup(self):
43
43
self .chipselect = toga .Selection (items = ["ESP8266" ,"ESP32" ], on_select = self .update_selections )
44
44
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" ])
45
45
46
+ #puerto
47
+ self .port = None
48
+ self .port_open = False
49
+
46
50
#switchs
47
51
self .switchdio = toga .Switch ('DIO' , is_on = False , style = Pack (padding_left = 10 ,padding_top = 5 ))
48
52
49
53
#textinputs
50
54
self .textfile = toga .TextInput (style = Pack (flex = 1 ,width = 200 ))
55
+ self .commandesp = toga .TextInput (style = Pack (flex = 1 ,width = 450 ))
51
56
52
57
#intento de terminal
53
58
self .textterminal = toga .MultilineTextInput (readonly = False ,style = Pack (flex = 1 ,width = 600 ,height = 600 ))
54
59
55
60
#textoutputs
56
61
self .textoutputs = toga .MultilineTextInput (readonly = True ,style = Pack (flex = 1 ,width = 200 ,height = 200 ))
57
62
63
+ #botones
64
+ self .btnport = toga .Button ("Abrir puerto" , on_press = self .open_port , style = Pack (padding = 2 ))
65
+
66
+
58
67
self .filelabel = toga .Label ("No ha seleccionado ningun archivo" , style = Pack (padding = 2 ))
59
68
self .fname = None
60
69
self .main_window .content = toga .Box (
@@ -80,12 +89,20 @@ def startup(self):
80
89
self .textoutputs
81
90
])
82
91
]),
83
- toga .Box (style = box_style_verti , children =
84
- [ toga .Button ("Flashear" ,on_press = self .flash ),
92
+ toga .Box (style = box_style_verti , children = [
93
+ toga .Button ("Flashear" ,on_press = self .flash ),
85
94
toga .Button ("Borrar flash/firmware" ,on_press = self .eraseflash ),
86
95
toga .Button ("Actualizar puertos" ,on_press = self .update_ports ),
87
- self .textterminal
96
+ self .btnport ,
97
+ self .textterminal ,
98
+
99
+ toga .Box (style = Pack (direction = ROW ,padding_top = 7 ), children = [
100
+ self .commandesp ,
101
+ toga .Button ("Enviar comando" , on_press = self .send_command , style = Pack (padding = 2 ))
102
+ ])
103
+
88
104
])
105
+
89
106
])
90
107
91
108
self .main_window .show ()
@@ -145,7 +162,28 @@ def get_file_esp(self,button):
145
162
self .textterminal .clear ()
146
163
self .textterminal .value = fdata
147
164
148
-
165
+ #======================================SOLO MANEJO DE PUERTO========================================================
166
+
167
+ def open_port (self ,button ):
168
+ from uPy_IDE .pyboard import Pyboard
169
+ if not self .port_open :
170
+ self .btnport .label = "Cerrar puerto"
171
+ self .port_open = True
172
+ self .textterminal .clear ()
173
+ self .port = Pyboard (self .portselect .value )
174
+ self .port .enter_raw_repl ()
175
+ read_port (self .port , self .port_open )
176
+ else :
177
+ self .btnport .label = "Abrir puerto"
178
+ self .port_open = False
179
+ self .port .exit_raw_repl ()
180
+
181
+ def send_command (self ,button ):
182
+ if self .port_open :
183
+ print (self .commandesp .value )
184
+ self .port .send (self .commandesp .value )
185
+
186
+ #===================================================================================================================
149
187
#metodos para la parte de esptool
150
188
def flash (self ,button ):
151
189
port = self .portselect .value
@@ -187,5 +225,16 @@ def eraseflash(self,button):
187
225
elif chip == 'ESP8266' :
188
226
esptool .main (["-p" ,self .portselect .value ,"erase_flash" ])
189
227
228
+ def read_port_thread (port ,port_status ):
229
+ while True :
230
+ if port_status :
231
+ ans = port .read_until (1 , b'\x04 ' , timeout = 10 , data_consumer = None )
232
+ print (ans )
233
+
234
+ def read_port (port , portstatus ):
235
+ import threading
236
+ runportthread = threading .Thread (target = read_port_thread , args = (port , portstatus ))
237
+ runportthread .start ()
238
+
190
239
def main ():
191
240
return uPyIDE ("uPyIDE" ,"org.funpython.upyide" )
0 commit comments