Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Migración a Toga, manejo de ampy #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
funcionamiento conjunto a ampy
  • Loading branch information
sasilva1998 committed Mar 28, 2019
commit b1e38b40ccdb326a725fdcc5c98c07359471cdd9
128 changes: 64 additions & 64 deletions 128 app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,28 @@
import sys
import glob
import serial
import time
from uPyIDE import esptool

def serial_ports():

if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
# this excludes your current terminal "/dev/tty"
ports = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
ports = glob.glob('/dev/tty.*')
else:
raise EnvironmentError('Unsupported platform')

result = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
result.append(port)
except:
pass
return result
if sys.platform.startswith('win'):
ports = ['COM%s' % (i + 1) for i in range(256)]
elif sys.platform.startswith('linux') or sys.platform.startswith('cygwin'):
ports = glob.glob('/dev/tty[A-Za-z]*')
elif sys.platform.startswith('darwin'):
ports = glob.glob('/dev/tty.*')
else:
raise EnvironmentError('Unsupported platform')

result = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
result.append(port)
except (OSError, serial.SerialException):
pass
return result

class uPyIDE(toga.App):

Expand All @@ -37,92 +37,92 @@ def startup(self):
label_style=Pack(flex=1,padding_right=24)
box_style=Pack(direction=ROW,padding=10)

global portselect
global chipselect
global verselect

portselect=toga.Selection(items=None, on_select=self.updateslct)
chipselect=toga.Selection(items=["ESP8266","ESP32"],on_select=self.updateslct)
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"])
self.portselect=toga.Selection(items=serial_ports())
self.chipselect=toga.Selection(items=["ESP8266","ESP32"], on_select=self.update_selections)
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"])

self.filelabel=toga.Label("No ha seleccionado ningun archivo")
self.fname=None
self.main_window.content=toga.Box(
children=[

toga.Box(style=box_style, children=[
portselect,
chipselect,
verselect
self.portselect,
self.chipselect,
self.verselect
]),

toga.Box(style=box_style, children=[
toga.Button("Flashear",on_press=self.flash),
toga.Button("Borrar flash/firmware",on_press=self.eraseflash),
toga.Button("Actualizar",on_press=self.updatebtn)
toga.Button("Actualizar puertos",on_press=self.update_ports)
]),

toga.Box(style=box_style, children=[
toga.Button("Seleccionar archivo",on_press=self.action_open_file_dialog),
self.filelabel,
toga.Button("Grabar archivo en ESP", on_press=self.save_esp)
])
])
self.main_window.show()


def save_esp(self, button):
command="python3.6 cli.py -p "+self.portselect.value+" put "+fname
os.system(command)


def flash(self,button):
import os
port=portselect.value
chip=chipselect.value
ver=verselect.value
port=self.portselect.value
chip=self.chipselect.value
ver=self.verselect.value

if chip == "ESP32":
command = 'esptool.py --chip esp32 --port '+port+' write_flash -z 0x1000 esp32/'+ver+'.bin'
command = 'python3.6 esptool.py --chip esp32 --port '+port+' write_flash -z 0x1000 esp32/'+ver+'.bin'
os.system(command)
elif chip == "ESP8266":
command = 'esptool.py --port '+port+' --baud 15200 write_flash --flash_size=detect 0 esp8266/'+ver+'.bin'
command = 'python3.6 esptool.py --port '+port+' --baud 460800 write_flash --flash_size=detect 0 esp8266/'+ver+'.bin'
os.system(command)

def updateslct(self, selection):
portlist = serial_ports()
micro=chipselect.value
if not portlist:
pass
else:
portselect.items(portlist)

if micro == "ESP32":
versionlist=["v1.9.4","v1.10"]
elif micro=="ESP8266":
versionlist=["v1.8.7","v1.9.0","v1.9.1","v1.9.2","v1.9.3","v1.9.4","v1.10.0"]
else:
pass
verselect.items(versionlist)

def updatebtn(self, button):
def update_ports(self, button):
portlist = serial_ports()
micro=chipselect.value
print(portlist)
if not portlist:
pass
else:
portselect.items(items=portlist)
self.portselect.items = portlist

def update_selections(self,button):
micro=self.chipselect.value
if micro == "ESP32":
versionlist=["v1.9.4","v1.10"]
elif micro=="ESP8266":
versionlist=["v1.8.7","v1.9.0","v1.9.1","v1.9.2","v1.9.3","v1.9.4","v1.10.0"]
else:
pass

verselect.items(items=versionlist)
self.verselect.items = versionlist


def eraseflash(self,button):
import os
port=portselect.value
chip=chipselect.value
port=self.portselect.value
chip=self.chipselect.value
if chip=='ESP32':
command='esptool.py --chip esp32 erase_flash'
command='python3.6 esptool.py --chip esp32 erase_flash'
os.system(command)
elif chip=='ESP8266':
command='esptool.py --port '+port+' erase_flash'
command='python3.6 esptool.py --port '+port+' erase_flash'
os.system(command)


def action_open_file_dialog(self, widget):
try:
self.fname = self.main_window.open_file_dialog(
title="Open file with Toga",
)
print(self.fname)
except ValueError:
print("ha ocurrido un error")
self.filelabel.text="Archivo seleccionado: "+self.fname.split("/")[-1]

def main():
return uPyIDE("uPyIDE","org.funpython.upyide")
return uPyIDE("uPyIDE","org.funpython.upyide")
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.