intermediate: ui first flash
This commit is contained in:
parent
a892d2cd94
commit
922fff40e6
|
@ -13,7 +13,7 @@ import builtins
|
|||
|
||||
oldprint=builtins.print
|
||||
def print(*args, **kwargs):
|
||||
app.addText(args[0],kwargs.get('end') == '')
|
||||
app.addText(*args,**kwargs)
|
||||
|
||||
|
||||
builtins.print=print
|
||||
|
@ -37,10 +37,10 @@ class App:
|
|||
row+=1
|
||||
self.mode=tk.IntVar()
|
||||
self.mode.set(1)
|
||||
btFrame=tk.Frame(frame)
|
||||
btFrame.grid(row=row,column=1,sticky="ew",pady=20)
|
||||
tk.Radiobutton(btFrame,text="Initial Flash",value=1,variable=self.mode,command=self.changeMode).grid(row=0,column=0)
|
||||
tk.Radiobutton(btFrame, text="Update Flash", value=2, variable=self.mode,command=self.changeMode).grid(row=0,column=1)
|
||||
rdFrame=tk.Frame(frame)
|
||||
rdFrame.grid(row=row,column=1,sticky="ew",pady=20)
|
||||
tk.Radiobutton(rdFrame,text="Initial Flash",value=1,variable=self.mode,command=self.changeMode).grid(row=0,column=0)
|
||||
tk.Radiobutton(rdFrame, text="Update Flash", value=2, variable=self.mode,command=self.changeMode).grid(row=0,column=1)
|
||||
row+=1
|
||||
tk.Label(frame, text="Com Port").grid(row=row,column=0,sticky='ew')
|
||||
self.port=ttk.Combobox(frame)
|
||||
|
@ -59,19 +59,30 @@ class App:
|
|||
self.flashInfo.set("Address 0x1000")
|
||||
tk.Label(frame,textvariable=self.flashInfo).grid(row=row,column=0,columnspan=2,sticky='ew',pady=10)
|
||||
row+=1
|
||||
tk.Button(frame,text="Flash",command=self.buttonAction).grid(row=row,column=0,columnspan=2,pady=10)
|
||||
btFrame=tk.Frame(frame)
|
||||
btFrame.grid(row=row,column=0,columnspan=2,pady=15)
|
||||
self.actionButtons=[]
|
||||
bt=tk.Button(btFrame,text="Check",command=self.buttonCheck)
|
||||
bt.grid(row=0,column=0)
|
||||
self.actionButtons.append(bt)
|
||||
bt=tk.Button(btFrame, text="Flash", command=self.buttonFlash)
|
||||
bt.grid(row=0, column=1)
|
||||
self.actionButtons.append(bt)
|
||||
self.cancelButton=tk.Button(btFrame,text="Cancel",state=tk.DISABLED,command=self.buttonCancel)
|
||||
self.cancelButton.grid(row=0,column=2)
|
||||
row+=1
|
||||
self.text_widget = tk.Text(frame)
|
||||
frame.rowconfigure(row,weight=1)
|
||||
self.text_widget.grid(row=row,column=0,columnspan=2,sticky='news')
|
||||
self.readDevices()
|
||||
self.interrupt=False
|
||||
|
||||
def updateFlashInfo(self):
|
||||
if self.mode.get() == 1:
|
||||
#full
|
||||
self.flashInfo.set("Address 0x1000")
|
||||
else:
|
||||
self.flashInfo.set("Address 0x10000")
|
||||
self.flashInfo.set("Erase(otadata): 0xe000...0xffff, Address 0x10000")
|
||||
def changeMode(self):
|
||||
m=self.mode.get()
|
||||
self.updateFlashInfo()
|
||||
|
@ -79,7 +90,7 @@ class App:
|
|||
self.fileInfo.set('')
|
||||
def fileDialog(self,ev):
|
||||
fn=FileDialog.askopenfilename()
|
||||
if fn is not None:
|
||||
if fn:
|
||||
self.filename.set(fn)
|
||||
info=self.checkImageFile(fn,self.mode.get() == 1)
|
||||
if info['error']:
|
||||
|
@ -97,12 +108,21 @@ class App:
|
|||
label=dev.name+"("+dev.device+")"
|
||||
names.append(label)
|
||||
self.port.configure(values=names)
|
||||
def addText(self,text,preventNl=False):
|
||||
le="\n"
|
||||
if preventNl:
|
||||
le=''
|
||||
self.text_widget.insert(tk.END,text+le)
|
||||
def addText(self,*args,**kwargs):
|
||||
first=True
|
||||
for k in args:
|
||||
self.text_widget.insert(tk.END,k)
|
||||
if not first:
|
||||
self.text_widget.insert(tk.END, ',')
|
||||
first=False
|
||||
if kwargs.get('end') is None:
|
||||
self.text_widget.insert(tk.END,"\n")
|
||||
else:
|
||||
self.text_widget.insert(tk.END,kwargs.get('end'))
|
||||
root.update()
|
||||
if self.interrupt:
|
||||
self.interrupt=False
|
||||
raise Exception("User cancel")
|
||||
|
||||
FULLOFFSET=61440
|
||||
HDROFFSET = 288
|
||||
|
@ -149,33 +169,64 @@ class App:
|
|||
offset=self.FULLOFFSET
|
||||
return self.getFirmwareInfo(fh,filename,offset)
|
||||
|
||||
|
||||
def buttonAction(self):
|
||||
def runCheck(self):
|
||||
self.text_widget.delete("1.0", "end")
|
||||
idx=self.port.current()
|
||||
isFull=self.mode.get() == 1
|
||||
idx = self.port.current()
|
||||
isFull = self.mode.get() == 1
|
||||
if idx < 0:
|
||||
self.addText("ERROR: no com port selected")
|
||||
return
|
||||
port=self.serialDevices[idx]
|
||||
fn=self.filename.get()
|
||||
port = self.serialDevices[idx]
|
||||
fn = self.filename.get()
|
||||
if fn is None or fn == '':
|
||||
self.addText("ERROR: no filename selected")
|
||||
return
|
||||
info=self.checkImageFile(fn,isFull)
|
||||
info = self.checkImageFile(fn, isFull)
|
||||
if info['error']:
|
||||
print("ERROR: %s"%info['info'])
|
||||
print("ERROR: %s" % info['info'])
|
||||
return
|
||||
command=['--chip','ESP32','--port',port,'chip_id']
|
||||
print("run esptool: %s"%" ".join(command))
|
||||
return {'port':port,'isFull':isFull}
|
||||
|
||||
def runEspTool(self,command):
|
||||
for b in self.actionButtons:
|
||||
b.configure(state=tk.DISABLED)
|
||||
self.cancelButton.configure(state=tk.NORMAL)
|
||||
print("run esptool: %s" % " ".join(command))
|
||||
root.update()
|
||||
root.update_idletasks()
|
||||
try:
|
||||
esptool.main(command)
|
||||
print("esptool done")
|
||||
except Exception as e:
|
||||
print("Exception in esptool %s"%e)
|
||||
|
||||
print("Exception in esptool %s" % e)
|
||||
for b in self.actionButtons:
|
||||
b.configure(state=tk.NORMAL)
|
||||
self.cancelButton.configure(state=tk.DISABLED)
|
||||
def buttonCheck(self):
|
||||
param = self.runCheck()
|
||||
if not param:
|
||||
return
|
||||
print("Settings OK")
|
||||
command = ['--chip', 'ESP32', '--port', param['port'], 'chip_id']
|
||||
self.runEspTool(command)
|
||||
|
||||
def buttonFlash(self):
|
||||
param=self.runCheck()
|
||||
if not param:
|
||||
return
|
||||
if param['isFull']:
|
||||
command=['--chip','ESP32','--port',param['port'],'write_flash','0x1000',self.filename.get()]
|
||||
self.runEspTool(command)
|
||||
else:
|
||||
command=['--chip','ESP32','--port',param['port'],'erase_region','0xe000','0x2000']
|
||||
self.runEspTool(command)
|
||||
command = ['--chip', 'ESP32', '--port', param['port'], 'write_flash', '0x10000', self.filename.get()]
|
||||
self.runEspTool(command)
|
||||
|
||||
|
||||
def buttonCancel(self):
|
||||
self.interrupt=True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = tk.Tk()
|
||||
|
|
Loading…
Reference in New Issue