Ejemplo n.º 1
0
    def _update_thread(self, instance):
        try:
            selection = instance.selection
            filename = selection[0] if len(selection) else None
            if filename:
                #Even though we stopped the RX thread, this is OK
                #since it doesn't return a value
                try:
                    self.ids.fw_progress.title = "Processing"
                    self._teardown_json_serial()
                except:
                    import sys, traceback
                    print "Exception in user code:"
                    print '-' * 60
                    traceback.print_exc(file=sys.stdout)
                    print '-' * 60
                    pass

                self.ids.fw_progress.title = "Progress"

                #Get our firmware updater class and register the
                #callback that will update the progress gauge
                fu = fw_update.FwUpdater()
                fu.register_progress_callback(self._update_progress_gauge)

                retries = 5
                port = None
                while retries > 0 and not port:
                    #Find our bootloader
                    port = fu.scan_for_device()

                    if not port:
                        retries -= 1
                        sleep(2)

                if not port:
                    self.ids.fw_progress.title = ""
                    raise Exception("Unable to locate bootloader")

                #Go on our jolly way
                fu.update_firmware(filename, port)
                self.ids.fw_progress.title = "Restarting"

                #Windows workaround
                if platform == 'win':
                    self.prompt_manual_restart()
                #Sleep for a few seconds since we need to let USB re-enumerate
                sleep(3)
            else:
                alertPopup('Error Loading', 'No firmware file selected')
        except Exception as detail:
            alertPopup('Error Loading',
                       'Failed to Load Firmware:\n\n' + str(detail))

        if not platform == 'win':
            self._restart_json_serial()
        self.ids.fw_progress.value = ''
        self.ids.fw_progress.title = ""
Ejemplo n.º 2
0
    def _update_thread(self, instance):
        try:
            selection = instance.selection
            filename = selection[0] if len(selection) else None
            if filename:
                # Even though we stopped the RX thread, this is OK
                # since it doesn't return a value
                self.ids.fw_progress.title = "Processing"

                self._teardown_json_serial()

                self.ids.fw_progress.title = "Progress"

                # Get our firmware updater class and register the
                # callback that will update the progress gauge
                fu = fw_update.FwUpdater(logger=Logger)
                fu.register_progress_callback(self._update_progress_gauge)

                retries = 5
                port = None
                while retries > 0 and not port:
                    # Find our bootloader
                    port = fu.scan_for_device()

                    if not port:
                        retries -= 1
                        sleep(2)

                if not port:
                    self.ids.fw_progress.title = ""
                    raise Exception("Unable to locate bootloader")

                # Go on our jolly way
                fu.update_firmware(filename, port)
                self.ids.fw_progress.title = "Restarting"

                # Sleep for a few seconds since we need to let USB re-enumerate
                sleep(3)
            else:
                alertPopup('Error Loading', 'No firmware file selected')
        except Exception as detail:
            alertPopup('Error Loading',
                       'Failed to Load Firmware:\n\n{}'.format(detail))
            Logger.error(traceback.format_exc())

        self._restart_json_serial()
        self.ids.fw_progress.value = ''
        self.ids.fw_progress.title = ""