Beispiel #1
0
        def is_present_async(present, extension_type, name):
            self.extension_type_preset[extension_type] = present

            if present:
                if self.device_info.extensions['ext0'] == None:
                    ext = 'ext0'
                elif self.device_info.extensions['ext1'] == None:
                    ext = 'ext1'
                else:
                    return # This should never be the case

                self.device_info.extensions[ext] = infos.ExtensionInfo()
                self.device_info.extensions[ext].name = name
                self.device_info.extensions[ext].extension_type = extension_type
                self.device_info.extensions[ext].position = ext
                self.device_info.extensions[ext].master_info = self.device_info
                infos.update_info(self.uid)

                def get_wifi2_firmware_version_async(version, ext):
                    self.device_info.extensions[ext].firmware_version_installed = version
                    infos.update_info(self.uid)

                if extension_type == self.master.EXTENSION_TYPE_WIFI2:
                    self.device_info.extensions[ext].url_part = 'wifi_v2'
                    async_call(self.master.get_wifi2_firmware_version, None, lambda v: get_wifi2_firmware_version_async(v, ext), self.increase_error_count)
    def reconfigure_everything_async1(self, group):
        for i in range(4):
            if group[i] == 'n':
                self.groups[i].setCurrentIndex(0)
            else:
                item = 'Port ' + group[i].upper()
                index = self.groups[i].findText(item, Qt.MatchStartsWith)
                if index == -1:
                    self.groups[i].setCurrentIndex(0)
                else:
                    self.groups[i].setCurrentIndex(index)

        self.monoflop_pin.clear()

        if group[0] == 'n' and group[1] == 'n' and group[2] == 'n' and group[3] == 'n':
            self.show_buttons(0)
            self.hide_buttons(1)
            self.hide_buttons(2)
            self.hide_buttons(3)
            self.monoflop_pin.addItem('Pin 0')
            self.monoflop_pin.addItem('Pin 1')
            self.monoflop_pin.addItem('Pin 2')
            self.monoflop_pin.addItem('Pin 3')
        else:
            for i in range(4):
                if group[i] == 'n':
                    self.hide_buttons(i)
                else:
                    for j in range(4):
                        self.monoflop_pin.addItem('Pin ' + str(i*4+j))
                    self.show_buttons(i)

        self.monoflop_pin.setCurrentIndex(0)

        async_call(self.ido4.get_value, None, self.reconfigure_everything_async2, self.increase_error_count)
    def apply_changes(self):
        config  = self.configs[self.combo_config.currentIndex()]
        content = config.edit.toPlainText()

        self.action_in_progress = True
        self.update_ui_state()

        self.label_progress.setText('Uploading ' + config.absolute_name)

        def cb_open(red_file):
            def cb_write(error):
                red_file.release()

                self.action_in_progress = False
                self.update_ui_state()

                if error != None:
                    QMessageBox.critical(get_main_window(), 'Apply Changes Error',
                                         u'Error while writing {0}: {1}'.format(config.display_name, error))
                    return

                config.set_content(content)

            red_file.write_async(content.encode('utf-8'), cb_write)

        def cb_open_error(error):
            self.action_in_progress = False
            self.update_ui_state()

            QMessageBox.critical(get_main_window(), 'Apply Changes Error',
                                 u'Error while opening {0}: {1}'.format(config.display_name, error))

        async_call(REDFile(self.session).open,
                   (config.absolute_name, REDFile.FLAG_WRITE_ONLY | REDFile.FLAG_CREATE | REDFile.FLAG_NON_BLOCKING | REDFile.FLAG_TRUNCATE, 0o644, 0, 0),
                   cb_open, cb_open_error, report_exception=True)
Beispiel #4
0
    def start(self):
        if self.session == None:
            return

        if self.image_version.string == None:
            # FIXME: this is should actually be sync to ensure that the image
            #        version is known before it'll be used
            def read_image_version_async(red_file):
                return red_file.open('/etc/tf_image_version',
                                     REDFile.FLAG_READ_ONLY | REDFile.FLAG_NON_BLOCKING,
                                     0, 0, 0).read(256).decode('utf-8').strip()

            def cb_success(image_version):
                if self.label_version != None:
                    self.label_version.setText(image_version)

                m = re.match(r'(\d+)\.(\d+)\s+\((.+)\)', image_version)

                if m != None:
                    try:
                        self.image_version.string = image_version
                        self.image_version.number = (int(m.group(1)), int(m.group(2)))
                        self.image_version.flavor = m.group(3)
                    except:
                        pass

                self.label_discovering.hide()
                self.tab_widget.show()
                self.tab_widget_current_changed(self.tab_widget.currentIndex())

            async_call(read_image_version_async, REDFile(self.session), cb_success, None)
        else:
            self.tab_widget_current_changed(self.tab_widget.currentIndex())
    def start(self):
        async_call(self.analog_in.get_sample_rate, None, self.get_sample_rate_async, self.increase_error_count)

        self.cbe_voltage0.set_period(100)
        self.cbe_voltage1.set_period(100)

        self.plot_widget.stop = False
Beispiel #6
0
    def start(self):
        async_call(self.rs2.get_remote_configuration,
                   None,
                   self.get_remote_configuration_async,
                   self.increase_error_count)

        self.timer_get_remote_input.start()
Beispiel #7
0
 def stop(self):
     self.cbe_error_count.set_period(0)
     if not self.read_callback_was_enabled:
         try:
             async_call(self.rs485.disable_read_callback, None, None, None)
         except:
             pass
Beispiel #8
0
    def get_image_version_async(self):
        if self.session == None:
            return

        def read_image_version_async(red_file):
            return red_file.open('/etc/tf_image_version',
                                 REDFile.FLAG_READ_ONLY | REDFile.FLAG_NON_BLOCKING,
                                 0, 0, 0).read(256).decode('utf-8').strip()

        def cb_success(image_version):
            if self.label_version != None:
                self.label_version.setText(image_version)

            m = re.match(r'(\d+)\.(\d+)\s+\((.+)\)', image_version)

            if m != None:
                try:
                    self.image_version.number = (int(m.group(1)), int(m.group(2)))
                    self.image_version.flavor = m.group(3)
                    self.image_version.string = image_version # set this last, because it is used as validity check
                except:
                    self.label_discovering.setText('Error: Could not parse Image Version: {0}'.format(image_version))
                else:
                    self.widget_discovering.hide()
                    self.tab_widget.show()
                    self.tab_widget_current_changed(self.tab_widget.currentIndex())
                    self.device_info.firmware_version_installed = self.image_version.number + (0, )
                    brickv.infos.update_info(self.device_info.uid)
            else:
                self.label_discovering.setText('Error: Could not parse Image Version: {0}'.format(image_version))

        self.label_discovering.setText('Discovering Image Version...')
        self.widget_discovering.show()
        async_call(read_image_version_async, REDFile(self.session), cb_success, None)
Beispiel #9
0
    def start(self):
        async_call(self.rtc.get_offset, None, self.get_offset_async, self.increase_error_count)

        if self.firmware_version >= (2, 0, 1):
            async_call(self.rtc.get_alarm, None, self.get_alarm_async, self.increase_error_count)

        self.cbe_date_time.set_period(50)
Beispiel #10
0
    def start(self):
        async_call(self.hf.get_edge_count_config, None, self.get_edge_count_config_async, self.increase_error_count,
                   expand_result_tuple_for_callback=True)

        self.cbe_edge_count.set_period(50)

        self.plot_widget.stop = False
    def slot_brickd_refresh_clicked(self):
        self.brickd_button_refresh_enabled(False)

        def cb_open(red_file):
            def cb_read(red_file, result):
                red_file.release()

                if result and result.data is not None:
                    self.brickd_conf = config_parser.parse(result.data.decode('utf-8'))
                    self.update_brickd_widget_data()
                else:
                    QtGui.QMessageBox.critical(get_main_window(),
                                               'Settings | Brickd',
                                               'Error reading brickd config file.')

                self.brickd_button_refresh_enabled(True)
                self.brickd_button_save_enabled(False)

            red_file.read_async(4096, lambda x: cb_read(red_file, x))

        def cb_open_error():
            self.brickd_button_refresh_enabled(True)
            QtGui.QMessageBox.critical(get_main_window(),
                                       'Settings | Brickd',
                                       'Error opening brickd config file.')

        async_call(self.brickd_conf_rfile.open,
                   (BRICKD_CONF_PATH, REDFile.FLAG_READ_ONLY | REDFile.FLAG_NON_BLOCKING, 0, 0, 0),
                   cb_open,
                   cb_open_error)
Beispiel #12
0
 def cb_state(self, state, idle):
     if state & (self.nfc.STATE_ERROR & ~self.nfc.STATE_IDLE):
         self.tag_type_changed(self.combo_box_tag_type.currentIndex())
         if (state & 0xF) == self.nfc.STATE_REQUEST_TAG_ID:
             s = 'Could not find {0} tag'.format(self.combo_box_tag_type.currentText())
             self.label_id.setText(s)
         elif (state & 0xF) == self.nfc.STATE_AUTHENTICATING_MIFARE_CLASSIC_PAGE:
             s = 'Error: Could not authenticate page {0}'.format(self.read_page_clicked_page_range)
             self.textedit_read_page.setPlainText(s)
         elif (state & 0xF) == self.nfc.STATE_WRITE_PAGE:
             self.write_page_was_clicked = False
             s = 'Error: Could not write page {0}'.format(self.write_page_clicked_page_range)
             self.textedit_read_page.setPlainText(s)
         elif (state & 0xF) == self.nfc.STATE_REQUEST_PAGE:
             s = 'Error: Could not read page {0}'.format(self.read_page_clicked_page_range)
             self.textedit_read_page.setPlainText(s)
     elif state & self.nfc.STATE_IDLE:
         if (state & 0xF) == self.nfc.STATE_REQUEST_TAG_ID:
             async_call(self.nfc.get_tag_id, None, self.get_tag_id_async, self.increase_error_count)
         elif (state & 0xF) == self.nfc.STATE_AUTHENTICATING_MIFARE_CLASSIC_PAGE:
             if self.write_page_was_clicked:
                 self.write_page_was_clicked = False
                 self.nfc.write_page(self.write_page_clicked_first_page, self.write_page_clicked_data)
             else:
                 self.nfc.request_page(self.read_page_clicked_first_page)
         elif (state & 0xF) == self.nfc.STATE_REQUEST_PAGE:
             async_call(self.nfc.get_page, None, self.get_page_async, self.increase_error_count)
         elif (state & 0xF) == self.nfc.STATE_WRITE_PAGE:
             self.write_page_was_clicked = False
             s = 'Successfully wrote page {0}'.format(self.write_page_clicked_page_range)
             self.textedit_read_page.setPlainText(s)
Beispiel #13
0
 def bl_clicked(self):
     if self.bl_button.text().replace('&', '') == 'Backlight On':
         async_call(self.lcd.backlight_on, None, None, self.increase_error_count)
         self.bl_button.setText('Backlight Off')
     else:
         async_call(self.lcd.backlight_off, None, None, self.increase_error_count)
         self.bl_button.setText('Backlight On')
Beispiel #14
0
    def start(self):
        async_call(self.tir.get_emissivity, None, self.get_emissivity_async, self.increase_error_count)

        self.cbe_ambient_temperature.set_period(250)
        self.cbe_object_temperature.set_period(250)

        self.plot_widget.stop = False
Beispiel #15
0
    def get_wifi_encryption_async(self, enc):
        encryption, key, key_index, eap_options, ca_certificate_length, client_certificate_length, private_key_length = enc

        if self.connection in (2, 3, 4, 5):
            encryption -= 2

        eap_outer = eap_options & 0b00000011
        eap_inner = (eap_options & 0b00000100) >> 2
        key = key.replace('\0', '')

        self.wifi_eap_outer_auth.setCurrentIndex(eap_outer)
        self.wifi_eap_inner_auth.setCurrentIndex(eap_inner)
        self.wifi_encryption.setCurrentIndex(encryption)

        if key == '-' and self.parent.firmware_version >= (2, 0, 2):
            async_call(self.master.get_long_wifi_key, None, self.get_long_wifi_key_async, self.parent.increase_error_count)
        else:
            self.wifi_key.setText(key)

        self.wifi_key_index.setValue(key_index)

        self.wifi_connection.currentIndexChanged.connect(self.connection_changed)
        self.wifi_encryption.currentIndexChanged.connect(self.encryption_changed)
        self.wifi_save.clicked.connect(self.save_clicked)
        self.wifi_show_status.clicked.connect(self.show_status_clicked)
        self.wifi_ca_certificate_browse.clicked.connect(self.ca_certificate_browse_clicked)
        self.wifi_client_certificate_browse.clicked.connect(self.client_certificate_browse_clicked)
        self.wifi_private_key_browse.clicked.connect(self.private_key_browse_clicked)

        self.connection_changed(0)
        self.encryption_changed(0)
        self.wifi_encryption.setCurrentIndex(encryption) # ensure that the correct encryption is displayed
Beispiel #16
0
    def start(self):
        async_call(self.p.get_sensor_type, None, self.get_sensor_type_async, self.increase_error_count)
        async_call(self.p.get_moving_average, None, self.get_moving_average_async, self.increase_error_count)

        self.cbe_pressure.set_period(100)

        self.plot_widget.stop = False
Beispiel #17
0
 def start(self):
     if self.has_clock_frequency:
         async_call(self.led_strip.get_clock_frequency, None, self.cb_frequency, self.increase_error_count)
     async_call(self.led_strip.get_supply_voltage, None, self.cb_voltage, self.increase_error_count)
     self.voltage_timer.start()
     self.led_strip.register_callback(self.led_strip.CALLBACK_FRAME_RENDERED,
                                      self.qtcb_frame_rendered.emit)
Beispiel #18
0
    def start(self):
        async_call(self.hf.get_counter_config, None, self.get_counter_config_async, self.increase_error_count)

        self.cbe_magnetic_flux_density.set_period(25)
        self.cbe_counter.set_period(100)

        self.plot_widget.stop = False
Beispiel #19
0
    def read_async(session, name, content_callback, error_callback, max_read_length=1024*1024):
        def cb_open(red_file):
            def cb_read(result):
                red_file.release()

                if result.error != None:
                    if error_callback != None:
                        error_callback(TextFile.ERROR_KIND_READ, result.error)

                    return

                try:
                    content = result.data.decode('utf-8')
                except UnicodeDecodeError as e:
                    if error_callback != None:
                        error_callback(TextFile.ERROR_KIND_UTF8, e)

                    return

                if content_callback != None:
                    content_callback(content)

            red_file.read_async(max_read_length, cb_read)

        def cb_open_error(error):
            if error_callback != None:
                error_callback(TextFile.ERROR_KIND_OPEN, error)

        async_call(REDFile(session).open,
                   (name, REDFile.FLAG_READ_ONLY | REDFile.FLAG_NON_BLOCKING, 0, 0, 0),
                   cb_open, cb_open_error, report_exception=True)
Beispiel #20
0
    def update(self):
        for pin in range(4):
            if self.monoflop_active[pin]:
                def get_lambda(pin):
                    return lambda x: self.update_async(pin, x)

                async_call(self.io.get_monoflop, pin, get_lambda(pin), self.increase_error_count)
    def __init__(self, *args):
        PluginBase.__init__(self, BrickletIndustrialDigitalIn4, *args)

        self.setupUi(self)
        
        self.idi4 = self.device
        
        self.gnd_pixmap = load_masked_pixmap('plugin_system/plugins/industrial_digital_in_4/dio_gnd.bmp')
        self.vcc_pixmap = load_masked_pixmap('plugin_system/plugins/industrial_digital_in_4/dio_vcc.bmp')
        
        self.pin_buttons = [self.b0, self.b1, self.b2, self.b3, self.b4, self.b5, self.b6, self.b7, self.b8, self.b9, self.b10, self.b11, self.b12, self.b13, self.b14, self.b15]
        self.pin_button_icons = [self.b0_icon, self.b1_icon, self.b2_icon, self.b3_icon, self.b4_icon, self.b5_icon, self.b6_icon, self.b7_icon, self.b8_icon, self.b9_icon, self.b10_icon, self.b11_icon, self.b12_icon, self.b13_icon, self.b14_icon, self.b15_icon]
        self.pin_button_labels = [self.b0_label, self.b1_label, self.b2_label, self.b3_label, self.b4_label, self.b5_label, self.b6_label, self.b7_label, self.b8_label, self.b9_label, self.b10_label, self.b11_label, self.b12_label, self.b13_label, self.b14_label, self.b15_label]
        self.groups = [self.group0, self.group1, self.group2, self.group3]

        self.lines = [[self.line0, self.line0a, self.line0b, self.line0c],
                      [self.line1, self.line1a, self.line1b, self.line1c],
                      [self.line2, self.line2a, self.line2b, self.line2c],
                      [self.line3, self.line3a, self.line3b, self.line3c]]
        for lines in self.lines:
            for line in lines:
                line.setVisible(False)
        
        self.available_ports = 0
        async_call(self.idi4.get_available_for_group, None, self.get_available_for_group_aysnc, self.increase_error_count)

        self.cbe_value = CallbackEmulator(self.idi4.get_value,
                                          self.cb_value,
                                          self.increase_error_count)
        
        self.set_group.clicked.connect(self.set_group_clicked)
        
        self.debounce_go.clicked.connect(self.debounce_go_clicked)
        
        self.reconfigure_everything()
Beispiel #22
0
    def start(self):
        async_call(self.acc.get_configuration, None, self.get_configuration_async, self.increase_error_count)
        async_call(self.acc.get_moving_average, None, self.get_moving_average_async, self.increase_error_count)

        self.cbe_current.set_period(100)

        self.plot_widget.stop = False
Beispiel #23
0
        def is_present_async(present, extension_type, name):
            self.extension_type_preset[extension_type] = present

            if present:
                if self.device_info.extensions['ext0'] == None:
                    ext = 'ext0'
                elif self.device_info.extensions['ext1'] == None:
                    ext = 'ext1'
                else:
                    return # This should never be the case

                self.device_info.extensions[ext] = infos.ExtensionInfo()
                self.device_info.extensions[ext].name = name
                self.device_info.extensions[ext].extension_type = extension_type
                self.device_info.extensions[ext].position = ext
                self.device_info.extensions[ext].master_info = self.device_info

                if extension_type == self.master.EXTENSION_TYPE_WIFI2:
                    self.device_info.extensions[ext].url_part = 'wifi_v2'
                    # When WIFI2 extension firmware version is being requested the
                    # extension might still not be done with booting and thus the
                    # message won't be received by the extension. So we delay sending
                    # the request which gives enough time to the extension to finish
                    # booting. Note that this delay is only induced when there is a
                    # WIFI2 extension present.
                    self.wifi2_ext = ext
                    self.label_no_extension.setText('Waiting for WIFI Extension 2.0 firmware version...')
                    async_call(self.master.get_wifi2_firmware_version, None, self.get_wifi2_firmware_version_async, self.increase_error_count, delay=2.0)

                infos.update_info(self.uid)
    def start(self):
        self.sound_pressure_level.register_callback(self.sound_pressure_level.CALLBACK_SPECTRUM, self.qtcb_spectrum.emit)

        async_call(self.sound_pressure_level.get_configuration, None, self.get_configuration_async, self.increase_error_count)
        async_call(self.sound_pressure_level.set_spectrum_callback_configuration, 1, None, self.increase_error_count)

        self.cbe_get_decibel.set_period(50)
    def __init__(self, ipcon, uid, version):
        PluginBase.__init__(self, ipcon, uid, 'Industrial Digital In 4 Bricklet', version)
        
        self.setupUi(self)
        
        self.idi4 = BrickletIndustrialDigitalIn4(uid, ipcon)
        
        self.gnd_pixmap = bmp_to_pixmap('plugin_system/plugins/industrial_digital_in_4/dio_gnd.bmp')
        self.vcc_pixmap = bmp_to_pixmap('plugin_system/plugins/industrial_digital_in_4/dio_vcc.bmp')
        
        self.pin_buttons = [self.b0, self.b1, self.b2, self.b3, self.b4, self.b5, self.b6, self.b7, self.b8, self.b9, self.b10, self.b11, self.b12, self.b13, self.b14, self.b15]
        self.pin_button_icons = [self.b0_icon, self.b1_icon, self.b2_icon, self.b3_icon, self.b4_icon, self.b5_icon, self.b6_icon, self.b7_icon, self.b8_icon, self.b9_icon, self.b10_icon, self.b11_icon, self.b12_icon, self.b13_icon, self.b14_icon, self.b15_icon]
        self.pin_button_labels = [self.b0_label, self.b1_label, self.b2_label, self.b3_label, self.b4_label, self.b5_label, self.b6_label, self.b7_label, self.b8_label, self.b9_label, self.b10_label, self.b11_label, self.b12_label, self.b13_label, self.b14_label, self.b15_label]
        self.groups = [self.group0, self.group1, self.group2, self.group3]

        self.lines = [[self.line0, self.line0a, self.line0b, self.line0c],
                      [self.line1, self.line1a, self.line1b, self.line1c],
                      [self.line2, self.line2a, self.line2b, self.line2c],
                      [self.line3, self.line3a, self.line3b, self.line3c]]
        for lines in self.lines:
            for line in lines:
                line.setVisible(False)
        
        self.available_ports = 0
        async_call(self.idi4.get_available_for_group, None, self.get_available_for_group_aysnc, self.increase_error_count)
        
        self.qtcb_interrupt.connect(self.cb_interrupt)
        self.idi4.register_callback(self.idi4.CALLBACK_INTERRUPT,
                                    self.qtcb_interrupt.emit)
        
        self.set_group.pressed.connect(self.set_group_pressed)
        
        self.debounce_go.pressed.connect(self.debounce_go_pressed)
        
        self.reconfigure_everything()
Beispiel #26
0
    def btn_cal_calibrate_clicked(self):
        self.parent.barometer.set_calibration(int(self.air_pressure * 1000), int(self.sbox_cal_actual_air_pressure.value() * 1000))

        async_call(self.parent.barometer.get_calibration,
                   None,
                   self.get_calibration_async,
                   self.parent.increase_error_count)
    def update(self):
        try:
            pin = int(self.monoflop_pin.currentText().replace('Pin ', ''))
        except ValueError:
            return

        async_call(self.iqr.get_monoflop, pin, lambda monoflop: self.update_async(pin, *monoflop), self.increase_error_count)
    def refresh_config(self, index, done_callback):
        if index >= len(self.configs):
            self.action_in_progress = False
            self.update_ui_state()

            if done_callback != None:
                done_callback()

            return

        config = self.configs[index]

        if config == None:
            self.refresh_config(index + 1, done_callback)
            return

        self.action_in_progress = True
        self.update_ui_state()

        self.label_progress.setText('Downloading ' + config.absolute_name)

        def cb_open(red_file):
            def cb_read(result):
                red_file.release()

                self.action_in_progress = False
                self.update_ui_state()

                if result.error != None:
                    if result.error.error_code != REDError.E_OPERATION_ABORTED and \
                       result.error.error_code != REDError.E_DOES_NOT_EXIST:
                        self.log_error(u'Error while reading {0}: {1}'.format(config.display_name, error))
                    else:
                        config.set_content('')
                else:
                    try:
                        content = result.data.decode('utf-8')
                    except UnicodeDecodeError:
                        # FIXME: maybe add a encoding guesser here or try some common encodings if UTF-8 fails
                        self.log_error(u'Error: Config file {0} is not UTF-8 encoded'.format(config.display_name))
                    else:
                        config.set_content(content)

                self.refresh_config(index + 1, done_callback)

            red_file.read_async(red_file.length, cb_read)

        def cb_open_error(error):
            if isinstance(error, REDError) and \
               error.error_code != REDError.E_OPERATION_ABORTED and \
               error.error_code != REDError.E_DOES_NOT_EXIST:
                self.log_error(u'Error while opening {0}: {1}'.format(config.display_name, error))
            else:
                config.set_content('')

            self.refresh_config(index + 1, done_callback)

        async_call(REDFile(self.session).open,
                   (config.absolute_name, REDFile.FLAG_READ_ONLY | REDFile.FLAG_NON_BLOCKING, 0, 0, 0),
                   cb_open, cb_open_error, report_exception=True)
Beispiel #29
0
 def radio_clicked(self):
     if self.radio_voltage.isChecked():
         async_call(self.ao.get_voltage, None, self.new_voltage, self.increase_error_count)
         self.mode_voltage()
     else:
         async_call(self.ao.get_current, None, self.new_current, self.increase_error_count)
         self.mode_current()
Beispiel #30
0
    def btn_cal_remove_clicked(self):
        self.parent.barometer.set_calibration(0, 0)

        async_call(self.parent.barometer.get_calibration,
                   None,
                   self.get_calibration_async,
                   self.parent.increase_error_count)
Beispiel #31
0
 def update_start(self):
     async_call(self.stepper.get_max_velocity, None,
                self.get_max_velocity_async, self.increase_error_count)
     async_call(self.stepper.get_speed_ramping, None,
                self.get_speed_ramping_async, self.increase_error_count)
     async_call(self.stepper.get_decay, None, self.get_decay_async,
                self.increase_error_count)
     async_call(self.stepper.is_enabled, None, self.is_enabled_async,
                self.increase_error_count)
     async_call(self.stepper.is_sync_rect, None, self.is_sync_rect_async,
                self.increase_error_count)
Beispiel #32
0
    def motor_current_button_clicked(self):
        qid = QInputDialog(self)
        qid.setInputMode(QInputDialog.IntInput)
        qid.setIntMinimum(0)
        qid.setIntMaximum(2500)
        qid.setIntStep(100)
        async_call(self.stepper.get_motor_current, None, qid.setIntValue, self.increase_error_count)
        qid.intValueSelected.connect(self.motor_current_selected)
        qid.setLabelText("Choose motor current in mA.")
#                         "<font color=red>Setting this too high can destroy your Motor.</font>")
        qid.open()
Beispiel #33
0
    def show(self):
        QDialog.show(self)

        self.cbe_p.set_period(100)
        self.cbe_a.set_period(100)
        self.cbe_t.set_period(100)

        self.sbox_cal_actual_air_pressure.setValue(1013.250)
        async_call(self.parent.barometer.get_calibration, None,
                   self.get_calibration_async,
                   self.parent.increase_error_count)
Beispiel #34
0
    def start(self):
        async_call(self.vc.get_configuration, None, self.get_configuration_async, self.increase_error_count)
        async_call(self.vc.get_calibration, None, self.get_calibration_async, self.increase_error_count)

        self.cbe_current.set_period(100)
        self.cbe_voltage.set_period(100)
        self.cbe_power.set_period(100)

        self.plot_widget_current.stop = False
        self.plot_widget_voltage.stop = False
        self.plot_widget_power.stop = False
Beispiel #35
0
    def start(self):
        async_call(self.idr.get_value, None, self.get_value_async,
                   self.increase_error_count)
        for channel in range(2):
            async_call(self.idr.get_channel_led_config,
                       channel,
                       self.get_channel_led_config_async,
                       self.increase_error_count,
                       pass_arguments_to_result_callback=True)

        self.monoflop.start()
Beispiel #36
0
 def update_start(self):
     async_call(self.dc.get_drive_mode, None, self.drive_mode_update,
                self.increase_error_count)
     async_call(self.dc.get_velocity, None, self.get_velocity_async,
                self.increase_error_count)
     async_call(self.dc.get_acceleration, None, self.get_acceleration_async,
                self.increase_error_count)
     async_call(self.dc.get_pwm_frequency, None,
                self.get_pwm_frequency_async, self.increase_error_count)
     async_call(self.dc.is_enabled, None, self.is_enabled_async,
                self.increase_error_count)
Beispiel #37
0
 def minimum_motor_voltage_button_clicked(self):
     qid = QInputDialog(self)
     qid.setInputMode(QInputDialog.IntInput)
     qid.setIntMinimum(0)
     qid.setIntMaximum(40000)
     qid.setIntStep(100)
     async_call(self.stepper.get_minimum_voltage, None, qid.setIntValue,
                self.increase_error_count)
     qid.intValueSelected.connect(self.minimum_motor_voltage_selected)
     qid.setLabelText("Choose minimum motor voltage in mV.")
     qid.open()
Beispiel #38
0
    def show(self):
        QDialog.show(self)

        self.cbe_voltage.set_period(100)
        self.cbe_current.set_period(100)
        self.cbe_power.set_period(100)

        async_call(self.parent.vc.get_calibration,
                   None,
                   self.get_calibration_async,
                   self.parent.increase_error_count)
Beispiel #39
0
    def start(self):
        async_call(self.color.get_configuration, None, self.get_configuration_async, self.increase_error_count)
        async_call(self.color.get_light, None, self.get_light_async, self.increase_error_count)

        self.cbe_color.set_period(50)
        self.cbe_illuminance.set_period(100)
        self.cbe_color_temperature.set_period(100)

        self.plot_widget.stop = False
        self.plot_widget_illuminance.stop = False
        self.plot_widget_color_temperature.stop = False
Beispiel #40
0
 def start(self):
     async_call(self.ao.get_voltage, None, self.new_voltage,
                self.increase_error_count)
     async_call(self.ao.get_current, None, self.new_current,
                self.increase_error_count)
     async_call(self.ao.get_enabled, None, self.get_enabled_async,
                self.increase_error_count)
     async_call(self.ao.get_configuration, None,
                self.get_configuration_async, self.increase_error_count)
     async_call(self.ao.get_out_led_config, None,
                self.get_out_led_config_async, self.increase_error_count)
    def refresh_program_list(self):
        def refresh_async():
            return get_lite_programs(self.session)

        def cb_success(programs):
            sorted_programs = {}

            for program in programs:
                first_upload = program.cast_custom_option_value(
                    'first_upload', int, 0)

                if first_upload in sorted_programs:
                    sorted_programs[first_upload][program.identifier] = program
                else:
                    sorted_programs[first_upload] = {
                        program.identifier: program
                    }

            for first_upload in sorted(sorted_programs.keys()):
                for identifier in sorted(sorted_programs[first_upload].keys()):
                    program = sorted_programs[first_upload][identifier]
                    language = program.cast_custom_option_value(
                        'language', unicode, '<unknown>')

                    try:
                        language = Constants.get_language_display_name(
                            language)
                    except:
                        pass

                    item = QTreeWidgetItem([
                        program.cast_custom_option_value(
                            'name', unicode, '<unknown>'), identifier, language
                    ])

                    self.tree_programs.addTopLevelItem(item)
                    item.setSelected(True)

            self.refresh_in_progress = False
            self.update_ui_state()
            self.tree_programs.setFocus()

        def cb_error(error):
            pass  # FIXME: report error

        self.refresh_in_progress = True
        self.update_ui_state()
        self.tree_programs.invisibleRootItem().takeChildren()

        async_call(refresh_async,
                   None,
                   cb_success,
                   cb_error,
                   report_exception=True)
Beispiel #42
0
    def render_leds(self, r, g, b, w):
        _, num_channels = self.chip_type_combobox.itemData(
            self.chip_type_combobox.currentIndex())

        if num_channels == 4:
            values = [value for rgbw in zip(r, g, b, w) for value in rgbw]
        else:
            values = [value for rgb in zip(r, g, b) for value in rgb]

        async_call(self.led_strip.set_led_values, (0, values), None,
                   self.increase_error_count)
Beispiel #43
0
 def motor_current_button_clicked(self):
     qid = QInputDialog(self)
     qid.setInputMode(QInputDialog.IntInput)
     qid.setIntMinimum(360)
     qid.setIntMaximum(1640)
     qid.setIntStep(100)
     async_call(self.silent_stepper_v2.get_motor_current, None,
                qid.setIntValue, self.increase_error_count)
     qid.intValueSelected.connect(self.motor_current_selected)
     qid.setLabelText("Choose motor current in mA.")
     qid.open()
Beispiel #44
0
    def start(self):
        async_call(self.sound_pressure_level.get_configuration, None,
                   self.get_configuration_async, self.increase_error_count)
        self.cbe_get_decibel.set_period(50)

        async_call(
            self.sound_pressure_level.set_spectrum_callback_configuration,
            (1, ), None, self.increase_error_count)
        self.sound_pressure_level.register_callback(
            self.sound_pressure_level.CALLBACK_SPECTRUM,
            self.qtcb_spectrum.emit)
Beispiel #45
0
    def start(self):
        self.config_direction = [None] * 16
        self.config_value = [None] * 16

        for channel in range(16):
            async_call(self.io.get_configuration, channel, self.get_configuration_async, self.increase_error_count,
                       pass_arguments_to_result_callback=True, expand_result_tuple_for_callback=True)

        self.cbe_value.set_period(50)

        self.monoflop.start()
Beispiel #46
0
    def start(self):
        async_call(self.dist.get_moving_average_configuration, None,
                   self.get_moving_average_configuration_async,
                   self.increase_error_count)
        async_call(self.dist.get_sensor_type, None, self.get_sensor_type_async,
                   self.increase_error_count)

        self.cbe_distance.set_period(10)
        self.cbe_analog_value.set_period(100)

        self.plot_widget.stop = False
Beispiel #47
0
    def update(self):
        for port in ['a', 'b']:
            for pin in range(8):
                if self.monoflop_active[port][pin]:

                    def get_lambda(port, pin):
                        return lambda x: self.update_async(port, pin, x)

                    async_call(self.io.get_port_monoflop, (port, pin),
                               get_lambda(port, pin),
                               self.increase_error_count)
Beispiel #48
0
    def connect_clicked(self):
        if self.ipcon.get_connection_state(
        ) == IPConnection.CONNECTION_STATE_DISCONNECTED:
            self.last_host = self.combo_host.currentText()
            self.setDisabled(True)
            self.button_connect.setText("Connecting...")

            async_call(self.ipcon.connect,
                       (self.last_host, self.spinbox_port.value()), None,
                       self.connect_error)
        else:
            self.do_disconnect()
Beispiel #49
0
                def cb_java_main_classes(result):
                    script_instance = script_instance_ref[0]

                    if script_instance != None:
                        aborted = script_instance.abort
                    else:
                        aborted = False

                    script_instance_ref[0] = None

                    def done():
                        progress.cancel()
                        self.combo_main_class.setEnabled(True)
                        self.completeChanged.emit()

                    if aborted:
                        done()
                        return

                    okay, message = check_script_result(result, decode_stderr=True)

                    if not okay:
                        self.label_main_class_error.setText('<b>Error:</b> ' + Qt.escape(message))
                        self.label_main_class_error.setVisible(True)
                        done()
                        return

                    def expand_async(data):
                        try:
                            main_classes = json.loads(zlib.decompress(buffer(data)).decode('utf-8'))

                            if not isinstance(main_classes, dict):
                                main_classes = {}
                        except:
                            main_classes = {}

                        return main_classes

                    def cb_expand_success(main_classes):
                        self.combo_main_class.clear()

                        for cls in sorted(main_classes.keys()):
                            self.combo_main_class.addItem(cls, main_classes[cls])

                        self.combo_main_class_checker.set_current_text(program.cast_custom_option_value('java.main_class', unicode, ''))
                        done()

                    def cb_expand_error():
                        self.label_main_class_error.setText('<b>Error:</b> Internal async error')
                        self.label_main_class_error.setVisible(True)
                        done()

                    async_call(expand_async, result.stdout, cb_expand_success, cb_expand_error)
Beispiel #50
0
    def start(self):
        async_call(self.rtc.get_offset, None, self.get_offset_async,
                   self.increase_error_count)

        if self.has_alarm:
            async_call(self.rtc.get_alarm,
                       None,
                       self.get_alarm_async,
                       self.increase_error_count,
                       expand_result_tuple_for_callback=True)

        self.cbe_date_time.set_period(50)
Beispiel #51
0
    def cb_alarm(self, year, month, day, hour, minute, second, centisecond,
                 weekday, interval):
        async_call(self.rtc.get_alarm,
                   None,
                   self.get_alarm_async,
                   self.increase_error_count,
                   expand_result_tuple_for_callback=True)

        self.list_alarms.addItem(
            '{0}-{1:02}-{2:02} T {3:02}:{4:02}:{5:02}.{6:02} {7}'.format(
                year, month, day, hour, minute, second, centisecond,
                WEEKDAY_BY_NUMBER[weekday]))
Beispiel #52
0
    def start(self):
        # Use response expected for write_line function, to make sure that the
        # data queue can't fill up while you move the slider around.
        self.write_line_response_expected = self.oled.get_response_expected(
            self.oled.FUNCTION_WRITE_LINE)
        self.oled.set_response_expected(self.oled.FUNCTION_WRITE_LINE, True)

        async_call(self.oled.get_display_configuration, None,
                   self.get_display_configuration_async,
                   self.increase_error_count)
        async_call(self.oled.read_pixels, (0, 0, 127, 63),
                   self.read_pixels_async, self.increase_error_count)
Beispiel #53
0
 def output_voltage_button_clicked(self):
     qid = QInputDialog(self)
     qid.setInputMode(QInputDialog.IntInput)
     qid.setIntMinimum(2000)
     qid.setIntMaximum(9000)
     qid.setIntStep(100)
     async_call(self.servo.get_output_voltage, None, qid.setIntValue,
                self.increase_error_count)
     qid.intValueSelected.connect(self.output_voltage_selected)
     qid.setLabelText("Choose Output Voltage in mV.")
     #                         "<font color=red>Setting this too high can destroy your servo.</font>")
     qid.open()
Beispiel #54
0
    def text_clicked(self):
        line = int(self.line_combo.currentText())
        position = int(self.pos_combo.currentText())
        text = self.text_edit.text()

        if self.has_custom_character:
            for i in range(8):
                text = text.replace('\\' + str(i), chr(i + 8))

        async_call(self.lcd.write_line,
                   (line, position, unicode_to_ks0066u(text)), None,
                   self.increase_error_count)
Beispiel #55
0
    def reconfigure_everything(self):
        for i in range(4):
            self.groups[i].clear()
            self.groups[i].addItem('Off')
            for j in range(4):
                if self.available_ports & (1 << j):
                    item = 'Port ' + chr(ord('A') + j)
                    self.groups[i].addItem(item)

        async_call(self.ido4.get_group, None,
                   self.reconfigure_everything_async1,
                   self.increase_error_count)
Beispiel #56
0
    def start(self):
        async_call(self.re.get_count, False, self.cb_count,
                   self.increase_error_count)

        if self.firmware_version >= (2, 0, 2):
            # firmware 2.0.2 fixed the is_pressed return value, it was inverted before
            async_call(self.re.is_pressed, None, self.encoder_knob.set_pressed,
                       self.increase_error_count)

        self.cbe_count.set_period(25)

        self.plot_widget.stop = False
Beispiel #57
0
        def cb_walk(result):
            okay, message = check_script_result(result, decode_stderr=True)

            if not okay:
                self.label_error.setText('<b>Error:</b> ' +
                                         html.escape(message))
                self.label_error.setVisible(True)
                self.refresh_files_done()
                return

            self.label_error.setVisible(False)

            def expand_async(data):
                try:
                    walk = json.loads(
                        zlib.decompress(memoryview(data)).decode('utf-8'))
                except:
                    walk = None

                if walk == None or not isinstance(walk, dict):
                    available_files = []
                    available_directories = []
                    walk = None
                else:
                    available_files, available_directories = expand_walk_to_lists(
                        walk)

                return walk, available_files, available_directories

            def cb_expand_success(result):
                walk, available_files, available_directories = result

                self.available_files = available_files
                self.available_directories = available_directories

                if walk != None:
                    expand_walk_to_model(walk, self.tree_files_model,
                                         self.folder_icon, self.file_icon)
                else:
                    self.label_error.setText(
                        '<b>Error:</b> Received invalid data')
                    self.label_error.setVisible(True)

                self.tree_files.header().setSortIndicator(0, Qt.AscendingOrder)
                self.refresh_files_done()

            def cb_expand_error():
                self.label_error.setText('<b>Error:</b> Internal async error')
                self.label_error.setVisible(True)
                self.refresh_files_done()

            async_call(expand_async, result.stdout, cb_expand_success,
                       cb_expand_error)
    def monoflop_pin_changed(self):
        try:
            pin = int(self.monoflop_pin.currentText().replace('Pin ', ''))
        except ValueError:
            return

        if self.monoflop_pending[pin]:
            async_call(self.iqr.get_monoflop, pin, self.monoflop_pin_changed_async, self.increase_error_count)
            self.monoflop_time.setEnabled(False)
        else:
            self.monoflop_time.setValue(self.monoflop_time_before[pin])
            self.monoflop_time.setEnabled(True)
Beispiel #59
0
 def minimum_voltage_button_clicked(self):
     qid = QInputDialog(self)
     qid.setWindowTitle('Servo Brick')
     qid.setInputMode(QInputDialog.IntInput)
     qid.setIntMinimum(5000)
     qid.setIntMaximum(0xFFFF)
     qid.setIntStep(100)
     async_call(self.servo.get_minimum_voltage, None, qid.setIntValue,
                self.increase_error_count)
     qid.intValueSelected.connect(self.minimum_voltage_selected)
     qid.setLabelText("Choose Minimum Servo Voltage in mV:")
     qid.open()
Beispiel #60
0
    def update_sensor(self):
        if self.combo_identifier_sensor.isEnabled():
            try:
                identifier = int(self.combo_identifier_sensor.currentText())
            except:
                return

            async_call(self.outdoor_weather.get_sensor_data, identifier, self.get_sensor_data_async, self.increase_error_count)
        else:
            self.label_temperature_sensor.setText('---')
            self.label_humidity_sensor.setText('---')
            self.label_last_change_sensor.setText('---')