Skip to content

Commit

Permalink
Add new features
Browse files Browse the repository at this point in the history
- record log for upload firmware
- Add Debugger to reset voice module
- change to use 4M flash_size to upload BiBoard firmware
- translate pre-postures name to different languages
  • Loading branch information
JasonWong08 committed Jun 28, 2024
1 parent b18f218 commit c239742
Show file tree
Hide file tree
Showing 7 changed files with 315 additions and 34 deletions.
100 changes: 89 additions & 11 deletions pyUI/FirmwareUploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
# May.1st, 2022

from commonVar import *
from subprocess import check_call
# from subprocess import check_call
import subprocess
import threading
from tkinter import ttk
from tkinter import filedialog
import pathlib


regularW = 14
language = languageList['English']
NyBoard_version_list = ['NyBoard_V1_0', 'NyBoard_V1_1', 'NyBoard_V1_2']
Expand Down Expand Up @@ -452,6 +454,7 @@ def WriteInstinctPrompts(self, port):
logger.debug(f"new line:{x}")
if x != "":
print(prompStr)
logger.info(prompStr)
questionMark = "Y/n"
if self.bFacReset and strBoardVersion in BiBoard_version_list: # for BiBoard Factory reset
newBoardMark = "Set up the new board"
Expand Down Expand Up @@ -617,7 +620,7 @@ def autoupload(self):
port = '/dev/' + self.strPort.get()
else:
port = self.strPort.get()
print(self.strPort.get())
logger.info(f"{self.strPort.get()}")
if port == ' ' or port == '':
messagebox.showwarning(txt('Warning'), txt('msgPort'))
self.force_focus()
Expand All @@ -632,7 +635,7 @@ def autoupload(self):
fnWriteI = path + 'WriteInstinct.ino.hex'
fnOpenCat = path + 'OpenCat' + strMode + '.ino.hex'
filename = [fnWriteI, fnOpenCat]
print(filename)
logger.info(f"{filename}")
uploadStage = ['Parameters', 'Main function']
for s in range(len(uploadStage)):
# if s == 0 and self.bParaUploaded and self.currentSetting[:4] == self.lastSetting[:4]:
Expand Down Expand Up @@ -669,11 +672,48 @@ def autoupload(self):
pass # no need upload configuration firmware again
else:
if self.OSname == 'x11': # Linuxself.OSname == 'x11': # Linux
check_call(avrdudePath + 'avrdude -C' + avrdudeconfPath + 'avrdude.conf -v -V -patmega328p -carduino -P%s -b115200 -D -Uflash:w:%s:i' % \
(port, filename[s]), shell=self.shellOption)
# check_call(avrdudePath + 'avrdude -C' + avrdudeconfPath + 'avrdude.conf -v -V -patmega328p -carduino -P%s -b115200 -D -Uflash:w:%s:i' % \
# (port, filename[s]), shell=self.shellOption)
cmd = avrdudePath + 'avrdude -C' + avrdudeconfPath + 'avrdude.conf -v -V -patmega328p -carduino -P' + port + ' -b115200 -D -Uflash:w:' + \
filename[s] + ':i'
else:
# check_call(avrdudePath + 'avrdude -C' + avrdudePath + 'avrdude.conf -v -V -patmega328p -carduino -P%s -b115200 -D -Uflash:w:%s:i > ./avrdude_log.txt 2> ./avrdude_errors.txt' % \
# (port, filename[s]), shell=self.shellOption)
cmd = avrdudePath + 'avrdude -C' + avrdudePath + 'avrdude.conf -v -V -patmega328p -carduino -P' + port + ' -b115200 -D -Uflash:w:' + \
filename[s] + ':i'

# Run the program and capture output
process = subprocess.Popen(cmd,shell = self.shellOption, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
output, error = process.communicate() # Wait for the program to finish
# printH("error:", error)
# printH("output:", output)

# Check for errors (optional)
if error:
logger.info(f"Error running program: {error}")
else:
check_call(avrdudePath + 'avrdude -C' + avrdudePath + 'avrdude.conf -v -V -patmega328p -carduino -P%s -b115200 -D -Uflash:w:%s:i' % \
(port, filename[s]), shell=self.shellOption)
# Write captured output to a file
with open("./logfile.log", "a+", encoding="utf-8") as logfile:
logfile.write(output.decode()) # Decode bytes to string
# time.sleep(5)
# lines = logfile.readlines()
# print(lines)
file = open('./logfile.log', 'r+')
lines = file.readlines()
file.close()

for line in lines:
line = line.strip() # remove the line break from each line
logger.debug(f"{line}")
if ("programmer is not responding" in line) or \
("can\'t open device" in line) or \
("attempt" in line):
status = txt(uploadStage[s]) + txt('failed to upload')
self.strStatus.set(status)
self.statusBar.update()
messagebox.showinfo('Petoi Desktop App',txt('checkLogfile'))
return False

# self.inProgress = False
except:
status = txt(uploadStage[s]) + txt('failed to upload')
Expand Down Expand Up @@ -717,7 +757,7 @@ def autoupload(self):
fnBootApp = path + 'boot_app0.bin'

filename = [fnBootLoader, fnPartitions, fnBootApp, fnMainFunc]
print(filename)
logger.info(f"{filename}")
self.strStatus.set(txt('Uploading') + txt('Main function') + ', ' + txt('Time consuming') + '...' )
self.win.update()
if self.OSname == 'win32': # Windows
Expand All @@ -731,10 +771,48 @@ def autoupload(self):
return False
else: # Mac
esptoolPath = resourcePath + 'esptoolMac/'
print()
# print()
try:
check_call(esptoolPath + 'esptool --chip esp32 --port %s --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 16MB 0x1000 %s 0x8000 %s 0xe000 %s 0x10000 %s' % \
(port, filename[0], filename[1], filename[2], filename[3]), shell=self.shellOption)
# check_call(esptoolPath + 'esptool --chip esp32 --port %s --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 16MB 0x1000 %s 0x8000 %s 0xe000 %s 0x10000 %s' % \
# (port, filename[0], filename[1], filename[2], filename[3]), shell=self.shellOption)
# subprocess.check_call(esptoolPath + 'esptool --chip esp32 --port %s --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x1000 %s 0x8000 %s 0xe000 %s 0x10000 %s' % \
# (port, filename[0], filename[1], filename[2], filename[3]), shell=self.shellOption)
cmd = esptoolPath + 'esptool --chip esp32 --port ' + port + ' --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x1000 ' \
+ filename[0] + \
' 0x8000 ' + filename[1] + \
' 0xe000 ' + filename[2] + \
' 0x10000 ' + filename[3]
# Run the program and capture output
process = subprocess.Popen(cmd, shell=self.shellOption, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
output, error = process.communicate() # Wait for the program to finish
# printH("error:", error)
# printH("output:", output)

# Check for errors (optional)
if error:
logger.info(f"Error running program: {error}")
else:
# Write captured output to a file
with open("./logfile.log", "a+", encoding="utf-8") as logfile:
logfile.write(output.decode()) # Decode bytes to string
# time.sleep(5)
# lines = logfile.readlines()
# print(lines)
file = open('./logfile.log', 'r+')
lines = file.readlines()
file.close()

for line in lines:
line = line.strip() # remove the line break from each line
logger.debug(f"{line}")
if ("Traceback" in line):
status = txt('Main function') + txt('failed to upload')
self.strStatus.set(status)
self.statusBar.update()
messagebox.showinfo('Petoi Desktop App', txt('checkLogfile'))
return False

except:
status = txt('Main function') + txt('failed to upload')
self.strStatus.set(status)
Expand Down
9 changes: 5 additions & 4 deletions pyUI/SkillComposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ def __init__(self,model, lan):

self.sixW = 6
self.sliderW = 320
# self.buttonW = 20
self.buttonW = 10
self.calibButtonW = 8
self.canvasW = 330
Expand All @@ -164,6 +165,7 @@ def __init__(self,model, lan):

self.sixW = 5
self.sliderW = 338
# self.buttonW = 18
self.buttonW = 8
self.calibButtonW = 6
self.canvasW = 420
Expand Down Expand Up @@ -483,9 +485,9 @@ def createPosture(self):
labelPosture.grid(row=0, column=0, columnspan=4)
i = 0
for pose in self.postureTable:
button = Button(self.framePosture, text=pose, fg='blue', width=self.buttonW,
button = Button(self.framePosture, text=txt(pose), fg='blue', width=self.buttonW,
command=lambda p=pose: self.setPose(p))
button.grid(row=i // 4 + 1, column=i % 4, padx=3)
button.grid(row=i // 3 + 1, column=i % 3, padx=3)
i += 1

def createSkillEditor(self):
Expand Down Expand Up @@ -1591,7 +1593,6 @@ def setAngle(self, idx, value):
send(ports, ['I', [idx, value], 0.05])
else:
send(ports, ['i', [idx, value], 0.05])

else:
diff = value - self.frameData[4 + idx]
indexedList = list()
Expand All @@ -1604,7 +1605,7 @@ def setAngle(self, idx, value):
send(ports, ['L', self.frameData[4:20], 0.05])
elif len(indexedList):
send(ports, ['I', indexedList, 0.05])

self.indicateEdit()
self.updateSliders(self.frameData)

Expand Down
7 changes: 5 additions & 2 deletions pyUI/UI.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from FirmwareUploader import *
from SkillComposer import *
from Calibrator import *
from Debugger import *
from tkinter import PhotoImage

language = languageList['English']
apps = ['Firmware Uploader', 'Joint Calibrator', 'Skill Composer'] # ,'Task Scheduler']
apps = ['Firmware Uploader', 'Joint Calibrator', 'Skill Composer', 'Debugger'] # ,'Task Scheduler']


def txt(key):
Expand Down Expand Up @@ -69,7 +70,7 @@ def __init__(self):
self.OSname = self.window.call('tk', 'windowingsystem')
if self.OSname == 'win32':
self.window.iconbitmap(resourcePath + 'Petoi.ico')
self.window.geometry('398x270+800+400')
self.window.geometry('398x360+800+400')
elif self.OSname == 'aqua':
self.window.geometry('+800+400')
self.backgroundColor = 'gray'
Expand Down Expand Up @@ -162,6 +163,8 @@ def utility(self, app):
elif app == 'Skill Composer':
self.showBootPrompt("skil")
SkillComposer(model, language)
elif app == 'Debugger':
Debugger(model, language)
elif app == 'Task Scheduler':
print('schedule')

Expand Down
2 changes: 1 addition & 1 deletion pyUI/commonVar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
NyBoard_version = 'NyBoard_V1_2'
verNumber = sys.version.split('(')[0].split()[0]
verNumber = verNumber.split('.')
print(verNumber)
logger.info(f"Python version is {verNumber}")
#verNumber = [2,1,1] #for testing
supportHoverTip = True
if int(verNumber[0])<3 or int(verNumber[1])<7:
Expand Down
Binary file added pyUI/resources/VoiceSwitch.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c239742

Please sign in to comment.