Skip to content

Commit bda0776

Browse files
authored
Merge pull request #2 from FunPythonEC/uPyIDEToga
correcion de errores (testeado)
2 parents 0a16c83 + 9e2eb67 commit bda0776

File tree

5 files changed

+44
-41
lines changed

5 files changed

+44
-41
lines changed

__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from uPyIDE.app import main
1+
from uPy_IDE.app import main
22

33
if __name__ == '__main__':
44
main().main_loop()

app.py

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import glob
77
import serial
88
import time
9-
from uPyIDE import esptool
9+
import uPy_IDE.esptool as esptool
1010

1111
def 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:

cli.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
if config:
3636
dotenv.load_dotenv(dotenv_path=config)
3737

38-
import files as files
39-
import pyboard as pyboard
38+
import uPy_IDE.files as files
39+
import uPy_IDE.pyboard as pyboard
4040

4141

4242
_board = None
@@ -194,11 +194,7 @@ def ls(directory, long_format, recursive):
194194
for f in board_files.ls(directory, long_format=long_format, recursive=recursive):
195195
print(f)
196196

197-
198-
@cli.command()
199-
@click.argument("local", type=click.Path(exists=True))
200-
@click.argument("remote", required=False)
201-
def put(local, remote):
197+
def put(local, remote=None, board=None):
202198
"""Put a file or folder and its contents on the board.
203199
204200
Put will upload a local file or folder to the board. If the file already
@@ -237,7 +233,7 @@ def put(local, remote):
237233
if os.path.isdir(local):
238234
# Directory copy, create the directory and walk all children to copy
239235
# over the files.
240-
board_files = files.Files(_board)
236+
board_files = files.Files(board)
241237
for parent, child_dirs, child_files in os.walk(local):
242238
# Create board filesystem absolute path to parent directory.
243239
remote_parent = posixpath.normpath(
@@ -259,7 +255,7 @@ def put(local, remote):
259255
# File copy, open the file and copy its contents to the board.
260256
# Put the file on the board.
261257
with open(local, "rb") as infile:
262-
board_files = files.Files(_board)
258+
board_files = files.Files(board)
263259
board_files.put(remote, infile.read())
264260

265261

esptool.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2609,7 +2609,6 @@ def add_spi_flash_subparsers(parent, is_elf2image):
26092609
expand_file_arguments()
26102610

26112611
args = parser.parse_args(custom_commandline)
2612-
26132612
print('esptool.py v%s' % __version__)
26142613

26152614
# operation function can take 1 arg (args), 2 args (esp, arg)

files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import ast
2323
import textwrap
2424

25-
from pyboard import PyboardError
25+
from uPy_IDE.pyboard import PyboardError
2626

2727

2828
BUFFER_SIZE = 32 # Amount of data to read or write to the serial port at a time.

0 commit comments

Comments
 (0)