3434ssl ._create_default_https_context = ssl ._create_unverified_context
3535
3636# App versioning
37- APP_VERSION = '0.9 .0'
37+ APP_VERSION = '1.0 .0'
3838APP_TIMESTAMP = '2019.08.14 14:20'
3939
4040# App name
5555USB_CON_IMG = os .path .join (RESOURCE_PATH , 'usb_con.png' )
5656USB_DCON_IMG = os .path .join (RESOURCE_PATH , 'usb_dcon.png' )
5757ORBITRON_FONT = os .path .join (RESOURCE_PATH , 'orbitron.ttf' )
58- BOOT_APP0_BIN = os .path .join (RESOURCE_PATH , 'boot_app0.bin' )
59- BOOTLOADER_DIO_40M_BIN = os .path .join (RESOURCE_PATH , 'bootloader_dio_40m.bin' )
6058
6159if hasattr (Qt , 'AA_EnableHighDpiScaling' ):
6260 QApplication .setAttribute (Qt .AA_EnableHighDpiScaling , True )
@@ -178,7 +176,7 @@ def show_dialog(self, title, message, details):
178176 msg_box .setTextFormat (Qt .RichText )
179177 msg_box .setStandardButtons (QMessageBox .Close )
180178 msg_box .setText (title )
181- msg_box .setInformativeText ('<font face=Arial>' + message + ' </font>' )
179+ msg_box .setInformativeText (f '<font face=Arial>{ message } </font>' )
182180 horizontalSpacer = QSpacerItem (550 , 0 , QSizePolicy .Minimum , QSizePolicy .Expanding )
183181 layout = msg_box .layout ()
184182 layout .addItem (horizontalSpacer , layout .rowCount (), 0 , 1 , layout .columnCount ())
@@ -187,18 +185,24 @@ def show_dialog(self, title, message, details):
187185 # Button clicked event
188186 def button_clicked (self ):
189187 # When some thread is already processing
190- if self .processing or not self .connected_port :
188+ if self .processing :
189+ return
190+
191+ #SumoRobot is not connected
192+ if not self .connected_port :
193+ self .show_dialog ('Updating SumoFirmware' ,
194+ 'Please connect your SumoRobot via USB cable first.' , '' )
191195 return
192196
193197 # Indicates a background thread process
194198 self .processing = 'update_firmware'
195199
196200 def app_info (self , event ):
197201 # Show app info dialog
198- self .show_dialog ('App info' , 'Version: ' + APP_VERSION + ' <br>' +
199- 'Timestamp: ' + APP_TIMESTAMP + ' <br><br>' +
200- 'This is the SumoManager app. You can update the SumoFirmware of your ' +
201- 'SumoRobot with it. Please keep this app up to the date for the best possible experience.<br>' , '' )
202+ self .show_dialog ('App info' , f 'Version: { APP_VERSION } <br>'
203+ + f 'Timestamp: { APP_TIMESTAMP } <br><br>'
204+ + 'This is the SumoManager app. You can update the SumoFirmware of your '
205+ + 'SumoRobot with it. Please keep this app up to the date for the best possible experience.<br>' , '' )
202206
203207 def update_firmware (self , event ):
204208 # When SumoRobot is connected and update firmware is not running
@@ -216,86 +220,53 @@ def run(self):
216220
217221 window .message .emit ('warning' , 'Downloading SumoFirmware ...' )
218222 try :
219- # Open the firmware and parition binary URLs
223+ # Open the SumoFirmware binary URL
220224 firmware_response = urllib .request .urlopen (SUMOFIRMWARE_URL + 'sumofirmware.bin' )
221- partitions_response = urllib .request .urlopen (SUMOFIRMWARE_URL + 'partitions.bin' )
222225
223- # Write the firmware binary into a file
226+ # Write the SumoFirmware binary into a file
224227 firmware_file = QTemporaryFile ()
225228 firmware_file .open ()
226229 firmware_file .writeData (firmware_response .read ())
227230 firmware_file .flush ()
228231
229- # Write the parition binary into a file
230- partitions_file = QTemporaryFile ()
231- partitions_file .open ()
232- partitions_file .writeData (partitions_response .read ())
233- partitions_file .flush ()
234-
235232 # Detect the ESP version
236233 esp = ESPLoader .detect_chip (window .connected_port )
237234
238235 # Prepare for flashing
239236 esp .run_stub ()
240237 esp .IS_STUB = True
241- esp .change_baud (460800 )
238+ esp .change_baud (115200 )
242239 esp .STATUS_BYTES_LENGTH = 2
243240 esp .flash_set_parameters (flash_size_bytes ('4MB' ))
244241 esp .FLASH_WRITE_SIZE = 0x4000
245242 esp .ESP_FLASH_DEFL_BEGIN = 0x10
246243
247- # Flash the latest MicroPython
248- window .message .emit ('warning' , 'Flashing SumoFirmware ...' )
249- write_flash (esp , argparse .Namespace (
250- addr_filename = [(0x1000 , open (BOOTLOADER_DIO_40M_BIN , 'rb' ))],
251- verify = False ,
252- compress = None ,
253- no_stub = False ,
254- erase_all = False ,
255- flash_mode = 'dio' ,
256- flash_size = '4MB' ,
257- flash_freq = 'keep' ,
258- no_compress = False ))
259- write_flash (esp , argparse .Namespace (
260- addr_filename = [(0x8000 , open (partitions_file .fileName (), 'rb' ))],
261- verify = False ,
262- compress = None ,
263- no_stub = False ,
264- erase_all = False ,
265- flash_mode = 'dio' ,
266- flash_size = '4MB' ,
267- flash_freq = 'keep' ,
268- no_compress = False ))
269- write_flash (esp , argparse .Namespace (
270- addr_filename = [(0xe000 , open (BOOT_APP0_BIN , 'rb' ))],
271- verify = False ,
272- compress = None ,
273- no_stub = False ,
274- erase_all = False ,
275- flash_mode = 'dio' ,
276- flash_size = '4MB' ,
277- flash_freq = 'keep' ,
278- no_compress = False ))
244+ # Callback to show flashing progress in percentage
245+ def show_progress (percentage ):
246+ window .message .emit ('warning' , f'Flashing SumoFirmware ... { percentage } %' )
247+
248+ # Flash the SumoFirmware image
279249 write_flash (esp , argparse .Namespace (
280- addr_filename = [(0x10000 , open (firmware_file .fileName (), 'rb' ))],
250+ addr_filename = [(0x1000 , open (firmware_file .fileName (), 'rb' ))],
281251 verify = False ,
282252 compress = None ,
283253 no_stub = False ,
284254 erase_all = False ,
285255 flash_mode = 'dio' ,
286256 flash_size = '4MB' ,
287257 flash_freq = 'keep' ,
288- no_compress = False ))
258+ no_compress = False ,
259+ callback = show_progress ))
289260 esp .hard_reset ()
290261 esp ._port .close ()
291262
292263 # All done
293264 window .message .emit ('info' , 'Successfully updated SumoFirmware' )
294265 except :
295266 window .dialog .emit ('Error updating SumoFirmware' ,
296- '* Check your Internet connection<br>' +
297- '* Try reconnecting the SumoRobot USB cable<br>' +
298- '* Finally try Update SumoFirmware again' ,
267+ '* Check your Internet connection<br>'
268+ + '* Try reconnecting the SumoRobot USB cable<br>'
269+ + '* Finally try Update SumoFirmware again' ,
299270 traceback .format_exc ())
300271 window .message .emit ('error' , 'Error updating SumoFirmware' )
301272
@@ -355,9 +326,9 @@ def run(self):
355326 response = urllib .request .urlopen (SUMOMANAGER_URL )
356327 if APP_VERSION .encode () not in response .read ():
357328 window .dialog .emit ('Update SumoManager' ,
358- 'Please download the latest SumoManager application under the following link:<br>' +
359- '<a style="color:white;cursor:pointer;" href="https://www.robokoding.com/kits/' +
360- 'sumorobot/sumomanager">https://www.robokoding.com/kits/sumorobot/sumomanager</a>' , '' )
329+ 'Please download the latest SumoManager application under the following link:<br>'
330+ + '<a style="color:white;cursor:pointer;" href="https://www.robokoding.com/kits/'
331+ + 'sumorobot/sumomanager">https://www.robokoding.com/kits/sumorobot/sumomanager</a>' , '' )
361332
362333 # Launch application
363334 sys .exit (app .exec_ ())
0 commit comments