def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletDualButtonV2, *args) self.setupUi(self) self.button = self.device self.cbe_button_state = CallbackEmulator(self.button.get_button_state, None, self.cb_button_state, self.increase_error_count, expand_result_tuple_for_callback=True) self.cbe_led_state = CallbackEmulator(self.button.get_led_state, None, self.cb_led_state, self.increase_error_count, expand_result_tuple_for_callback=True) self.led_r = BrickletDualButtonV2.LED_STATE_OFF self.led_l = BrickletDualButtonV2.LED_STATE_OFF self.button_r = BrickletDualButtonV2.BUTTON_STATE_RELEASED self.button_l = BrickletDualButtonV2.BUTTON_STATE_RELEASED self.button_led_on_button_r.clicked.connect(self.on_button_r_clicked) self.button_led_on_button_l.clicked.connect(self.on_button_l_clicked) self.button_led_off_button_r.clicked.connect(self.off_button_r_clicked) self.button_led_off_button_l.clicked.connect(self.off_button_l_clicked) self.button_toggle_button_r.clicked.connect(self.toggle_button_r_clicked) self.button_toggle_button_l.clicked.connect(self.toggle_button_l_clicked) self.count = 0
class DistanceUSV2(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletDistanceUSV2, *args) self.dist = self.device self.cbe_distance = CallbackEmulator(self.dist.get_distance, None, self.cb_distance, self.increase_error_count) self.current_distance = CurveValueWrapper() plots = [('Distance', Qt.red, self.current_distance, '{:.1f} cm'.format)] self.plot_widget = PlotWidget('Distance [cm]', plots, y_resolution=1.0) self.update_rate_label = QLabel('Update Rate:') self.update_rate_combo = QComboBox() self.update_rate_combo.addItem(" 2 Hz") self.update_rate_combo.addItem("10 Hz") self.update_rate_combo.currentIndexChanged.connect(self.new_update_rate) hlayout = QHBoxLayout() hlayout.addWidget(self.update_rate_label) hlayout.addWidget(self.update_rate_combo) hlayout.addStretch() layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addLayout(hlayout) def new_update_rate(self): update_rate = self.update_rate_combo.currentIndex() self.dist.set_update_rate(update_rate) def get_update_rate_async(self, update_rate): self.update_rate_combo.setCurrentIndex(update_rate) def start(self): async_call(self.dist.get_update_rate, None, self.get_update_rate_async, self.increase_error_count) self.cbe_distance.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_distance.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletDistanceUSV2.DEVICE_IDENTIFIER def cb_distance(self, distance): self.current_distance.value = distance / 10.0
class COMCUPluginBase(PluginBase): def __init__(self, device_class, ipcon, device_info, override_base_name=None): PluginBase.__init__(self, device_class, ipcon, device_info, override_base_name) self.start_called = False self.has_comcu = True self.cbe_bootloader_mode = CallbackEmulator(self.device.get_bootloader_mode, self.cb_bootloader_mode, self.increase_error_count) def cb_bootloader_mode(self, mode): if not self.start_called and mode == self.device.BOOTLOADER_MODE_FIRMWARE and self.isVisible(): self.start_called = True self.start() elif mode == self.device.BOOTLOADER_MODE_BOOTLOADER and self.isVisible(): self.stop() self.hide() self.widget_bootloader.show() elif mode == self.device.BOOTLOADER_MODE_FIRMWARE and not self.isVisible(): self.widget_bootloader.hide() self.show() self.start_called = True self.start() def start_comcu(self): self.start_called = False async_call(self.device.get_bootloader_mode, None, self.cb_bootloader_mode, self.increase_error_count) self.cbe_bootloader_mode.set_period(1000) def stop_comcu(self): self.cbe_bootloader_mode.set_period(0) self.stop()
class CO2V2(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletCO2V2, *args) self.co2 = self.device self.cbe_all_values = CallbackEmulator(self.co2.get_all_values, None, self.cb_all_values, self.increase_error_count) self.current_co2 = CurveValueWrapper() # int, ppm self.current_temperature = CurveValueWrapper() # float, °C self.current_humidity = CurveValueWrapper() # float, %RH plots_co2 = [('CO2', Qt.red, self.current_co2, '{} PPM'.format)] self.plot_widget_co2 = PlotWidget('CO2 [PPM]', plots_co2, y_resolution=1.0) plots_temperature = [('Temperature', Qt.red, self.current_temperature, '{} °C'.format)] self.plot_widget_temperature = PlotWidget('Temperature [°C]', plots_temperature, y_resolution=0.01) plots_humidity = [('Relative Humidity', Qt.red, self.current_humidity, '{} %RH'.format)] self.plot_widget_humidity = PlotWidget('Relative Humidity [%RH]', plots_humidity, y_resolution=0.01) layout_plot1 = QHBoxLayout() layout_plot1.addWidget(self.plot_widget_co2) layout_plot2 = QHBoxLayout() layout_plot2.addWidget(self.plot_widget_temperature) layout_plot2.addWidget(self.plot_widget_humidity) layout_main = QVBoxLayout(self) layout_main.addLayout(layout_plot1) layout_main.addLayout(layout_plot2) def cb_all_values(self, values): self.current_co2.value = values.co2_concentration self.current_temperature.value = values.temperature / 100.0 self.current_humidity.value = values.humidity / 100.0 def start(self): self.cbe_all_values.set_period(250) self.plot_widget_co2.stop = False self.plot_widget_temperature.stop = False self.plot_widget_humidity.stop = False def stop(self): self.cbe_all_values.set_period(0) self.plot_widget_co2.stop = True self.plot_widget_temperature.stop = True self.plot_widget_humidity.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletCO2V2.DEVICE_IDENTIFIER
def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletOutdoorWeather, *args) self.outdoor_weather = self.device self.changing = False self.setupUi(self) self.cbe_identifiers_station = CallbackEmulator(self.outdoor_weather.get_station_identifiers, None, self.cb_station_identifiers, self.increase_error_count) self.cbe_identifiers_sensor = CallbackEmulator(self.outdoor_weather.get_sensor_identifiers, None, self.cb_sensor_identifiers, self.increase_error_count) self.combo_identifier_station.currentIndexChanged.connect(self.update_station) self.combo_identifier_sensor.currentIndexChanged.connect(self.update_sensor) self.identifiers_station = [] self.identifiers_sensor = [] self.data_timer_station = QTimer(self) self.data_timer_station.timeout.connect(self.update_station) self.data_timer_sensor = QTimer(self) self.data_timer_sensor.timeout.connect(self.update_sensor)
def __init__(self, parent): QDialog.__init__(self, parent, get_modeless_dialog_flags()) self.parent = parent self.setupUi(self) # Synced air pressure, altitude and temperature. Updated with callbacks. self.air_pressure = 0 self.altitude = 0 self.temperature = 0 self.btn_cal_remove.clicked.connect(self.btn_cal_remove_clicked) self.btn_cal_calibrate.clicked.connect(self.btn_cal_calibrate_clicked) self.cbe_air_pressure = CallbackEmulator(self.parent.barometer.get_air_pressure, None, self.cb_air_pressure, self.parent.increase_error_count) self.cbe_altitude = CallbackEmulator(self.parent.barometer.get_altitude, None, self.cb_altitude, self.parent.increase_error_count) self.cbe_temperature = CallbackEmulator(self.parent.barometer.get_temperature, None, self.cb_temperature, self.parent.increase_error_count)
def __init__(self, *args): PluginBase.__init__(self, BrickletVoltageCurrent, *args) self.setupUi(self) self.vc = self.device self.cbe_current = CallbackEmulator(self.vc.get_current, self.cb_current, self.increase_error_count) self.cbe_voltage = CallbackEmulator(self.vc.get_voltage, self.cb_voltage, self.increase_error_count) self.cbe_power = CallbackEmulator(self.vc.get_power, self.cb_power, self.increase_error_count) self.current_voltage = None # float, V self.current_current = None # float, A self.current_power = None # float, W plots_voltage = [("Voltage", Qt.red, lambda: self.current_voltage, format_voltage)] plots_current = [("Current", Qt.blue, lambda: self.current_current, format_current)] plots_power = [("Power", Qt.darkGreen, lambda: self.current_power, format_power)] self.plot_widget_voltage = PlotWidget("Voltage [V]", plots_voltage, self.button_clear_graphs) self.plot_widget_current = PlotWidget("Current [A]", plots_current, self.button_clear_graphs) self.plot_widget_power = PlotWidget("Power [W]", plots_power, self.button_clear_graphs) self.save_cal_button.clicked.connect(self.save_cal_clicked) self.save_conf_button.clicked.connect(self.save_conf_clicked) hlayout = QHBoxLayout() hlayout.addWidget(self.plot_widget_voltage) hlayout.addWidget(self.plot_widget_current) hlayout.addWidget(self.plot_widget_power) self.main_layout.insertLayout(0, hlayout)
def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletHallEffectV2, *args) self.setupUi(self) self.hf = self.device self.cbe_magnetic_flux_density = CallbackEmulator(self.hf.get_magnetic_flux_density, None, self.cb_magnetic_flux_density, self.increase_error_count) self.cbe_counter = CallbackEmulator(self.get_counter, False, self.cb_counter, self.increase_error_count) self.current_magnetic_flux_density = CurveValueWrapper() plots = [('Magnetic Flux Density', Qt.red, self.current_magnetic_flux_density, '{} µT'.format)] self.plot_widget = PlotWidget('Magnetic Flux Density [µT]', plots, y_resolution=1.0) self.button_reset.clicked.connect(self.button_reset_clicked) self.spinbox_low.editingFinished.connect(self.new_config) self.spinbox_high.editingFinished.connect(self.new_config) self.spinbox_debounce.editingFinished.connect(self.new_config) self.main_vert_layout.insertWidget(0, self.plot_widget)
class Tilt(PluginBase): def __init__(self, *args): super().__init__(BrickletTilt, *args) self.tilt = self.device self.cbe_tilt_state = CallbackEmulator(self.tilt.get_tilt_state, None, self.cb_tilt_state, self.increase_error_count) self.label = QLabel("Closed") self.closed_pixmap = load_masked_pixmap('plugin_system/plugins/tilt/tilt_closed.bmp') self.open_pixmap = load_masked_pixmap('plugin_system/plugins/tilt/tilt_open.bmp') self.closed_vibrationg_pixmap = load_masked_pixmap('plugin_system/plugins/tilt/tilt_closed_vibrating.bmp') self.image_label = QLabel("") self.image_label.setPixmap(self.closed_pixmap) layout = QVBoxLayout(self) layout.addStretch() h_layout1 = QHBoxLayout() h_layout1.addStretch() h_layout1.addWidget(self.label) h_layout1.addStretch() h_layout2 = QHBoxLayout() h_layout2.addStretch() h_layout2.addWidget(self.image_label) h_layout2.addStretch() layout.addLayout(h_layout1) layout.addLayout(h_layout2) layout.addStretch() def cb_tilt_state(self, state): if state == 0: self.label.setText("Closed") self.image_label.setPixmap(self.closed_pixmap) elif state == 1: self.label.setText("Open") self.image_label.setPixmap(self.open_pixmap) elif state == 2: self.label.setText("Closed Vibrating") self.image_label.setPixmap(self.closed_vibrationg_pixmap) def start(self): self.cbe_tilt_state.set_period(25) def stop(self): self.cbe_tilt_state.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletTilt.DEVICE_IDENTIFIER
class HeartRate(PluginBase): qtcb_beat_state_changed = pyqtSignal(int) def __init__(self, *args): super().__init__(BrickletHeartRate, *args) self.hr = self.device self.cbe_heart_rate = CallbackEmulator(self.hr.get_heart_rate, None, self.cb_heart_rate, self.increase_error_count) # FIXME: add beat state getter to Heart Rate Bricklet API self.qtcb_beat_state_changed.connect(self.cb_beat_state_changed) self.hr.register_callback(self.hr.CALLBACK_BEAT_STATE_CHANGED, self.qtcb_beat_state_changed.emit) self.heart_white_bitmap = load_masked_pixmap('plugin_system/plugins/heart_rate/heart_white_small.bmp') self.heart_red_bitmap = load_masked_pixmap('plugin_system/plugins/heart_rate/heart_red_small.bmp') self.heart_icon = QLabel() self.heart_icon.setPixmap(self.heart_white_bitmap) self.current_heart_rate = CurveValueWrapper() plots = [('Heart Rate', Qt.red, self.current_heart_rate, '{} BPM'.format)] self.plot_widget = PlotWidget('Heart Rate [BPM]', plots, extra_key_widgets=[self.heart_icon], y_resolution=1.0) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): async_call(self.hr.enable_beat_state_changed_callback, None, None, self.increase_error_count) self.cbe_heart_rate.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_heart_rate.set_period(0) async_call(self.hr.disable_beat_state_changed_callback, None, None, self.increase_error_count) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletHeartRate.DEVICE_IDENTIFIER def cb_heart_rate(self, heart_rate): self.current_heart_rate.value = heart_rate def cb_beat_state_changed(self, state): if state == self.hr.BEAT_STATE_RISING: self.heart_icon.setPixmap(self.heart_red_bitmap) else: self.heart_icon.setPixmap(self.heart_white_bitmap)
def __init__(self, *args): super().__init__(BrickletIndustrialDualAnalogIn, *args) self.analog_in = self.device # the firmware version of a EEPROM Bricklet can (under common circumstances) # not change during the lifetime of an EEPROM Bricklet plugin. therefore, # it's okay to make final decisions based on it here self.has_fixed_calibration = self.firmware_version >= (2, 0, 1) self.cbe_voltage0 = CallbackEmulator(self.analog_in.get_voltage, 0, self.cb_voltage, self.increase_error_count, pass_arguments_to_result_callback=True) self.cbe_voltage1 = CallbackEmulator(self.analog_in.get_voltage, 1, self.cb_voltage, self.increase_error_count, pass_arguments_to_result_callback=True) self.calibration = None self.sample_rate_label = QLabel('Sample Rate:') self.sample_rate_combo = QComboBox() self.sample_rate_combo.addItem('976 Hz') self.sample_rate_combo.addItem('488 Hz') self.sample_rate_combo.addItem('244 Hz') self.sample_rate_combo.addItem('122 Hz') self.sample_rate_combo.addItem('61 Hz') self.sample_rate_combo.addItem('4 Hz') self.sample_rate_combo.addItem('2 Hz') self.sample_rate_combo.addItem('1 Hz') self.current_voltage = [CurveValueWrapper(), CurveValueWrapper()] # float, V self.calibration_button = QPushButton('Calibration...') self.sample_rate_combo.currentIndexChanged.connect(self.sample_rate_combo_index_changed) self.calibration_button.clicked.connect(self.calibration_button_clicked) plots = [('Channel 0', Qt.red, self.current_voltage[0], format_voltage), ('Channel 1', Qt.blue, self.current_voltage[1], format_voltage)] self.plot_widget = PlotWidget('Voltage [V]', plots, y_resolution=0.001) hlayout = QHBoxLayout() hlayout.addWidget(self.sample_rate_label) hlayout.addWidget(self.sample_rate_combo) hlayout.addStretch() hlayout.addWidget(self.calibration_button) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout)
def __init__(self, *args): super().__init__(BrickletUVLightV2, *args) self.uv_light = self.device self.cbe_uva = CallbackEmulator(self.uv_light.get_uva, None, self.cb_uva, self.increase_error_count) self.cbe_uvb = CallbackEmulator(self.uv_light.get_uvb, None, self.cb_uvb, self.increase_error_count) self.cbe_uvi = CallbackEmulator(self.uv_light.get_uvi, None, self.cb_uvi, self.increase_error_count) self.index_label = IndexLabel(' UVI: ? ') self.index_label.setText('0.0') self.current_uva = CurveValueWrapper() self.current_uvb = CurveValueWrapper() plots = [('UVA', Qt.red, self.current_uva, '{} mW/m²'.format), ('UVB', Qt.darkGreen, self.current_uvb, '{} mW/m²'.format)] self.plot_widget = PlotWidget('UV [mW/m²]', plots, extra_key_widgets=[self.index_label], y_resolution=0.1) self.time_label = QLabel('Integration Time:') self.time_combo = QComboBox() self.time_combo.addItem("50 ms", BrickletUVLightV2.INTEGRATION_TIME_50MS) self.time_combo.addItem("100 ms", BrickletUVLightV2.INTEGRATION_TIME_100MS) self.time_combo.addItem("200 ms", BrickletUVLightV2.INTEGRATION_TIME_200MS) self.time_combo.addItem("400 ms", BrickletUVLightV2.INTEGRATION_TIME_400MS) self.time_combo.addItem("800 ms", BrickletUVLightV2.INTEGRATION_TIME_800MS) self.time_combo.currentIndexChanged.connect(self.new_config) self.saturation_label = QLabel('Sensor is saturated, choose a shorter integration time!') self.saturation_label.setStyleSheet('QLabel { color : red }') self.saturation_label.hide() hlayout = QHBoxLayout() hlayout.addWidget(self.time_label) hlayout.addWidget(self.time_combo) hlayout.addStretch() hlayout.addWidget(self.saturation_label) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout)
def __init__(self, *args): PluginBase.__init__(self, BrickletIndustrialDual020mA, *args) self.dual020 = self.device self.str_connected = 'Sensor {0} is currently <font color="green">connected</font>' self.str_not_connected = 'Sensor {0} is currently <font color="red">not connected</font>' self.cbe_current0 = CallbackEmulator(functools.partial(self.dual020.get_current, 0), functools.partial(self.cb_current, 0), self.increase_error_count) self.cbe_current1 = CallbackEmulator(functools.partial(self.dual020.get_current, 1), functools.partial(self.cb_current, 1), self.increase_error_count) self.current_label = [CurrentLabel(), CurrentLabel()] self.sample_rate_label1 = QLabel('Sample Rate:') self.sample_rate_combo = QComboBox() self.sample_rate_combo.addItem('240') self.sample_rate_combo.addItem('60') self.sample_rate_combo.addItem('15') self.sample_rate_combo.addItem('4') self.sample_rate_label2 = QLabel('Samples per second') self.connected_label = [QLabel(self.str_not_connected.format(0)), QLabel(self.str_not_connected.format(1))] self.current_value = [None, None] self.sample_rate_combo.currentIndexChanged.connect(self.sample_rate_combo_index_changed) plot_list = [['Sensor 0', Qt.red, self.get_current_value0], ['Sensor 1', Qt.blue, self.get_current_value1]] self.plot_widget = PlotWidget('Current [mA]', plot_list) layout_h = QHBoxLayout() layout_h.addWidget(QLabel("Sensor 0: ")) layout_h.addWidget(self.current_label[0]) layout_h.addStretch() layout_h.addWidget(self.connected_label[0]) layout_h2 = QHBoxLayout() layout_h2.addWidget(QLabel("Sensor 1: ")) layout_h2.addWidget(self.current_label[1]) layout_h2.addStretch() layout_h2.addWidget(self.connected_label[1]) layout_h3 = QHBoxLayout() layout_h3.addWidget(self.sample_rate_label1) layout_h3.addWidget(self.sample_rate_combo) layout_h3.addWidget(self.sample_rate_label2) layout_h3.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addLayout(layout_h2) layout.addWidget(self.plot_widget) layout.addLayout(layout_h3)
class UVLight(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletUVLight, *args) self.uv_light = self.device self.cbe_uv_light = CallbackEmulator(self.uv_light.get_uv_light, self.cb_uv_light, self.increase_error_count) self.index_label = IndexLabel('UV Index: ') self.current_uv_light = None plots = [('UV Light', Qt.red, lambda: self.current_uv_light, u'{} µW/cm²'.format)] self.plot_widget = PlotWidget(u'UV Light [µW/cm²]', plots, extra_key_widgets=[self.index_label]) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): async_call(self.uv_light.get_uv_light, None, self.cb_uv_light, self.increase_error_count) self.cbe_uv_light.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_uv_light.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'uv_light' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletUVLight.DEVICE_IDENTIFIER def cb_uv_light(self, uv_light): self.current_uv_light = uv_light index = round(uv_light/250.0, 1) self.index_label.setText(unicode(index)) if index < 2.5: color = 'green' elif index < 5.5: color = 'yellow' elif index < 7.5: color = 'orange' elif index < 10.5: color = 'red' else: color = 'magenta' self.index_label.setStyleSheet('QLabel {{ color : {0} }}'.format(color))
class LinearPoti(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletLinearPoti, *args) self.lp = self.device self.cbe_position = CallbackEmulator(self.lp.get_position, self.cb_position, self.increase_error_count) self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 100) self.position_label = PositionLabel('Position: ') self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Position', plot_list) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(self.position_label) layout_h.addWidget(self.slider) layout_h.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addWidget(self.plot_widget) def start(self): async_call(self.lp.get_position, None, self.cb_position, self.increase_error_count) self.cbe_position.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_position.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'linear_poti' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLinearPoti.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_position(self, position): self.current_value = position self.slider.setValue(position) self.position_label.setText(str(position))
class Isolator(COMCUPluginBase, Ui_Isolator): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletIsolator, *args) self.setupUi(self) self.isolator = self.device self.cbe_statistics = CallbackEmulator(self.isolator.get_statistics, None, self.cb_statistics, self.increase_error_count) self.last_connected = None def cb_statistics(self, statistics): self.label_messages_from_brick.setText(str(statistics.messages_from_brick)) self.label_messages_from_bricklet.setText(str(statistics.messages_from_bricklet)) try: name = infos.get_info(statistics.connected_bricklet_uid).plugin.device_class.DEVICE_DISPLAY_NAME except: name = None if statistics.connected_bricklet_uid != '' and name != None: self.label_isolated_bricklet.setText('<b>{0}</b> with UID "{1}"'.format(name, statistics.connected_bricklet_uid)) self.button_bricklet.setText('Open {0}'.format(name)) if self.last_connected != statistics.connected_bricklet_uid: self.last_connected = statistics.connected_bricklet_uid try: self.button_bricklet.clicked.disconnect() except: pass self.button_bricklet.clicked.connect(lambda: get_main_window().show_plugin(statistics.connected_bricklet_uid)) self.button_bricklet.setEnabled(True) else: self.label_isolated_bricklet.setText('Unknown Bricklet (Did you connect a Bricklet?)') self.button_bricklet.setText('Open Bricklet') self.button_bricklet.setEnabled(False) def start(self): self.cbe_statistics.set_period(200) def stop(self): self.cbe_statistics.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletIsolator.DEVICE_IDENTIFIER
def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletGPSV2, *args) self.setupUi(self) self.gps = self.device self.cbe_universal = CallbackEmulator(self.get_universal, self.cb_universal, self.increase_error_count) self.cbe_universal_gps = CallbackEmulator( self.get_universal_gps, self.cb_universal_gps, self.increase_error_count ) self.cbe_universal_glo = CallbackEmulator( self.get_universal_glo, self.cb_universal_glo, self.increase_error_count ) self.qtcb_pps.connect(self.cb_pps) self.gps.register_callback(self.gps.CALLBACK_PULSE_PER_SECOND, self.qtcb_pps.emit) self.format_combobox.currentIndexChanged.connect(self.format_changed) self.show_pos.clicked.connect(self.show_pos_clicked) self.hot_start.clicked.connect(lambda: self.restart_clicked(0)) self.warm_start.clicked.connect(lambda: self.restart_clicked(1)) self.cold_start.clicked.connect(lambda: self.restart_clicked(2)) self.factory_reset.clicked.connect(lambda: self.restart_clicked(3)) self.had_fix = False self.last_lat = 0 self.last_ns = "U" self.last_long = 0 self.last_ew = "U" self.gps_counter = 0 self.glo_counter = 0 self.gps_model = QStandardItemModel(32, 3, self) self.gps_table.setModel(self.gps_model) self.gps_model.setHorizontalHeaderItem(0, QStandardItem(u"Elevation (°)")) self.gps_model.setHorizontalHeaderItem(1, QStandardItem(u"Azimuth (°)")) self.gps_model.setHorizontalHeaderItem(2, QStandardItem(u"SNR (dB)")) for i in range(32): self.gps_model.setVerticalHeaderItem(i, QStandardItem(u"Sat " + str(i + 1))) self.gps_table.horizontalHeader().setResizeMode(QHeaderView.Stretch) self.glo_model = QStandardItemModel(32, 3, self) self.glo_table.setModel(self.glo_model) self.glo_model.setHorizontalHeaderItem(0, QStandardItem(u"Elevation (°)")) self.glo_model.setHorizontalHeaderItem(1, QStandardItem(u"Azimuth (°)")) self.glo_model.setHorizontalHeaderItem(2, QStandardItem(u"SNR (dB)")) for i in range(32): self.glo_model.setVerticalHeaderItem(i, QStandardItem(u"Sat " + str(i + 1 + 64))) self.glo_table.horizontalHeader().setResizeMode(QHeaderView.Stretch)
class CO2(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletCO2, *args) self.co2 = self.device self.cbe_co2_concentration = CallbackEmulator(self.co2.get_co2_concentration, self.cb_co2_concentration, self.increase_error_count) self.co2_concentration_label = CO2ConcentrationLabel('CO2 Concentration: ') self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('CO2 Concentration [ppm]', plot_list) layout_h2 = QHBoxLayout() layout_h2.addStretch() layout_h2.addWidget(self.co2_concentration_label) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h2) layout.addWidget(self.plot_widget) def start(self): async_call(self.co2.get_co2_concentration, None, self.cb_co2_concentration, self.increase_error_count) self.cbe_co2_concentration.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_co2_concentration.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'co2' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletCO2.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_co2_concentration(self, co2_concentration): self.current_value = co2_concentration self.co2_concentration_label.setText(str(co2_concentration))
class Temperature(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletTemperature, *args) self.tem = self.device self.cbe_temperature = CallbackEmulator(self.tem.get_temperature, self.cb_temperature, self.increase_error_count) self.temperature_label = TemperatureLabel() self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Temperature [%cC]' % 0xB0, plot_list) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(self.temperature_label) layout_h.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addWidget(self.plot_widget) def start(self): async_call(self.tem.get_temperature, None, self.cb_temperature, self.increase_error_count) self.cbe_temperature.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_temperature.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'temperature' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletTemperature.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_temperature(self, temperature): self.current_value = temperature/100.0 self.temperature_label.setText(str(temperature/100.0))
class Humidity(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletHumidity, *args) self.hum = self.device self.cbe_humidity = CallbackEmulator(self.hum.get_humidity, self.cb_humidity, self.increase_error_count) self.humidity_label = HumidityLabel('Humidity: ') self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Relative Humidity [%RH]', plot_list) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(self.humidity_label) layout_h.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addWidget(self.plot_widget) def start(self): async_call(self.hum.get_humidity, None, self.cb_humidity, self.increase_error_count) self.cbe_humidity.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_humidity.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'humidity' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletHumidity.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_humidity(self, humidity): self.current_value = humidity/10.0 self.humidity_label.setText(str(humidity/10.0))
class DistanceUS(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletDistanceUS, *args) self.dist = self.device self.cbe_distance = CallbackEmulator(self.dist.get_distance_value, self.cb_distance, self.increase_error_count) self.distance_label = DistanceLabel('Distance Value: ') self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Distance', plot_list) layout_h1 = QHBoxLayout() layout_h1.addStretch() layout_h1.addWidget(self.distance_label) layout_h1.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h1) layout.addWidget(self.plot_widget) def start(self): async_call(self.dist.get_distance_value, None, self.cb_distance, self.increase_error_count) self.cbe_distance.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_distance.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'distance_us' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletDistanceUS.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_distance(self, distance): self.current_value = distance self.distance_label.setText(str(distance))
class DustDetector(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletDustDetector, *args) self.dust_detector = self.device self.cbe_dust_density = CallbackEmulator(self.dust_detector.get_dust_density, self.cb_dust_density, self.increase_error_count) self.dust_density_label = DustDensityLabel() self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget(u'Dust Density [µg/m³]', plot_list) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(self.dust_density_label) layout_h.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addWidget(self.plot_widget) def get_current_value(self): return self.current_value def cb_dust_density(self, dust_density): self.current_value = dust_density self.dust_density_label.setText(str(dust_density)) def start(self): async_call(self.dust_detector.get_dust_density, None, self.cb_dust_density, self.increase_error_count) self.cbe_dust_density.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_dust_density.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'dust_detector' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletDustDetector.DEVICE_IDENTIFIER
def __init__(self, *args): super().__init__(BrickletDistanceIRV2, *args) self.dist = self.device self.cbe_distance = CallbackEmulator(self.dist.get_distance, None, self.cb_distance, self.increase_error_count) self.cbe_analog_value = CallbackEmulator(self.dist.get_analog_value, None, self.cb_analog_value, self.increase_error_count) self.analog_label = AnalogLabel('Analog Value:') hlayout = QHBoxLayout() self.average_label = QLabel('Moving Average Length:') self.average_spin = QSpinBox() self.average_spin.setMinimum(1) self.average_spin.setMaximum(1000) self.average_spin.setSingleStep(1) self.average_spin.setValue(25) self.average_spin.editingFinished.connect(self.average_spin_finished) self.sensor_label = QLabel('Sensor Type:') self.sensor_combo = QComboBox() self.sensor_combo.addItem('2Y0A41 (4-30cm)') self.sensor_combo.addItem('2Y0A21 (10-80cm)') self.sensor_combo.addItem('2Y0A02 (20-150cm)') self.sensor_combo.currentIndexChanged.connect(self.sensor_combo_changed) hlayout.addWidget(self.average_label) hlayout.addWidget(self.average_spin) hlayout.addStretch() hlayout.addWidget(self.sensor_label) hlayout.addWidget(self.sensor_combo) self.current_distance = CurveValueWrapper() # float, cm plots = [('Distance', Qt.red, self.current_distance, '{} cm'.format)] self.plot_widget = PlotWidget('Distance [cm]', plots, extra_key_widgets=[self.analog_label], y_resolution=0.1) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout)
class Voltage(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletVoltage, *args) self.vol = self.device self.cbe_voltage = CallbackEmulator(self.vol.get_voltage, self.cb_voltage, self.increase_error_count) self.voltage_label = CurrentLabel("Voltage: ") self.current_value = None plot_list = [["", Qt.red, self.get_current_value]] self.plot_widget = PlotWidget("Voltage [mV]", plot_list) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(self.voltage_label) layout_h.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addWidget(self.plot_widget) def start(self): async_call(self.vol.get_voltage, None, self.cb_voltage, self.increase_error_count) self.cbe_voltage.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_voltage.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return "voltage" @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletVoltage.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_voltage(self, voltage): self.current_value = voltage self.voltage_label.setText(str(voltage / 1000.0))
class RotaryPoti(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletRotaryPoti, *args) self.rp = self.device self.cbe_position = CallbackEmulator(self.rp.get_position, self.cb_position, self.increase_error_count) self.position_knob = KnobWidget(self) self.position_knob.setFocusPolicy(Qt.NoFocus) self.position_knob.set_total_angle(300) self.position_knob.set_range(-150, 150) self.position_knob.set_scale(30, 3) self.position_knob.set_knob_radius(25) self.current_position = None plots = [('Position', Qt.red, lambda: self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, curve_motion_granularity=40, update_interval=0.025) layout = QHBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(self.position_knob) def start(self): async_call(self.rp.get_position, None, self.cb_position, self.increase_error_count) self.cbe_position.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_position.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'rotary_poti' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletRotaryPoti.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position = position self.position_knob.set_value(position)
def __init__(self, *args): PluginBase.__init__(self, BrickletDistanceIR, *args) self.dist = self.device self.cbe_distance = CallbackEmulator(self.dist.get_distance, self.cb_distance, self.increase_error_count) self.cbe_analog_value = CallbackEmulator(self.dist.get_analog_value, self.cb_analog_value, self.increase_error_count) self.analog_value = 0 self.distance_label = DistanceLabel('Distance: ') self.analog_label = AnalogLabel('Analog value: ') self.sample_layout = QHBoxLayout() self.sample_label = QLabel('Sample Points:') self.sample_edit = QLineEdit() self.sample_file = QPushButton("Browse") self.sample_save = QPushButton("Save") self.sample_file.clicked.connect(self.sample_file_clicked) self.sample_save.clicked.connect(self.sample_save_clicked) self.sample_layout.addWidget(self.sample_label) self.sample_layout.addWidget(self.sample_edit) self.sample_layout.addWidget(self.sample_file) self.sample_layout.addWidget(self.sample_save) self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Distance [cm]', plot_list) layout_h1 = QHBoxLayout() layout_h1.addStretch() layout_h1.addWidget(self.distance_label) layout_h1.addStretch() layout_h2 = QHBoxLayout() layout_h2.addStretch() layout_h2.addWidget(self.analog_label) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h1) layout.addLayout(layout_h2) layout.addWidget(self.plot_widget) layout.addLayout(self.sample_layout)
def __init__(self, *args): PluginBase.__init__(self, BrickletIndustrialDualAnalogIn, *args) self.analog_in = self.device self.cbe_voltage0 = CallbackEmulator(functools.partial(self.analog_in.get_voltage, 0), functools.partial(self.cb_voltage, 0), self.increase_error_count) self.cbe_voltage1 = CallbackEmulator(functools.partial(self.analog_in.get_voltage, 1), functools.partial(self.cb_voltage, 1), self.increase_error_count) self.calibration = None self.sample_rate_label = QLabel('Sample Rate:') self.sample_rate_combo = QComboBox() self.sample_rate_combo.addItem('976 Hz') self.sample_rate_combo.addItem('488 Hz') self.sample_rate_combo.addItem('244 Hz') self.sample_rate_combo.addItem('122 Hz') self.sample_rate_combo.addItem('61 Hz') self.sample_rate_combo.addItem('4 Hz') self.sample_rate_combo.addItem('2 Hz') self.sample_rate_combo.addItem('1 Hz') self.current_voltage = [None, None] # float, V self.calibration_button = QPushButton('Calibration...') self.sample_rate_combo.currentIndexChanged.connect(self.sample_rate_combo_index_changed) self.calibration_button.clicked.connect(self.calibration_button_clicked) plots = [('Channel 0', Qt.red, lambda: self.current_voltage[0], format_voltage), ('Channel 1', Qt.blue, lambda: self.current_voltage[1], format_voltage)] self.plot_widget = PlotWidget('Voltage [V]', plots) hlayout = QHBoxLayout() hlayout.addWidget(self.sample_rate_label) hlayout.addWidget(self.sample_rate_combo) hlayout.addStretch() hlayout.addWidget(self.calibration_button) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout)
def __init__(self, *args): PluginBase.__init__(self, BrickletTemperatureIR, *args) self.tem = self.device self.cbe_ambient_temperature = CallbackEmulator(self.tem.get_ambient_temperature, self.cb_ambient_temperature, self.increase_error_count) self.cbe_object_temperature = CallbackEmulator(self.tem.get_object_temperature, self.cb_object_temperature, self.increase_error_count) self.ambient_label = AmbientLabel() self.object_label = ObjectLabel() self.emissivity_label = QLabel('Emissivity: ') self.emissivity_edit = QLineEdit() self.emissivity_button = QPushButton('Save') self.emissivity_layout = QHBoxLayout() self.emissivity_layout.addWidget(self.emissivity_label) self.emissivity_layout.addWidget(self.emissivity_edit) self.emissivity_layout.addWidget(self.emissivity_button) self.emissivity_button.clicked.connect(self.emissivity_clicked) self.current_ambient = None self.current_object = None plot_list = [['Ambient', Qt.blue, self.get_current_ambient], ['Object', Qt.red, self.get_current_object]] self.plot_widget = PlotWidget('Temperature [%cC]' % 0xB0, plot_list) layout_h1 = QHBoxLayout() layout_h1.addStretch() layout_h1.addWidget(self.ambient_label) layout_h1.addStretch() layout_h2 = QHBoxLayout() layout_h2.addStretch() layout_h2.addWidget(self.object_label) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h1) layout.addLayout(layout_h2) layout.addWidget(self.plot_widget) layout.addLayout(self.emissivity_layout)
def __init__(self, *args): PluginBase.__init__(self, BrickletAnalogOutV2, *args) self.ao = self.device self.input_voltage_label = VoltageLabel() self.output_voltage_label = QLabel('Output Voltage [mV]: ') self.output_voltage_box = QSpinBox() self.output_voltage_box.setMinimum(0) self.output_voltage_box.setMaximum(12000) self.output_voltage_box.setSingleStep(1) layout_h1 = QHBoxLayout() layout_h1.addStretch() layout_h1.addWidget(self.output_voltage_label) layout_h1.addWidget(self.output_voltage_box) layout_h1.addStretch() layout_h2 = QHBoxLayout() layout_h2.addStretch() layout_h2.addWidget(self.input_voltage_label) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h2) layout.addLayout(layout_h1) layout.addStretch() self.output_voltage_box.editingFinished.connect(self.voltage_finished) self.cbe_input_voltage = CallbackEmulator(self.ao.get_input_voltage, self.cb_get_input_voltage, self.increase_error_count)
def __init__(self, *args): super().__init__(BrickletRotaryPotiV2, *args) self.rp = self.device self.cbe_position = CallbackEmulator(self.rp.get_position, None, self.cb_position, self.increase_error_count) self.position_knob = KnobWidget(self) self.position_knob.setFocusPolicy(Qt.NoFocus) self.position_knob.set_total_angle(300) self.position_knob.set_range(-150, 150) self.position_knob.set_scale(30, 3) self.position_knob.set_knob_radius(25) self.current_position = CurveValueWrapper() plots = [('Position', Qt.red, self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, update_interval=0.025, y_resolution=1.0) layout = QHBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(self.position_knob)
def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletIndustrialDualAnalogInV2, *args) self.analog_in = self.device self.cbe_voltage0 = CallbackEmulator(functools.partial(self.analog_in.get_voltage, 0), functools.partial(self.cb_voltage, 0), self.increase_error_count) self.cbe_voltage1 = CallbackEmulator(functools.partial(self.analog_in.get_voltage, 1), functools.partial(self.cb_voltage, 1), self.increase_error_count) self.calibration = None self.sample_rate_label = QLabel('Sample Rate:') self.sample_rate_combo = QComboBox() self.sample_rate_combo.addItem('976 Hz') self.sample_rate_combo.addItem('488 Hz') self.sample_rate_combo.addItem('244 Hz') self.sample_rate_combo.addItem('122 Hz') self.sample_rate_combo.addItem('61 Hz') self.sample_rate_combo.addItem('4 Hz') self.sample_rate_combo.addItem('2 Hz') self.sample_rate_combo.addItem('1 Hz') self.current_voltage = [None, None] # float, V self.calibration_button = QPushButton('Calibration...') self.sample_rate_combo.currentIndexChanged.connect(self.sample_rate_combo_index_changed) self.calibration_button.clicked.connect(self.calibration_button_clicked) plots = [('Channel 0', Qt.red, lambda: self.current_voltage[0], format_voltage), ('Channel 1', Qt.blue, lambda: self.current_voltage[1], format_voltage)] self.plot_widget = PlotWidget('Voltage [V]', plots) # Define lines line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) line1 = QFrame() line1.setFrameShape(QFrame.HLine) line1.setFrameShadow(QFrame.Sunken) line2 = QFrame() line2.setFrameShape(QFrame.HLine) line2.setFrameShadow(QFrame.Sunken) # Define channel LED status config widgets self.led_config_ch0_label = QLabel('Channel 0') self.led_config_ch1_label = QLabel('Channel 1') self.led_config_label = QLabel('LED Config:') self.led_status_config_label = QLabel('LED Status Config:') self.led_status_config_ch0_min_label = QLabel('Min:') self.led_status_config_ch0_max_label = QLabel('Max:') self.led_status_config_ch1_min_label = QLabel('Min:') self.led_status_config_ch1_max_label = QLabel('Max:') self.led_config_ch0_combo = QComboBox() self.led_config_ch0_combo.addItem('Off') self.led_config_ch0_combo.addItem('On') self.led_config_ch0_combo.addItem('Show Heartbeat') self.led_config_ch0_combo.addItem('Show Channel Status') self.led_config_ch0_combo.currentIndexChanged.connect(self.led_config_ch0_combo_changed) self.led_config_ch1_combo = QComboBox() self.led_config_ch1_combo.addItem('Off') self.led_config_ch1_combo.addItem('On') self.led_config_ch1_combo.addItem('Show Heartbeat') self.led_config_ch1_combo.addItem('Show Channel Status') self.led_config_ch1_combo.currentIndexChanged.connect(self.led_config_ch1_combo_changed) self.led_status_config_ch0_combo = QComboBox() self.led_status_config_ch0_combo.addItem('Threshold') self.led_status_config_ch0_combo.addItem('Intensity') self.led_status_config_ch0_combo.currentIndexChanged.connect(self.led_status_config_ch0_combo_changed) self.led_status_config_ch1_combo = QComboBox() self.led_status_config_ch1_combo.addItem('Threshold') self.led_status_config_ch1_combo.addItem('Intensity') self.led_status_config_ch1_combo.currentIndexChanged.connect(self.led_status_config_ch1_combo_changed) self.led_status_config_ch0_min_sbox = QSpinBox() self.led_status_config_ch0_min_sbox.setMinimum(-35000) self.led_status_config_ch0_min_sbox.setMaximum(35000) self.led_status_config_ch0_min_sbox.setValue(0) self.led_status_config_ch0_min_sbox.setSingleStep(1) self.led_status_config_ch0_min_sbox.setSuffix(' mV') self.led_status_config_ch0_min_sbox.valueChanged.connect(self.led_status_config_ch0_min_sbox_changed) self.led_status_config_ch0_max_sbox = QSpinBox() self.led_status_config_ch0_max_sbox.setMinimum(-35000) self.led_status_config_ch0_max_sbox.setMaximum(35000) self.led_status_config_ch0_max_sbox.setValue(0) self.led_status_config_ch0_max_sbox.setSingleStep(1) self.led_status_config_ch0_max_sbox.setSuffix(' mV') self.led_status_config_ch0_max_sbox.valueChanged.connect(self.led_status_config_ch0_max_sbox_changed) self.led_status_config_ch1_min_sbox = QSpinBox() self.led_status_config_ch1_min_sbox.setMinimum(-35000) self.led_status_config_ch1_min_sbox.setMaximum(35000) self.led_status_config_ch1_min_sbox.setValue(0) self.led_status_config_ch1_min_sbox.setSingleStep(1) self.led_status_config_ch1_min_sbox.setSuffix(' mV') self.led_status_config_ch1_min_sbox.valueChanged.connect(self.led_status_config_ch1_min_sbox_changed) self.led_status_config_ch1_max_sbox = QSpinBox() self.led_status_config_ch1_max_sbox.setMinimum(-35000) self.led_status_config_ch1_max_sbox.setMaximum(35000) self.led_status_config_ch1_max_sbox.setValue(0) self.led_status_config_ch1_max_sbox.setSingleStep(1) self.led_status_config_ch1_max_sbox.setSuffix(' mV') self.led_status_config_ch1_max_sbox.valueChanged.connect(self.led_status_config_ch1_max_sbox_changed) # Define size policies h_sp = QSizePolicy() h_sp.setHorizontalPolicy(QSizePolicy.Expanding) # Set size policies self.sample_rate_combo.setSizePolicy(h_sp) self.led_config_ch0_combo.setSizePolicy(h_sp) self.led_config_ch1_combo.setSizePolicy(h_sp) self.led_status_config_ch0_combo.setSizePolicy(h_sp) self.led_status_config_ch1_combo.setSizePolicy(h_sp) self.led_status_config_ch0_min_sbox.setSizePolicy(h_sp) self.led_status_config_ch0_max_sbox.setSizePolicy(h_sp) self.led_status_config_ch1_min_sbox.setSizePolicy(h_sp) self.led_status_config_ch1_max_sbox.setSizePolicy(h_sp) # Define layouts hlayout = QHBoxLayout() vlayout = QVBoxLayout() glayout = QGridLayout() layout = QVBoxLayout(self) hlayout_ch0_min_max = QHBoxLayout() hlayout_ch1_min_max = QHBoxLayout() # Populate layouts vlayout.addWidget(self.calibration_button) hlayout.addWidget(self.sample_rate_label) hlayout.addWidget(self.sample_rate_combo) vlayout.addLayout(hlayout) vlayout.addWidget(line1) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_min_label) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_min_sbox) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_max_label) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_max_sbox) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_min_label) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_min_sbox) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_max_label) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_max_sbox) glayout.addWidget(self.led_config_ch0_label, 0, 1, 1, 1) # R, C, RS, CS glayout.addWidget(self.led_config_ch1_label, 0, 2, 1, 1) glayout.addWidget(line2, 1, 0, 1, 3) glayout.addWidget(self.led_config_label, 2, 0, 1, 1) glayout.addWidget(self.led_config_ch0_combo, 2, 1, 1, 1) glayout.addWidget(self.led_config_ch1_combo, 2, 2, 1, 1) glayout.addWidget(self.led_status_config_label, 3, 0, 1, 1) glayout.addWidget(self.led_status_config_ch0_combo, 3, 1, 1, 1) glayout.addWidget(self.led_status_config_ch1_combo, 3, 2, 1, 1) glayout.addLayout(hlayout_ch0_min_max, 4, 1, 1, 1) glayout.addLayout(hlayout_ch1_min_max, 4, 2, 1, 1) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(vlayout) layout.addLayout(glayout) self.ui_group_ch_status_ch0 = [self.led_status_config_ch0_combo, self.led_status_config_ch0_min_sbox, self.led_status_config_ch0_max_sbox] self.ui_group_ch_status_ch1 = [self.led_status_config_ch1_combo, self.led_status_config_ch1_min_sbox, self.led_status_config_ch1_max_sbox]
def __init__(self, *args): PluginBase.__init__(self, BrickletIndustrialDualAnalogIn, *args) self.analog_in = self.device self.cbe_voltage0 = CallbackEmulator( functools.partial(self.analog_in.get_voltage, 0), functools.partial(self.cb_voltage, 0), self.increase_error_count) self.cbe_voltage1 = CallbackEmulator( functools.partial(self.analog_in.get_voltage, 1), functools.partial(self.cb_voltage, 1), self.increase_error_count) self.voltage_label = [VoltageLabel(), VoltageLabel()] self.calibration = None self.sample_rate_label1 = QLabel('Sample Rate:') self.sample_rate_combo = QComboBox() self.sample_rate_combo.addItem('976') self.sample_rate_combo.addItem('488') self.sample_rate_combo.addItem('244') self.sample_rate_combo.addItem('122') self.sample_rate_combo.addItem('61') self.sample_rate_combo.addItem('4') self.sample_rate_combo.addItem('2') self.sample_rate_combo.addItem('1') self.sample_rate_label2 = QLabel('Samples per second') self.voltage_value = [None, None] self.calibration_button = QPushButton('Show/Edit Calibration') self.sample_rate_combo.currentIndexChanged.connect( self.sample_rate_combo_index_changed) self.calibration_button.clicked.connect( self.calibration_button_clicked) plot_list = [['Channel 0', Qt.red, self.get_voltage_value0], ['Channel 1', Qt.blue, self.get_voltage_value1]] self.plot_widget = PlotWidget('Voltage [V]', plot_list) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(QLabel("Channel 0: ")) layout_h.addWidget(self.voltage_label[0]) layout_h.addStretch() layout_h1 = QHBoxLayout() layout_h1.addStretch() layout_h1.addWidget(QLabel("Channel 1: ")) layout_h1.addWidget(self.voltage_label[1]) layout_h1.addStretch() layout_h2 = QHBoxLayout() layout_h2.addWidget(self.sample_rate_label1) layout_h2.addWidget(self.sample_rate_combo) layout_h2.addWidget(self.sample_rate_label2) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addLayout(layout_h1) layout.addWidget(self.plot_widget) layout.addLayout(layout_h2) layout.addWidget(line) layout.addWidget(self.calibration_button)
class TemperatureIRV2(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletTemperatureIRV2, *args) self.tir = self.device self.cbe_ambient_temperature = CallbackEmulator( self.tir.get_ambient_temperature, None, self.cb_ambient_temperature, self.increase_error_count) self.cbe_object_temperature = CallbackEmulator( self.tir.get_object_temperature, None, self.cb_object_temperature, self.increase_error_count) self.current_ambient = CurveValueWrapper() # float, °C self.current_object = CurveValueWrapper() # float, °C plots = [('Ambient', Qt.blue, self.current_ambient, '{} °C'.format), ('Object', Qt.red, self.current_object, '{} °C'.format)] self.plot_widget = PlotWidget('Temperature [°C]', plots, y_resolution=0.1) self.spin_emissivity = QSpinBox() self.spin_emissivity.setMinimum(6553) self.spin_emissivity.setMaximum(65535) self.spin_emissivity.setValue(65535) self.spin_emissivity.editingFinished.connect( self.spin_emissivity_finished) hlayout = QHBoxLayout() hlayout.addWidget(QLabel('Emissivity:')) hlayout.addWidget(self.spin_emissivity) hlayout.addStretch() line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) 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 def stop(self): self.cbe_ambient_temperature.set_period(0) self.cbe_object_temperature.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletTemperatureIRV2.DEVICE_IDENTIFIER def cb_object_temperature(self, temperature): self.current_object.value = temperature / 10.0 def cb_ambient_temperature(self, temperature): self.current_ambient.value = temperature / 10.0 def get_emissivity_async(self, emissivity): self.spin_emissivity.setValue(emissivity) def spin_emissivity_finished(self): self.tir.set_emissivity(self.spin_emissivity.value())
class PTC(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletPTC, *args) self.ptc = self.device self.str_connected = 'Sensor is <font color="green">connected</font>' self.str_not_connected = 'Sensor is <font color="red">not connected</font>' self.cbe_temperature = CallbackEmulator(self.ptc.get_temperature, self.cb_temperature, self.increase_error_count) #self.cbe_resistance = CallbackEmulator(self.ptc.get_resistance, # self.cb_resistance, # self.increase_error_count) #self.resistance_label = ResistanceLabel() self.wire_label = QLabel('Wire Type:') self.wire_combo = QComboBox() self.wire_combo.addItem('2-Wire') self.wire_combo.addItem('3-Wire') self.wire_combo.addItem('4-Wire') self.noise_label = QLabel('Noise Rejection Filter:') self.noise_combo = QComboBox() self.noise_combo.addItem('50 Hz') self.noise_combo.addItem('60 Hz') self.connected_label = QLabel(self.str_connected) self.current_temperature = None # float, °C self.wire_combo.currentIndexChanged.connect(self.wire_combo_index_changed) self.noise_combo.currentIndexChanged.connect(self.noise_combo_index_changed) plots = [('Temperature', Qt.red, lambda: self.current_temperature, u'{} °C'.format)] self.plot_widget = PlotWidget(u'Temperature [°C]', plots, extra_key_widgets=[self.connected_label]) hlayout = QHBoxLayout() hlayout.addWidget(self.wire_label) hlayout.addWidget(self.wire_combo) hlayout.addStretch() hlayout.addWidget(self.noise_label) hlayout.addWidget(self.noise_combo) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) self.connected_timer = QTimer() self.connected_timer.timeout.connect(self.update_connected) self.connected_timer.setInterval(1000) def start(self): async_call(self.ptc.get_temperature, None, self.cb_temperature, self.increase_error_count) #async_call(self.ptc.get_resistance, None, self.cb_resistance, self.increase_error_count) self.cbe_temperature.set_period(100) #self.cbe_resistance.set_period(100) async_call(self.ptc.is_sensor_connected, None, self.is_sensor_connected_async, self.increase_error_count) async_call(self.ptc.get_noise_rejection_filter, None, self.get_noise_rejection_filter_async, self.increase_error_count) async_call(self.ptc.get_wire_mode, None, self.get_wire_mode_async, self.increase_error_count) self.connected_timer.start() self.plot_widget.stop = False def stop(self): self.cbe_temperature.set_period(0) #self.cbe_resistance.set_period(0) self.connected_timer.stop() self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletPTC.DEVICE_IDENTIFIER def update_connected(self): async_call(self.ptc.is_sensor_connected, None, self.is_sensor_connected_async, self.increase_error_count) def wire_combo_index_changed(self, index): async_call(self.ptc.set_wire_mode, index+2, None, self.increase_error_count) def noise_combo_index_changed(self, index): async_call(self.ptc.set_noise_rejection_filter, index, None, self.increase_error_count) def is_sensor_connected_async(self, connected): if connected: self.connected_label.setText(self.str_connected) else: self.connected_label.setText(self.str_not_connected) def get_noise_rejection_filter_async(self, filter_option): self.noise_combo.setCurrentIndex(filter_option) def get_wire_mode_async(self, mode): self.wire_combo.setCurrentIndex(mode-2) def cb_temperature(self, temperature): self.current_temperature = temperature / 100.0 def cb_resistance(self, resistance): resistance_str = str(round(resistance * 3900.0 / (1 << 15), 1)) self.resistance_label.setText(resistance_str)
class DistanceIR(PluginBase): NUM_VALUES = 128 DIVIDER = 2**12 // NUM_VALUES def __init__(self, *args): super().__init__(BrickletDistanceIR, *args) self.dist = self.device self.cbe_distance = CallbackEmulator(self, self.dist.get_distance, None, self.cb_distance, self.increase_error_count) self.cbe_analog_value = CallbackEmulator(self, self.dist.get_analog_value, None, self.cb_analog_value, self.increase_error_count) self.analog_label = AnalogLabel('Analog Value:') hlayout = QHBoxLayout() self.sample_label = QLabel('Sample Points:') self.sample_edit = QLineEdit() self.sample_file = QPushButton("Browse") self.sample_save = QPushButton("Save") self.sample_file.clicked.connect(self.sample_file_clicked) self.sample_save.clicked.connect(self.sample_save_clicked) hlayout.addWidget(self.sample_label) hlayout.addWidget(self.sample_edit) hlayout.addWidget(self.sample_file) hlayout.addWidget(self.sample_save) self.current_distance = CurveValueWrapper() # float, cm plots = [('Distance', Qt.red, self.current_distance, '{} cm'.format)] self.plot_widget = PlotWidget('Distance [cm]', plots, extra_key_widgets=[self.analog_label], y_resolution=0.1) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) def start(self): self.cbe_distance.set_period(100) self.cbe_analog_value.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_distance.set_period(0) self.cbe_analog_value.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletDistanceIR.DEVICE_IDENTIFIER def sample_file_clicked(self): if len(self.sample_edit.text()) > 0: last_dir = os.path.dirname( os.path.realpath(self.sample_edit.text())) else: last_dir = get_home_path() filename = get_open_file_name(get_main_window(), "Open Sample Points", last_dir) if len(filename) > 0: self.sample_edit.setText(filename) def sample_interpolate(self, x, y): spline = NaturalSpline() points = [] for point in zip(x, y): points.append((float(point[0]), float(point[1]))) spline.set_points(points) px = range(0, int(2**12), DistanceIR.DIVIDER) py = [] for X in px: py.append(spline.get_value(X)) for i in range(x[0] // DistanceIR.DIVIDER): py[i] = y[0] for i in range(x[-1] // DistanceIR.DIVIDER, 2**12 // DistanceIR.DIVIDER): py[i] = y[-1] for i in range(len(py)): if py[i] > y[0]: py[i] = y[0] if py[i] < y[-1]: py[i] = y[-1] try: old_text = self.sample_edit.text() for i in range(DistanceIR.NUM_VALUES): value = int(round(py[i] * 100)) self.dist.set_sampling_point(i, value) self.sample_edit.setText("Writing sample point, value: " + str((i, value))) QApplication.processEvents() self.sample_edit.setText(old_text) except ip_connection.Error: return def _save_samples(self): x = [] y = [] filename = self.sample_edit.text() if len(filename) == 0: return with open(filename, 'r') as f: for line in f: c = line.find('#') if c != -1: line = line[:c] line = line.strip() if line.startswith( '\xEF\xBB\xBF' ): # strip UTF-8 BOM, Internet Explorer adds it to text files line = line[3:] if len(line) == 0: continue if ':' not in line: QMessageBox.critical( get_main_window(), "Sample points", "Sample points file is malformed (error code 1)", QMessageBox.Ok) return s = line.split(':') if len(s) != 2: QMessageBox.critical( get_main_window(), "Sample points", "Sample points file is malformed (error code 2)", QMessageBox.Ok) return try: x.append(int(s[1])) y.append(int(s[0])) except: QMessageBox.critical( get_main_window(), "Sample points", "Sample points file is malformed (error code 3)", QMessageBox.Ok) return self.sample_interpolate(x, y) def sample_save_clicked(self): self.sample_save.setDisabled(True) self._save_samples() self.sample_save.setEnabled(True) def cb_distance(self, distance): self.current_distance.value = distance / 10.0 def cb_analog_value(self, analog_value): self.analog_label.setText(analog_value)
class Current12(PluginBase): qtcb_over = pyqtSignal() def __init__(self, *args): PluginBase.__init__(self, BrickletCurrent12, *args) self.cur = self.device self.cbe_current = CallbackEmulator(self.cur.get_current, self.cb_current, self.increase_error_count) self.qtcb_over.connect(self.cb_over) self.cur.register_callback(self.cur.CALLBACK_OVER_CURRENT, self.qtcb_over.emit) self.current_label = CurrentLabel('Current: ') self.over_label = QLabel('Over Current: No') self.calibrate_button = QPushButton('Calibrate') self.calibrate_button.clicked.connect(self.calibrate_clicked) self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Current [mA]', plot_list) layout_h1 = QHBoxLayout() layout_h1.addStretch() layout_h1.addWidget(self.current_label) layout_h1.addStretch() layout_h2 = QHBoxLayout() layout_h2.addStretch() layout_h2.addWidget(self.over_label) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h1) layout.addLayout(layout_h2) layout.addWidget(self.plot_widget) layout.addWidget(self.calibrate_button) def start(self): async_call(self.cur.get_current, None, self.cb_current, self.increase_error_count) self.cbe_current.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_current.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'current12' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletCurrent12.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_current(self, current): self.current_value = current self.current_label.setText(str(current / 1000.0)) def cb_over(self): self.over_label.setText('Over Current: Yes') def calibrate_clicked(self): try: self.cur.calibrate() except ip_connection.Error: return
class Current12(PluginBase): qtcb_over = pyqtSignal() def __init__(self, *args): PluginBase.__init__(self, BrickletCurrent12, *args) self.cur = self.device self.cbe_current = CallbackEmulator(self.cur.get_current, self.cb_current, self.increase_error_count) self.qtcb_over.connect(self.cb_over) self.cur.register_callback(self.cur.CALLBACK_OVER_CURRENT, self.qtcb_over.emit) self.over_label = QLabel('Over Current: No') self.calibrate_button = QPushButton('Calibrate Zero') self.calibrate_button.clicked.connect(self.calibrate_clicked) self.current_current = None # float, A plots = [('Current', Qt.red, lambda: self.current_current, format_current)] self.plot_widget = PlotWidget('Current [A]', plots, extra_key_widgets=[self.over_label]) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addWidget(self.calibrate_button) def start(self): async_call(self.cur.get_current, None, self.cb_current, self.increase_error_count) self.cbe_current.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_current.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletCurrent12.DEVICE_IDENTIFIER def cb_current(self, current): self.current_current = current / 1000.0 def cb_over(self): self.over_label.setText('Over Current: Yes') def calibrate_clicked(self): try: self.cur.calibrate() except ip_connection.Error: return
class CO2V2(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletCO2V2, *args) self.co2 = self.device self.cbe_all_values = CallbackEmulator(self, self.co2.get_all_values, None, self.cb_all_values, self.increase_error_count) self.current_co2 = CurveValueWrapper() # int, ppm self.current_temperature = CurveValueWrapper() # float, °C self.current_humidity = CurveValueWrapper() # float, %RH plots_co2 = [('CO2', Qt.red, self.current_co2, '{} PPM'.format)] self.plot_widget_co2 = PlotWidget('CO2 [PPM]', plots_co2, y_resolution=1.0) plots_temperature = [('Temperature', Qt.red, self.current_temperature, '{} °C'.format)] self.plot_widget_temperature = PlotWidget('Temperature [°C]', plots_temperature, y_resolution=0.01) plots_humidity = [('Relative Humidity', Qt.red, self.current_humidity, '{} %RH'.format)] self.plot_widget_humidity = PlotWidget('Relative Humidity [%RH]', plots_humidity, y_resolution=0.01) layout_plot1 = QHBoxLayout() layout_plot1.addWidget(self.plot_widget_co2) layout_plot2 = QHBoxLayout() layout_plot2.addWidget(self.plot_widget_temperature) layout_plot2.addWidget(self.plot_widget_humidity) layout_main = QVBoxLayout(self) layout_main.addLayout(layout_plot1) layout_main.addLayout(layout_plot2) def cb_all_values(self, values): self.current_co2.value = values.co2_concentration self.current_temperature.value = values.temperature / 100.0 self.current_humidity.value = values.humidity / 100.0 def start(self): self.cbe_all_values.set_period(250) self.plot_widget_co2.stop = False self.plot_widget_temperature.stop = False self.plot_widget_humidity.stop = False def stop(self): self.cbe_all_values.set_period(0) self.plot_widget_co2.stop = True self.plot_widget_temperature.stop = True self.plot_widget_humidity.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletCO2V2.DEVICE_IDENTIFIER
class ACCurrent(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletACCurrent, *args) self.acc = self.device self.cbe_current = CallbackEmulator(self.acc.get_current, self.cb_current, self.increase_error_count) self.current_label = CurrentLabel('Current: ') self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Current [A]', plot_list) layout_h2 = QHBoxLayout() layout_h2.addStretch() layout_h2.addWidget(self.current_label) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h2) layout.addWidget(self.plot_widget) self.label_average = QLabel('Length of moving average:') self.spin_average = QSpinBox() self.spin_average.setMinimum(1) self.spin_average.setMaximum(50) self.spin_average.setSingleStep(1) self.spin_average.setValue(50) self.spin_average.editingFinished.connect(self.spin_average_finished) self.label_range = QLabel('Current Range: ') self.combo_range = QComboBox() self.combo_range.addItem("0") # TODO: Adjust ranges self.combo_range.addItem("1") self.combo_range.currentIndexChanged.connect(self.new_config) layout_h1 = QHBoxLayout() layout_h1.addStretch() layout_h1.addWidget(self.label_average) layout_h1.addWidget(self.spin_average) layout_h1.addStretch() layout_h1.addWidget(self.label_range) layout_h1.addWidget(self.combo_range) layout_h1.addStretch() layout.addLayout(layout_h1) def get_configuration_async(self, conf): self.combo_range.setCurrentIndex(conf) def get_moving_average_async(self, average): self.spin_average.setValue(average) def new_config(self, value): try: self.acc.set_configuration(value) except: pass 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) async_call(self.acc.get_current, None, self.cb_current, self.increase_error_count) self.cbe_current.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_current.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'ac_current' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletACCurrent.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_current(self, current): c = round(current/1000.0, 2) self.current_value = c self.current_label.setText('%6.02f' % c) def spin_average_finished(self): self.acc.set_moving_average(self.spin_average.value())
def __init__(self, *args): super().__init__(BrickletAccelerometer, *args) self.accelerometer = self.device self.cbe_acceleration = CallbackEmulator( self, self.accelerometer.get_acceleration, None, self.cb_acceleration, self.increase_error_count, expand_result_tuple_for_callback=True) self.cbe_temperature = CallbackEmulator( self, self.accelerometer.get_temperature, None, self.cb_temperature, self.increase_error_count) self.current_acceleration_x = CurveValueWrapper() # float, g self.current_acceleration_y = CurveValueWrapper() # float, g self.current_acceleration_z = CurveValueWrapper() # float, g self.pitch_label = PitchLabel() self.roll_label = RollLabel() self.temperature_label = TemperatureLabel() plots = [('X', Qt.red, self.current_acceleration_x, '{:.3f} g'.format), ('Y', Qt.darkGreen, self.current_acceleration_y, '{:.3f} g'.format), ('Z', Qt.blue, self.current_acceleration_z, '{:.3f} g'.format) ] self.plot_widget = PlotWidget('Acceleration [g]', plots, extra_key_widgets=[ self.pitch_label, self.roll_label, self.temperature_label ], update_interval=0.05, y_resolution=0.001) self.fs_label = QLabel('Full Scale:') self.fs_combo = QComboBox() self.fs_combo.addItem("2 g") self.fs_combo.addItem("4 g") self.fs_combo.addItem("6 g") self.fs_combo.addItem("8 g") self.fs_combo.addItem("16 g") self.fs_combo.currentIndexChanged.connect(self.new_config) self.dr_label = QLabel('Data Rate:') self.dr_combo = QComboBox() self.dr_combo.addItem("Off") self.dr_combo.addItem("3.125 Hz") self.dr_combo.addItem("6.25 Hz") self.dr_combo.addItem("12.5 Hz") self.dr_combo.addItem("25 Hz") self.dr_combo.addItem("50 Hz") self.dr_combo.addItem("100 Hz") self.dr_combo.addItem("400 Hz") self.dr_combo.addItem("800 Hz") self.dr_combo.addItem("1600 Hz") self.dr_combo.currentIndexChanged.connect(self.new_config) self.fb_label = QLabel('Filter Bandwidth:') self.fb_combo = QComboBox() self.fb_combo.addItem("800 Hz") self.fb_combo.addItem("400 Hz") self.fb_combo.addItem("200 Hz") self.fb_combo.addItem("50 Hz") self.fb_combo.currentIndexChanged.connect(self.new_config) self.enable_led = QCheckBox("Enable LED") self.enable_led.stateChanged.connect(self.enable_led_changed) hlayout = QHBoxLayout() hlayout.addWidget(self.fs_label) hlayout.addWidget(self.fs_combo) hlayout.addStretch() hlayout.addWidget(self.dr_label) hlayout.addWidget(self.dr_combo) hlayout.addStretch() hlayout.addWidget(self.fb_label) hlayout.addWidget(self.fb_combo) hlayout.addStretch() hlayout.addWidget(self.enable_led) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout)
class Accelerometer(PluginBase): def __init__(self, *args): super().__init__(BrickletAccelerometer, *args) self.accelerometer = self.device self.cbe_acceleration = CallbackEmulator( self, self.accelerometer.get_acceleration, None, self.cb_acceleration, self.increase_error_count, expand_result_tuple_for_callback=True) self.cbe_temperature = CallbackEmulator( self, self.accelerometer.get_temperature, None, self.cb_temperature, self.increase_error_count) self.current_acceleration_x = CurveValueWrapper() # float, g self.current_acceleration_y = CurveValueWrapper() # float, g self.current_acceleration_z = CurveValueWrapper() # float, g self.pitch_label = PitchLabel() self.roll_label = RollLabel() self.temperature_label = TemperatureLabel() plots = [('X', Qt.red, self.current_acceleration_x, '{:.3f} g'.format), ('Y', Qt.darkGreen, self.current_acceleration_y, '{:.3f} g'.format), ('Z', Qt.blue, self.current_acceleration_z, '{:.3f} g'.format) ] self.plot_widget = PlotWidget('Acceleration [g]', plots, extra_key_widgets=[ self.pitch_label, self.roll_label, self.temperature_label ], update_interval=0.05, y_resolution=0.001) self.fs_label = QLabel('Full Scale:') self.fs_combo = QComboBox() self.fs_combo.addItem("2 g") self.fs_combo.addItem("4 g") self.fs_combo.addItem("6 g") self.fs_combo.addItem("8 g") self.fs_combo.addItem("16 g") self.fs_combo.currentIndexChanged.connect(self.new_config) self.dr_label = QLabel('Data Rate:') self.dr_combo = QComboBox() self.dr_combo.addItem("Off") self.dr_combo.addItem("3.125 Hz") self.dr_combo.addItem("6.25 Hz") self.dr_combo.addItem("12.5 Hz") self.dr_combo.addItem("25 Hz") self.dr_combo.addItem("50 Hz") self.dr_combo.addItem("100 Hz") self.dr_combo.addItem("400 Hz") self.dr_combo.addItem("800 Hz") self.dr_combo.addItem("1600 Hz") self.dr_combo.currentIndexChanged.connect(self.new_config) self.fb_label = QLabel('Filter Bandwidth:') self.fb_combo = QComboBox() self.fb_combo.addItem("800 Hz") self.fb_combo.addItem("400 Hz") self.fb_combo.addItem("200 Hz") self.fb_combo.addItem("50 Hz") self.fb_combo.currentIndexChanged.connect(self.new_config) self.enable_led = QCheckBox("Enable LED") self.enable_led.stateChanged.connect(self.enable_led_changed) hlayout = QHBoxLayout() hlayout.addWidget(self.fs_label) hlayout.addWidget(self.fs_combo) hlayout.addStretch() hlayout.addWidget(self.dr_label) hlayout.addWidget(self.dr_combo) hlayout.addStretch() hlayout.addWidget(self.fb_label) hlayout.addWidget(self.fb_combo) hlayout.addStretch() hlayout.addWidget(self.enable_led) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) def enable_led_changed(self, state): if state == Qt.Checked: self.accelerometer.led_on() else: self.accelerometer.led_off() def is_led_on_async(self, on): self.enable_led.setChecked(on) def new_config(self): dr = self.dr_combo.currentIndex() fs = self.fs_combo.currentIndex() fb = self.fb_combo.currentIndex() self.accelerometer.set_configuration(dr, fs, fb) def cb_acceleration(self, x, y, z): self.current_acceleration_x.value = x / 1000.0 self.current_acceleration_y.value = y / 1000.0 self.current_acceleration_z.value = z / 1000.0 self.pitch_label.setText(x, y, z) self.roll_label.setText(x, y, z) def get_configuration_async(self, conf): self.fs_combo.setCurrentIndex(conf.full_scale) self.fb_combo.setCurrentIndex(conf.filter_bandwidth) self.dr_combo.setCurrentIndex(conf.data_rate) def cb_temperature(self, temperature): self.temperature_label.setText(temperature) def start(self): async_call(self.accelerometer.is_led_on, None, self.is_led_on_async, self.increase_error_count) async_call(self.accelerometer.get_configuration, None, self.get_configuration_async, self.increase_error_count) self.cbe_acceleration.set_period(50) self.cbe_temperature.set_period(1000) self.plot_widget.stop = False def stop(self): self.cbe_acceleration.set_period(0) self.cbe_temperature.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletAccelerometer.DEVICE_IDENTIFIER
def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletServoV2, *args) self.setupUi(self) self.servo = self.device self.cbe_status = CallbackEmulator(self, self.servo.get_status, None, self.cb_status, self.increase_error_count) self.position_list = [] self.velocity_list = [] self.current_list = [] self.enable_list = [] self.up_cur = 0 self.up_siv = 0 self.up_eiv = 0 self.up_opv = 0 self.up_mv = 0 self.up_ena = [0]*10 self.up_pos = [0]*10 self.up_vel = [0]*10 self.up_acc = [0]*10 self.alive = True for i in range(1, 11): label = QLabel() label.setText('Off') self.enable_list.append(label) self.status_grid.addWidget(label, i, 1) for i in range(1, 11): pk = PositionKnob() self.position_list.append(pk) self.status_grid.addWidget(pk, i, 2) for i in range(1, 11): cb = ColorBar(Qt.Vertical) self.velocity_list.append(cb) self.status_grid.addWidget(cb, i, 3) for i in range(1, 11): cb = ColorBar(Qt.Vertical) self.current_list.append(cb) self.status_grid.addWidget(cb, i, 4) self.servo_dropbox.currentIndexChanged.connect(lambda x: self.update_servo_specific()) self.enable_checkbox.stateChanged.connect(self.enable_state_changed) self.position_syncer = SliderSpinSyncer(self.position_slider, self.position_spin, self.position_changed) self.velocity_syncer = SliderSpinSyncer(self.velocity_slider, self.velocity_spin, self.motion_changed) self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider, self.acceleration_spin, self.motion_changed) self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider, self.deceleration_spin, self.motion_changed) self.period_syncer = SliderSpinSyncer(self.period_slider, self.period_spin, self.period_changed) self.pulse_width_min_spin.editingFinished.connect(self.pulse_width_spin_finished) self.pulse_width_max_spin.editingFinished.connect(self.pulse_width_spin_finished) self.degree_min_spin.editingFinished.connect(self.degree_spin_finished) self.degree_max_spin.editingFinished.connect(self.degree_spin_finished)
class EnergyMonitor(COMCUPluginBase, Ui_EnergyMonitor): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletEnergyMonitor, *args) self.setupUi(self) self.energy_monitor = self.device self.cbe_get_energy_data = CallbackEmulator(self, self.energy_monitor.get_energy_data, None, self.cb_energy_data, self.increase_error_count) self.cbe_get_transformer_status = CallbackEmulator(self, self.energy_monitor.get_transformer_status, None, self.cb_transformer_status, self.increase_error_count) plots_waveform_v = [('Waveform V', Qt.red, None, None)] self.plot_widget_waveform_v = PlotWidget('Voltage [V]', plots_waveform_v, clear_button=None, x_diff=768*ENERGY_MONITOR_MS_PER_TICK, x_scale_title_text='Time [ms]', key=None, x_scale_visible=False) plots_waveform_a = [('Waveform A', Qt.red, None, None)] self.plot_widget_waveform_a = PlotWidget('Current [A]', plots_waveform_a, clear_button=None, x_diff=768*ENERGY_MONITOR_MS_PER_TICK, x_scale_title_text='Time [ms]', key=None) self.plot_widget_waveform_v.add_y_scale_sibling(self.plot_widget_waveform_a) self.plot_widget_waveform_a.add_y_scale_sibling(self.plot_widget_waveform_v) # try to make the actual curve area equal in height by fiddling with the # minimum-height and the stretch factors self.plot_widget_waveform_v.setMinimumHeight(194) self.plot_widget_waveform_a.setMinimumHeight(250) self.layout_graph.insertWidget(0, self.plot_widget_waveform_v, 86) self.layout_graph.addWidget(self.plot_widget_waveform_a, 100) self.x_data = [x * ENERGY_MONITOR_MS_PER_TICK for x in list(range(768))] self.button_energy.clicked.connect(self.button_energy_clicked) self.button_transformer_settings.clicked.connect(self.button_transformer_settings_clicked) self.voltage_connected = True self.current_connected = True self.running = False def button_energy_clicked(self): self.energy_monitor.reset_energy() def button_transformer_settings_clicked(self): voltage_ratio = int(self.spinbox_voltage_ratio.value()*100) current_ratio = int(self.spinbox_current_ratio.value()*100) self.energy_monitor.set_transformer_calibration(voltage_ratio, current_ratio, 0) def cb_waveform_error(self): self.increase_error_count() if self.running: async_call(self.energy_monitor.get_waveform, None, self.cb_waveform, self.cb_waveform_error, delay=0.5) def cb_waveform(self, waveform): y_data_v = [x*0.1 for x in waveform[::2]] y_data_a = [x*0.01 for x in waveform[1::2]] self.plot_widget_waveform_v.set_data(0, self.x_data, y_data_v) self.plot_widget_waveform_a.set_data(0, self.x_data, y_data_a) if self.running: async_call(self.energy_monitor.get_waveform, None, self.cb_waveform, self.cb_waveform_error, delay=0.5) def cb_energy_data(self, data): if self.voltage_connected: if self.label_voltage.text() == NOT_CONNECTED: self.label_voltage.maximum_size_hint = None self.label_voltage.setText('{0:.2f}'.format(data.voltage / 100)) else: self.label_voltage.setText(NOT_CONNECTED) if self.current_connected: if self.label_current.text() == NOT_CONNECTED: self.label_current.maximum_size_hint = None self.label_current.setText('{0:.2f}'.format(data.current / 100)) else: self.label_current.setText(NOT_CONNECTED) self.label_energy.setText('{0:.2f}'.format(data.energy / 100)) self.label_real_power.setText('{0:.2f}'.format(data.real_power / 100)) self.label_apparent_power.setText('{0:.2f}'.format(data.apparent_power / 100)) self.label_reactive_power.setText('{0:.2f}'.format(data.reactive_power / 100)) self.label_power_factor.setText('{0:.2f}'.format((data.power_factor // 10) / 100)) self.label_frequency.setText('{0:.2f}'.format(data.frequency / 100)) def cb_transformer_status(self, status): self.voltage_connected = status.voltage_transformer_connected self.current_connected = status.current_transformer_connected if not self.voltage_connected: self.label_voltage.setText(NOT_CONNECTED) if not self.current_connected: self.label_current.setText(NOT_CONNECTED) def cb_transformer_calibration(self, cal): self.spinbox_voltage_ratio.setValue(cal.voltage_ratio/100.0) self.spinbox_current_ratio.setValue(cal.current_ratio/100.0) def start(self): self.running = True async_call(self.energy_monitor.get_transformer_calibration, None, self.cb_transformer_calibration, self.increase_error_count) async_call(self.energy_monitor.get_waveform, None, self.cb_waveform, self.cb_waveform_error) self.cbe_get_energy_data.set_period(200) self.cbe_get_transformer_status.set_period(200) def stop(self): self.running = False self.cbe_get_energy_data.set_period(0) self.cbe_get_transformer_status.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletEnergyMonitor.DEVICE_IDENTIFIER
class IMUV2(PluginBase, Ui_IMUV2): def __init__(self, *args): PluginBase.__init__(self, BrickIMUV2, *args) self.setupUi(self) self.imu = self.device self.cbe_all_data = CallbackEmulator(self.imu.get_all_data, None, self.cb_all_data, self.increase_error_count) self.imu_gl = IMUV23DWidget(self) self.imu_gl.setFixedSize(200, 200) self.imu_gl_wrapper = None self.state = None self.data_plot_widget = [] self.sensor_data = [CurveValueWrapper() for i in range(23)] self.data_labels = [ self.label_acceleration_x, self.label_acceleration_y, self.label_acceleration_z, self.label_magnetic_field_x, self.label_magnetic_field_y, self.label_magnetic_field_z, self.label_angular_velocity_x, self.label_angular_velocity_y, self.label_angular_velocity_z, self.label_euler_angle_heading, self.label_euler_angle_roll, self.label_euler_angle_pitch, self.label_quaternion_w, self.label_quaternion_x, self.label_quaternion_y, self.label_quaternion_z, self.label_linear_acceleration_x, self.label_linear_acceleration_y, self.label_linear_acceleration_z, self.label_gravity_vector_x, self.label_gravity_vector_y, self.label_gravity_vector_z, self.label_temperature ] self.data_rows = [ [ self.label_acceleration_11, self.label_acceleration_21, self.label_acceleration_22, self.label_acceleration_23, self.label_acceleration_41, self.label_acceleration_42, self.label_acceleration_43, self.label_acceleration_x, self.label_acceleration_y, self.label_acceleration_z ], [ self.label_magnetic_field_11, self.label_magnetic_field_21, self.label_magnetic_field_22, self.label_magnetic_field_23, self.label_magnetic_field_41, self.label_magnetic_field_42, self.label_magnetic_field_43, self.label_magnetic_field_x, self.label_magnetic_field_y, self.label_magnetic_field_z ], [ self.label_angular_velocity_11, self.label_angular_velocity_21, self.label_angular_velocity_22, self.label_angular_velocity_23, self.label_angular_velocity_41, self.label_angular_velocity_42, self.label_angular_velocity_43, self.label_angular_velocity_x, self.label_angular_velocity_y, self.label_angular_velocity_z ], [ self.label_euler_angle_11, self.label_euler_angle_21, self.label_euler_angle_22, self.label_euler_angle_23, self.label_euler_angle_41, self.label_euler_angle_42, self.label_euler_angle_43, self.label_euler_angle_roll, self.label_euler_angle_pitch, self.label_euler_angle_heading ], [ self.label_quaternion_11, self.label_quaternion_21, self.label_quaternion_22, self.label_quaternion_23, self.label_quaternion_24, self.label_quaternion_41, self.label_quaternion_42, self.label_quaternion_43, self.label_quaternion_44, self.label_quaternion_w, self.label_quaternion_x, self.label_quaternion_y, self.label_quaternion_z ], [ self.label_linear_acceleration_11, self.label_linear_acceleration_21, self.label_linear_acceleration_22, self.label_linear_acceleration_23, self.label_linear_acceleration_41, self.label_linear_acceleration_42, self.label_linear_acceleration_43, self.label_linear_acceleration_x, self.label_linear_acceleration_y, self.label_linear_acceleration_z ], [ self.label_gravity_vector_11, self.label_gravity_vector_21, self.label_gravity_vector_22, self.label_gravity_vector_23, self.label_gravity_vector_41, self.label_gravity_vector_42, self.label_gravity_vector_43, self.label_gravity_vector_x, self.label_gravity_vector_y, self.label_gravity_vector_z ], [ self.label_temperature_11, self.label_temperature_21, self.label_temperature_41, self.label_temperature ] ] even_color = QColor(240, 240, 240) odd_color = QColor(255, 255, 255) self.data_color = [(Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.red, odd_color), (Qt.darkGreen, odd_color), (Qt.blue, odd_color), (Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.red, odd_color), (Qt.darkGreen, odd_color), (Qt.blue, odd_color), (Qt.magenta, even_color), (Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.red, odd_color), (Qt.darkGreen, odd_color), (Qt.blue, odd_color), (Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.magenta, odd_color)] even_palette = QPalette() even_palette.setColor(QPalette.Window, even_color) odd_palette = QPalette() odd_palette.setColor(QPalette.Window, odd_color) for i, row in enumerate(self.data_rows): for label in row: if i % 2: label.setPalette(odd_palette) else: label.setPalette(even_palette) label.setAutoFillBackground(True) self.plot_timer = QTimer(self) self.plot_timer.start(100) for i in range(23): self.data_plot_widget.append( PlotWidget( "", [("", self.data_color[i][0], self.sensor_data[i], str)], clear_button=self.clear_graphs, x_scale_visible=False, y_scale_visible=False, curve_outer_border_visible=False, curve_motion='smooth', canvas_color=self.data_color[i][1], external_timer=self.plot_timer, curve_start='right', key=None, y_resolution=0.01)) for w in self.data_plot_widget: w.setMinimumHeight(15) w.setMaximumHeight(25) for i in range(23): self.data_grid.addWidget(self.data_plot_widget[i], i, 4) self.data_grid.setColumnMinimumWidth(2, 75) self.gl_layout = QVBoxLayout() self.gl_layout.addWidget(self.imu_gl) self.layout_bottom.addLayout(self.gl_layout) self.save_orientation.clicked.connect(self.save_orientation_clicked) self.button_detach_3d_view.clicked.connect(self.detach_3d_view_clicked) self.checkbox_leds.stateChanged.connect(self.led_clicked) self.button_calibration.clicked.connect(self.calibration_clicked) self.calibration_color = [ Qt.red, QColor(0xFF, 0xA0, 0x00), Qt.yellow, Qt.darkGreen ] self.calibration = None self.alive = True self.callback_counter = 0 self.status_led_action = QAction('Status LED', self) self.status_led_action.setCheckable(True) self.status_led_action.toggled.connect( lambda checked: self.imu.enable_status_led() if checked else self.imu.disable_status_led()) self.set_configs([(0, None, [self.status_led_action])]) reset = QAction('Reset', self) reset.triggered.connect(self.imu.reset) self.set_actions([(0, None, [reset])]) def save_orientation_clicked(self): self.imu_gl.save_orientation() if self.imu_gl_wrapper is not None: self.imu_gl_wrapper.glWidget.save_orientation() self.orientation_label.hide() def cleanup_gl(self): self.state = self.imu_gl.get_state() self.imu_gl.hide() self.imu_gl.cleanup() def restart_gl(self): self.imu_gl = IMUV23DWidget() self.imu_gl.setFixedSize(200, 200) self.gl_layout.addWidget(self.imu_gl) self.imu_gl.show() self.save_orientation.clicked.connect(self.save_orientation_clicked) self.imu_gl.set_state(self.state) def start(self): if not self.alive: return self.parent().add_callback_on_untab(lambda x: self.cleanup_gl(), 'imu_v2_cleanup_on_untab') self.parent().add_callback_post_untab(lambda x: self.restart_gl(), 'imu_v2_restart_post_untab') self.parent().add_callback_on_tab(lambda x: self.cleanup_gl(), 'imu_v2_cleanup_on_tab') self.parent().add_callback_post_tab(lambda x: self.restart_gl(), 'imu_v2_restart_post_tab') self.gl_layout.activate() async_call(self.imu.is_status_led_enabled, None, self.status_led_action.setChecked, self.increase_error_count) async_call(self.imu.are_leds_on, None, self.checkbox_leds.setChecked, self.increase_error_count) self.cbe_all_data.set_period(50) for w in self.data_plot_widget: w.stop = False def stop(self): for w in self.data_plot_widget: w.stop = True if self.imu_gl_wrapper == None: self.cbe_all_data.set_period(0) def destroy(self): self.alive = False self.cleanup_gl() # Stop callback to fix deadlock with callback emulation thread. self.cbe_all_data.set_period(0) if self.calibration != None: self.calibration.close() if self.imu_gl_wrapper != None: self.imu_gl_wrapper.close() @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickIMUV2.DEVICE_IDENTIFIER def calibration_clicked(self): if self.calibration is None: self.calibration = Calibration(self) self.button_calibration.setEnabled(False) self.calibration.show() def detach_3d_view_clicked(self): if self.imu_gl_wrapper != None: self.imu_gl_wrapper.close() self.button_detach_3d_view.setEnabled(False) self.imu_gl_wrapper = WrapperWidget(self) self.imu_gl_wrapper.glWidget.set_state(self.imu_gl.get_state()) self.save_orientation.clicked.connect(self.save_orientation_clicked) self.imu_gl_wrapper.show() def cb_all_data(self, data): self.callback_counter += 1 if self.callback_counter == 2: self.callback_counter = 0 self.sensor_data[0].value = data.acceleration[0] / 100.0 self.sensor_data[1].value = data.acceleration[1] / 100.0 self.sensor_data[2].value = data.acceleration[2] / 100.0 self.sensor_data[3].value = data.magnetic_field[0] / 16.0 self.sensor_data[4].value = data.magnetic_field[1] / 16.0 self.sensor_data[5].value = data.magnetic_field[2] / 16.0 self.sensor_data[6].value = data.angular_velocity[0] / 16.0 self.sensor_data[7].value = data.angular_velocity[1] / 16.0 self.sensor_data[8].value = data.angular_velocity[2] / 16.0 self.sensor_data[9].value = data.euler_angle[0] / 16.0 self.sensor_data[10].value = data.euler_angle[1] / 16.0 self.sensor_data[11].value = data.euler_angle[2] / 16.0 self.sensor_data[12].value = data.quaternion[0] / (2**14 - 1) self.sensor_data[13].value = data.quaternion[1] / (2**14 - 1) self.sensor_data[14].value = data.quaternion[2] / (2**14 - 1) self.sensor_data[15].value = data.quaternion[3] / (2**14 - 1) self.sensor_data[16].value = data.linear_acceleration[0] / 100.0 self.sensor_data[17].value = data.linear_acceleration[1] / 100.0 self.sensor_data[18].value = data.linear_acceleration[2] / 100.0 self.sensor_data[19].value = data.gravity_vector[0] / 100.0 self.sensor_data[20].value = data.gravity_vector[1] / 100.0 self.sensor_data[21].value = data.gravity_vector[2] / 100.0 self.sensor_data[22].value = data.temperature for i in range(23): self.data_labels[i].setText("{0:.2f}".format( self.sensor_data[i].value)) self.imu_gl.update_orientation(self.sensor_data[12].value, self.sensor_data[13].value, self.sensor_data[14].value, self.sensor_data[15].value) if self.imu_gl_wrapper is not None: self.imu_gl_wrapper.glWidget.update_orientation( self.sensor_data[12].value, self.sensor_data[13].value, self.sensor_data[14].value, self.sensor_data[15].value) cal_mag = data.calibration_status & 3 cal_acc = (data.calibration_status & (3 << 2)) >> 2 cal_gyr = (data.calibration_status & (3 << 4)) >> 4 cal_sys = (data.calibration_status & (3 << 6)) >> 6 if self.calibration != None: self.calibration.save_calibration.setEnabled( data.calibration_status == 0xFF) self.calibration.mag_color.set_color( self.calibration_color[cal_mag]) self.calibration.acc_color.set_color( self.calibration_color[cal_acc]) self.calibration.gyr_color.set_color( self.calibration_color[cal_gyr]) self.calibration.sys_color.set_color( self.calibration_color[cal_sys]) else: self.imu_gl.update_orientation(data.quaternion[0] / (2**14 - 1), data.quaternion[1] / (2**14 - 1), data.quaternion[2] / (2**14 - 1), data.quaternion[3] / (2**14 - 1)) if self.imu_gl_wrapper is not None: self.imu_gl_wrapper.glWidget.update_orientation( data.quaternion[0] / (2**14 - 1), data.quaternion[1] / (2**14 - 1), data.quaternion[2] / (2**14 - 1), data.quaternion[3] / (2**14 - 1)) def led_clicked(self, state): if state == Qt.Checked: self.imu.leds_on() else: self.imu.leds_off()
class HATZero(COMCUPluginBase, Ui_HATZero): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickHATZero, *args) self.setupUi(self) self.hat_zero = self.device self.cbe_voltage = CallbackEmulator(self, self.hat_zero.get_usb_voltage, None, self.cb_usb_voltage, self.increase_error_count) self.ports = [self.port_a, self.port_b, self.port_c, self.port_d] for port in self.ports: port.setProperty('_bricklet_uid', None) port.setEnabled(False) port.clicked.connect(self.port_clicked) self.update_timer = QTimer(self) self.update_timer.timeout.connect(self.update_bricklets) def cb_usb_voltage(self, voltage): self.label_usb_voltage.setText('{:.2f}V'.format(voltage / 1000)) def port_clicked(self): uid = self.sender().property('_bricklet_uid') if uid != None: get_main_window().show_plugin(uid) def update_bricklets(self): info = inventory.get_info(self.uid) if info == None: return for i in range(4): port = chr(ord('a') + i) try: bricklet = info.connections_get(port)[0] text = '{0} ({1})'.format(bricklet.name, bricklet.uid) if text != self.ports[i].text(): self.ports[i].setText(text) self.ports[i].setProperty('_bricklet_uid', bricklet.uid) self.ports[i].setEnabled(True) except: self.ports[i].setText('Not Connected') self.ports[i].setProperty('_bricklet_uid', None) self.ports[i].setEnabled(False) def start(self): self.cbe_voltage.set_period(250) self.update_bricklets() self.update_timer.start(500) def stop(self): self.cbe_voltage.set_period(0) self.update_timer.stop() def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickHATZero.DEVICE_IDENTIFIER
def __init__(self, *args): PluginBase.__init__(self, BrickIMUV2, *args) self.setupUi(self) self.imu = self.device self.cbe_all_data = CallbackEmulator(self.imu.get_all_data, None, self.cb_all_data, self.increase_error_count) self.imu_gl = IMUV23DWidget(self) self.imu_gl.setFixedSize(200, 200) self.imu_gl_wrapper = None self.state = None self.data_plot_widget = [] self.sensor_data = [CurveValueWrapper() for i in range(23)] self.data_labels = [ self.label_acceleration_x, self.label_acceleration_y, self.label_acceleration_z, self.label_magnetic_field_x, self.label_magnetic_field_y, self.label_magnetic_field_z, self.label_angular_velocity_x, self.label_angular_velocity_y, self.label_angular_velocity_z, self.label_euler_angle_heading, self.label_euler_angle_roll, self.label_euler_angle_pitch, self.label_quaternion_w, self.label_quaternion_x, self.label_quaternion_y, self.label_quaternion_z, self.label_linear_acceleration_x, self.label_linear_acceleration_y, self.label_linear_acceleration_z, self.label_gravity_vector_x, self.label_gravity_vector_y, self.label_gravity_vector_z, self.label_temperature ] self.data_rows = [ [ self.label_acceleration_11, self.label_acceleration_21, self.label_acceleration_22, self.label_acceleration_23, self.label_acceleration_41, self.label_acceleration_42, self.label_acceleration_43, self.label_acceleration_x, self.label_acceleration_y, self.label_acceleration_z ], [ self.label_magnetic_field_11, self.label_magnetic_field_21, self.label_magnetic_field_22, self.label_magnetic_field_23, self.label_magnetic_field_41, self.label_magnetic_field_42, self.label_magnetic_field_43, self.label_magnetic_field_x, self.label_magnetic_field_y, self.label_magnetic_field_z ], [ self.label_angular_velocity_11, self.label_angular_velocity_21, self.label_angular_velocity_22, self.label_angular_velocity_23, self.label_angular_velocity_41, self.label_angular_velocity_42, self.label_angular_velocity_43, self.label_angular_velocity_x, self.label_angular_velocity_y, self.label_angular_velocity_z ], [ self.label_euler_angle_11, self.label_euler_angle_21, self.label_euler_angle_22, self.label_euler_angle_23, self.label_euler_angle_41, self.label_euler_angle_42, self.label_euler_angle_43, self.label_euler_angle_roll, self.label_euler_angle_pitch, self.label_euler_angle_heading ], [ self.label_quaternion_11, self.label_quaternion_21, self.label_quaternion_22, self.label_quaternion_23, self.label_quaternion_24, self.label_quaternion_41, self.label_quaternion_42, self.label_quaternion_43, self.label_quaternion_44, self.label_quaternion_w, self.label_quaternion_x, self.label_quaternion_y, self.label_quaternion_z ], [ self.label_linear_acceleration_11, self.label_linear_acceleration_21, self.label_linear_acceleration_22, self.label_linear_acceleration_23, self.label_linear_acceleration_41, self.label_linear_acceleration_42, self.label_linear_acceleration_43, self.label_linear_acceleration_x, self.label_linear_acceleration_y, self.label_linear_acceleration_z ], [ self.label_gravity_vector_11, self.label_gravity_vector_21, self.label_gravity_vector_22, self.label_gravity_vector_23, self.label_gravity_vector_41, self.label_gravity_vector_42, self.label_gravity_vector_43, self.label_gravity_vector_x, self.label_gravity_vector_y, self.label_gravity_vector_z ], [ self.label_temperature_11, self.label_temperature_21, self.label_temperature_41, self.label_temperature ] ] even_color = QColor(240, 240, 240) odd_color = QColor(255, 255, 255) self.data_color = [(Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.red, odd_color), (Qt.darkGreen, odd_color), (Qt.blue, odd_color), (Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.red, odd_color), (Qt.darkGreen, odd_color), (Qt.blue, odd_color), (Qt.magenta, even_color), (Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.red, odd_color), (Qt.darkGreen, odd_color), (Qt.blue, odd_color), (Qt.red, even_color), (Qt.darkGreen, even_color), (Qt.blue, even_color), (Qt.magenta, odd_color)] even_palette = QPalette() even_palette.setColor(QPalette.Window, even_color) odd_palette = QPalette() odd_palette.setColor(QPalette.Window, odd_color) for i, row in enumerate(self.data_rows): for label in row: if i % 2: label.setPalette(odd_palette) else: label.setPalette(even_palette) label.setAutoFillBackground(True) self.plot_timer = QTimer(self) self.plot_timer.start(100) for i in range(23): self.data_plot_widget.append( PlotWidget( "", [("", self.data_color[i][0], self.sensor_data[i], str)], clear_button=self.clear_graphs, x_scale_visible=False, y_scale_visible=False, curve_outer_border_visible=False, curve_motion='smooth', canvas_color=self.data_color[i][1], external_timer=self.plot_timer, curve_start='right', key=None, y_resolution=0.01)) for w in self.data_plot_widget: w.setMinimumHeight(15) w.setMaximumHeight(25) for i in range(23): self.data_grid.addWidget(self.data_plot_widget[i], i, 4) self.data_grid.setColumnMinimumWidth(2, 75) self.gl_layout = QVBoxLayout() self.gl_layout.addWidget(self.imu_gl) self.layout_bottom.addLayout(self.gl_layout) self.save_orientation.clicked.connect(self.save_orientation_clicked) self.button_detach_3d_view.clicked.connect(self.detach_3d_view_clicked) self.checkbox_leds.stateChanged.connect(self.led_clicked) self.button_calibration.clicked.connect(self.calibration_clicked) self.calibration_color = [ Qt.red, QColor(0xFF, 0xA0, 0x00), Qt.yellow, Qt.darkGreen ] self.calibration = None self.alive = True self.callback_counter = 0 self.status_led_action = QAction('Status LED', self) self.status_led_action.setCheckable(True) self.status_led_action.toggled.connect( lambda checked: self.imu.enable_status_led() if checked else self.imu.disable_status_led()) self.set_configs([(0, None, [self.status_led_action])]) reset = QAction('Reset', self) reset.triggered.connect(self.imu.reset) self.set_actions([(0, None, [reset])])
class TemperatureV2(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletTemperatureV2, *args) self.tem = self.device self.cbe_temperature = CallbackEmulator(self, self.tem.get_temperature, None, self.cb_temperature, self.increase_error_count) self.current_temperature = CurveValueWrapper() # float, °C plots_temperature = [('Temperature', Qt.red, self.current_temperature, '{} °C'.format)] self.plot_widget_temperature = PlotWidget('Temperature [°C]', plots_temperature, y_resolution=0.01) self.enable_heater = QCheckBox("Enable Heater") self.enable_heater.stateChanged.connect(self.enable_heater_changed) layout_plot = QHBoxLayout() layout_plot.addWidget(self.plot_widget_temperature) layout_config = QHBoxLayout() layout_config.addStretch() layout_config.addWidget(self.enable_heater) layout_config.addStretch() layout_main = QVBoxLayout(self) layout_main.addLayout(layout_plot) layout_main.addLayout(layout_config) def enable_heater_changed(self, state): if state == Qt.Checked: self.tem.set_heater_configuration(self.tem.HEATER_CONFIG_ENABLED) else: self.tem.set_heater_configuration(self.tem.HEATER_CONFIG_DISABLED) def start(self): async_call(self.tem.get_heater_configuration, None, self.get_heater_configuration_async, self.increase_error_count) self.cbe_temperature.set_period(250) self.plot_widget_temperature.stop = False def stop(self): self.cbe_temperature.set_period(0) self.plot_widget_temperature.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletTemperatureV2.DEVICE_IDENTIFIER def cb_temperature(self, temperature): self.current_temperature.value = temperature / 100.0 def get_heater_configuration_async(self, heater_config): if heater_config == 0: self.enable_heater.setChecked(False) else: self.enable_heater.setChecked(True)
def __init__(self, *args): PluginBase.__init__(self, BrickletThermocouple, *args) self.thermo = self.device self.qtcb_error_state.connect(self.cb_error_state) self.thermo.register_callback(self.thermo.CALLBACK_ERROR_STATE, self.qtcb_error_state.emit) self.cbe_temperature = CallbackEmulator(self.thermo.get_temperature, self.cb_temperature, self.increase_error_count) self.current_temperature = None # float, °C self.error_label = QLabel('Current Errors: None') self.error_label.setAlignment(Qt.AlignVCenter | Qt.AlignRight) plots = [('Temperature', Qt.red, lambda: self.current_temperature, u'{:.2f} °C'.format)] self.plot_widget = PlotWidget(u'Temperature [°C]', plots, extra_key_widgets=[self.error_label]) self.averaging_label = QLabel('Averaging:') self.averaging_combo = QComboBox() self.averaging_combo.addItem('1', BrickletThermocouple.AVERAGING_1) self.averaging_combo.addItem('2', BrickletThermocouple.AVERAGING_2) self.averaging_combo.addItem('4', BrickletThermocouple.AVERAGING_4) self.averaging_combo.addItem('8', BrickletThermocouple.AVERAGING_8) self.averaging_combo.addItem('16', BrickletThermocouple.AVERAGING_16) self.type_label = QLabel('Thermocouple Type:') self.type_combo = QComboBox() self.type_combo.addItem('B', BrickletThermocouple.TYPE_B) self.type_combo.addItem('E', BrickletThermocouple.TYPE_E) self.type_combo.addItem('J', BrickletThermocouple.TYPE_J) self.type_combo.addItem('K', BrickletThermocouple.TYPE_K) self.type_combo.addItem('N', BrickletThermocouple.TYPE_N) self.type_combo.addItem('R', BrickletThermocouple.TYPE_R) self.type_combo.addItem('S', BrickletThermocouple.TYPE_S) self.type_combo.addItem('T', BrickletThermocouple.TYPE_T) self.type_combo.addItem('Gain 8', BrickletThermocouple.TYPE_G8) self.type_combo.addItem('Gain 32', BrickletThermocouple.TYPE_G32) self.filter_label = QLabel('Noise Rejection Filter:') self.filter_combo = QComboBox() self.filter_combo.addItem('50 Hz', BrickletThermocouple.FILTER_OPTION_50HZ) self.filter_combo.addItem('60 Hz', BrickletThermocouple.FILTER_OPTION_60HZ) hlayout = QHBoxLayout() hlayout.addWidget(self.averaging_label) hlayout.addWidget(self.averaging_combo) hlayout.addStretch() hlayout.addWidget(self.type_label) hlayout.addWidget(self.type_combo) hlayout.addStretch() hlayout.addWidget(self.filter_label) hlayout.addWidget(self.filter_combo) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) self.averaging_combo.currentIndexChanged.connect( self.configuration_changed) self.type_combo.currentIndexChanged.connect(self.configuration_changed) self.filter_combo.currentIndexChanged.connect( self.configuration_changed)
class SoundIntensity(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletSoundIntensity, *args) self.si = self.device self.cbe_intensity = CallbackEmulator(self.si.get_intensity, self.cb_intensity, self.increase_error_count) self.intensity_label = IntensityLabel() self.current_value = None self.thermo = TuningThermo() #plot_list = [['', Qt.red, self.get_current_value]] #self.plot_widget = PlotWidget('Intensity Value', plot_list) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(self.intensity_label) layout_h.addStretch() layout_h2 = QHBoxLayout() layout_h2.addStretch() layout_h2.addWidget(self.thermo) layout_h2.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addLayout(layout_h2) layout.addStretch() #layout.addWidget(QLabel('')) # abuse a label as a fixed-size spacer #layout.addWidget(self.plot_widget) def get_current_value(self): return self.current_value def cb_intensity(self, intensity): self.thermo.set_value(intensity) self.current_value = intensity self.intensity_label.setText(str(intensity)) def start(self): async_call(self.si.get_intensity, None, self.cb_intensity, self.increase_error_count) self.cbe_intensity.set_period(25) #self.plot_widget.stop = False def stop(self): self.cbe_intensity.set_period(0) #self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'sound_intensity' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletSoundIntensity.DEVICE_IDENTIFIER
class Calibration(QDialog, Ui_Calibration): def __init__(self, parent): QDialog.__init__(self, parent, get_modeless_dialog_flags()) self.parent = parent self.setupUi(self) # Synced voltage, current and power. Updated with callbacks. self.voltage = 0 self.current = 0 self.power = 0 # Synced calibration parameters. Updated with get_calibration() calls. self.cal_v_mul = 1 self.cal_v_div = 1 self.cal_c_mul = 1 self.cal_c_div = 1 self.btn_cal_v.clicked.connect(self.cal_v_clicked) self.btn_cal_c.clicked.connect(self.cal_c_clicked) self.btn_cal_rst.clicked.connect(self.cal_rst_clicked) self.cbe_voltage = CallbackEmulator(self.parent.vc.get_voltage, None, self.cb_voltage, self.parent.increase_error_count) self.cbe_current = CallbackEmulator(self.parent.vc.get_current, None, self.cb_current, self.parent.increase_error_count) self.cbe_power = CallbackEmulator(self.parent.vc.get_power, None, self.cb_power, self.parent.increase_error_count) 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) def cal_rst_clicked(self): self.parent.vc.set_calibration(1, 1, 1, 1) async_call(self.parent.vc.get_calibration, None, self.get_calibration_async, self.parent.increase_error_count) def cal_v_clicked(self): self.parent.vc.set_calibration(self.sbox_cal_v_mul.value(), self.voltage, 1, 1) async_call(self.parent.vc.get_calibration, None, self.get_calibration_async, self.parent.increase_error_count) def cal_c_clicked(self): self.parent.vc.set_calibration(self.cal_v_mul, self.cal_v_div, self.sbox_cal_c_mul.value(), self.current) async_call(self.parent.vc.get_calibration, None, self.get_calibration_async, self.parent.increase_error_count) def get_calibration_async(self, cal): self.cal_v_mul = cal.voltage_multiplier self.cal_v_div = cal.voltage_divisor self.cal_c_mul = cal.current_multiplier self.cal_c_div = cal.current_divisor self.sbox_cal_v_mul.setValue(self.cal_v_mul) self.sbox_cal_c_mul.setValue(self.cal_c_mul) def cb_voltage(self, voltage): self.voltage = voltage if (self.voltage / 1000.0) < 1.0: self.lbl_voltage.setText(str(self.voltage) + ' mV') else: self.lbl_voltage.setText(str(self.voltage / 1000.0) + ' V') def cb_current(self, current): self.current = current if (self.current / 1000.0) < 1.0: self.lbl_current.setText(str(self.current) + ' mA') else: self.lbl_current.setText(str(self.current / 1000.0) + ' A') def cb_power(self, power): self.power = power if (self.power / 1000.0) < 1.0: self.lbl_power.setText(str(self.power) + ' mW') else: self.lbl_power.setText(str(self.power / 1000.0) + ' W') def closeEvent(self, event): self.cbe_voltage.set_period(0) self.cbe_current.set_period(0) self.cbe_power.set_period(0) self.parent.button_calibration.setEnabled(True)
class Barometer(PluginBase): def __init__(self, *args): super().__init__(BrickletBarometer, *args) self.barometer = self.device # the firmware version of a EEPROM Bricklet can (under common circumstances) # not change during the lifetime of an EEPROM Bricklet plugin. therefore, # it's okay to make final decisions based on it here self.has_averaging = self.firmware_version >= (2, 0, 2) self.moving_average_pressure = 25 self.average_pressure = 10 self.average_temperature = 10 self.cbe_air_pressure = CallbackEmulator( self.barometer.get_air_pressure, None, self.cb_air_pressure, self.increase_error_count) self.cbe_altitude = CallbackEmulator(self.barometer.get_altitude, None, self.cb_altitude, self.increase_error_count) self.cbe_chip_temperature = CallbackEmulator( self.barometer.get_chip_temperature, None, self.cb_chip_temperature, self.increase_error_count) self.chip_temperature_label = ChipTemperatureLabel() self.current_air_pressure = CurveValueWrapper() # float, hPa self.current_altitude = CurveValueWrapper() # float, m self.clear_graphs_button = QPushButton('Clear Graphs') plots = [('Air Pressure', Qt.red, self.current_air_pressure, '{:.3f} hPa (QFE)'.format)] self.air_pressure_plot_widget = PlotWidget('Air Pressure [hPa]', plots, self.clear_graphs_button, y_resolution=0.001) plots = [('Altitude', Qt.darkGreen, self.current_altitude, lambda value: '{:.2f} m ({:.2f} ft)'.format( value, value / METER_TO_FEET_DIVISOR))] self.altitude_plot_widget = PlotWidget('Altitude [m]', plots, self.clear_graphs_button, y_resolution=0.01) self.reference_label = QLabel('Reference Air Pressure [hPa]:') self.reference_box = QDoubleSpinBox() self.reference_box.setMinimum(10) self.reference_box.setMaximum(1200) self.reference_box.setDecimals(3) self.reference_box.setValue(1013.25) self.reference_box.editingFinished.connect(self.reference_box_finished) self.use_current_button = QPushButton('Use Current') self.use_current_button.clicked.connect(self.use_current_clicked) if self.has_averaging: self.avg_pressure_box = QSpinBox() self.avg_pressure_box.setMinimum(0) self.avg_pressure_box.setMaximum(10) self.avg_pressure_box.setSingleStep(1) self.avg_pressure_box.setValue(10) self.avg_pressure_box.editingFinished.connect( self.avg_pressure_box_finished) self.avg_temperature_box = QSpinBox() self.avg_temperature_box.setMinimum(0) self.avg_temperature_box.setMaximum(255) self.avg_temperature_box.setSingleStep(1) self.avg_temperature_box.setValue(10) self.avg_temperature_box.editingFinished.connect( self.avg_temperature_box_finished) self.avg_moving_pressure_box = QSpinBox() self.avg_moving_pressure_box.setMinimum(0) self.avg_moving_pressure_box.setMaximum(25) self.avg_moving_pressure_box.setSingleStep(1) self.avg_moving_pressure_box.setValue(25) self.avg_moving_pressure_box.editingFinished.connect( self.avg_moving_pressure_box_finished) layout_h1 = QHBoxLayout() layout_h1.addWidget(self.air_pressure_plot_widget) layout_h1.addWidget(self.altitude_plot_widget) layout = QVBoxLayout(self) layout.addLayout(layout_h1) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout.addWidget(line) layout_h2 = QHBoxLayout() layout_h2.addWidget(self.reference_label) layout_h2.addWidget(self.reference_box) layout_h2.addWidget(self.use_current_button) layout_h2.addStretch() layout_h2.addWidget(self.chip_temperature_label) layout_h2.addStretch() layout_h2.addWidget(self.clear_graphs_button) layout.addLayout(layout_h2) if self.has_averaging: layout_h3 = QHBoxLayout() layout_h3.addWidget(QLabel('Air Pressure Moving Average Length:')) layout_h3.addWidget(self.avg_moving_pressure_box) layout_h3.addStretch() layout_h3.addWidget(QLabel('Air Pressure Average Length:')) layout_h3.addWidget(self.avg_pressure_box) layout_h3.addStretch() layout_h3.addWidget(QLabel('Temperate Average Length:')) layout_h3.addWidget(self.avg_temperature_box) layout.addLayout(layout_h3) def start(self): if self.has_averaging: async_call(self.barometer.get_averaging, None, self.get_averaging_async, self.increase_error_count) async_call(self.barometer.get_reference_air_pressure, None, self.get_reference_air_pressure_async, self.increase_error_count) self.cbe_air_pressure.set_period(100) self.cbe_altitude.set_period(100) self.cbe_chip_temperature.set_period(100) self.air_pressure_plot_widget.stop = False self.altitude_plot_widget.stop = False def stop(self): self.cbe_air_pressure.set_period(0) self.cbe_altitude.set_period(0) self.cbe_chip_temperature.set_period(0) self.air_pressure_plot_widget.stop = True self.altitude_plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletBarometer.DEVICE_IDENTIFIER def get_averaging_async(self, avg): moving_average_pressure, average_pressure, average_temperature = avg self.moving_average_pressure = moving_average_pressure self.average_pressure = average_pressure self.average_temperature = average_temperature self.avg_moving_pressure_box.setValue(moving_average_pressure) self.avg_pressure_box.setValue(average_pressure) self.avg_temperature_box.setValue(average_temperature) def avg_pressure_box_finished(self): self.average_pressure = self.avg_pressure_box.value() self.save_new_averaging() def avg_temperature_box_finished(self): self.average_temperature = self.avg_temperature_box.value() self.save_new_averaging() def avg_moving_pressure_box_finished(self): self.moving_average_pressure = self.avg_moving_pressure_box.value() self.save_new_averaging() def save_new_averaging(self): self.barometer.set_averaging(self.moving_average_pressure, self.average_pressure, self.average_temperature) def get_reference_air_pressure_async(self, reference): self.reference_box.setValue(reference / 1000.0) def use_current_clicked(self): self.barometer.set_reference_air_pressure(0) async_call(self.barometer.get_reference_air_pressure, None, self.get_reference_air_pressure_async, self.increase_error_count) def reference_box_finished(self): self.barometer.set_reference_air_pressure(self.reference_box.value() * 1000.0) def cb_air_pressure(self, air_pressure): self.current_air_pressure.value = air_pressure / 1000.0 def cb_altitude(self, altitude): self.current_altitude.value = altitude / 100.0 def cb_chip_temperature(self, temperature): self.chip_temperature_label.setText('{:.2f}'.format(temperature / 100.0))
class Calibration(QDialog, Ui_Calibration): def __init__(self, parent): QDialog.__init__(self, parent, get_modeless_dialog_flags()) self.parent = parent self.values0 = [0]*10 self.values1 = [0]*10 self.values_index = 0 self.setupUi(self) self.button_cal_remove.clicked.connect(self.remove_clicked) self.button_cal_offset.clicked.connect(self.offset_clicked) self.button_cal_gain.clicked.connect(self.gain_clicked) self.cbe_adc = CallbackEmulator(self.parent.analog_in.get_adc_values, self.cb_adc_values, self.parent.increase_error_count) def show(self): QDialog.show(self) self.cbe_adc.set_period(100) self.current_offset0 = 0 self.current_offset1 = 0 self.current_gain0 = 0 self.current_gain1 = 0 self.update_calibration() def update_calibration(self): async_call(self.parent.analog_in.get_calibration, None, self.cb_get_calibration, self.parent.increase_error_count) def remove_clicked(self): self.parent.analog_in.set_calibration((0, 0), (0, 0)) self.update_calibration() def offset_clicked(self): self.parent.analog_in.set_calibration((-sum(self.values0)/10, -sum(self.values1)/10), (self.current_gain0, self.current_gain1)) self.update_calibration() def gain_clicked(self): try: measured0 = (sum(self.values0)/10.0)*244/44983 measured1 = (sum(self.values1)/10.0)*244/44983 factor0 = self.spinbox_voltage_ch0.value()/measured0 factor1 = self.spinbox_voltage_ch1.value()/measured1 gain0 = int((factor0-1)*2**23) gain1 = int((factor1-1)*2**23) if not is_int32(gain0) or not is_int32(gain1): raise ValueError("Out of range") except: QMessageBox.critical(self, "Failure during Calibration", "Calibration values are not in range.", QMessageBox.Ok) return self.parent.analog_in.set_calibration((self.current_offset0, self.current_offset1), (gain0, gain1)) self.update_calibration() def cb_get_calibration(self, cal): self.current_offset0 = cal.offset[0] self.current_offset1 = cal.offset[1] self.current_gain0 = cal.gain[0] self.current_gain1 = cal.gain[1] self.label_offset0.setText(str(cal.offset[0])) self.label_offset1.setText(str(cal.offset[1])) self.label_gain0.setText(str(cal.gain[0])) self.label_gain1.setText(str(cal.gain[1])) def cb_adc_values(self, values): self.values0[self.values_index] = values[0] self.values1[self.values_index] = values[1] self.values_index += 1 if self.values_index >= 10: self.values_index = 0 self.label_adc0.setText(str(sum(self.values0)/10)) self.label_adc1.setText(str(sum(self.values1)/10)) def closeEvent(self, event): self.parent.calibration_button.setEnabled(True) self.cbe_adc.set_period(0)
class Thermocouple(PluginBase): qtcb_error_state = pyqtSignal(bool, bool) def __init__(self, *args): PluginBase.__init__(self, BrickletThermocouple, *args) self.thermo = self.device self.qtcb_error_state.connect(self.cb_error_state) self.thermo.register_callback(self.thermo.CALLBACK_ERROR_STATE, self.qtcb_error_state.emit) self.cbe_temperature = CallbackEmulator(self.thermo.get_temperature, self.cb_temperature, self.increase_error_count) self.current_temperature = None # float, °C self.error_label = QLabel('Current Errors: None') self.error_label.setAlignment(Qt.AlignVCenter | Qt.AlignRight) plots = [('Temperature', Qt.red, lambda: self.current_temperature, u'{:.2f} °C'.format)] self.plot_widget = PlotWidget(u'Temperature [°C]', plots, extra_key_widgets=[self.error_label]) self.averaging_label = QLabel('Averaging:') self.averaging_combo = QComboBox() self.averaging_combo.addItem('1', BrickletThermocouple.AVERAGING_1) self.averaging_combo.addItem('2', BrickletThermocouple.AVERAGING_2) self.averaging_combo.addItem('4', BrickletThermocouple.AVERAGING_4) self.averaging_combo.addItem('8', BrickletThermocouple.AVERAGING_8) self.averaging_combo.addItem('16', BrickletThermocouple.AVERAGING_16) self.type_label = QLabel('Thermocouple Type:') self.type_combo = QComboBox() self.type_combo.addItem('B', BrickletThermocouple.TYPE_B) self.type_combo.addItem('E', BrickletThermocouple.TYPE_E) self.type_combo.addItem('J', BrickletThermocouple.TYPE_J) self.type_combo.addItem('K', BrickletThermocouple.TYPE_K) self.type_combo.addItem('N', BrickletThermocouple.TYPE_N) self.type_combo.addItem('R', BrickletThermocouple.TYPE_R) self.type_combo.addItem('S', BrickletThermocouple.TYPE_S) self.type_combo.addItem('T', BrickletThermocouple.TYPE_T) self.type_combo.addItem('Gain 8', BrickletThermocouple.TYPE_G8) self.type_combo.addItem('Gain 32', BrickletThermocouple.TYPE_G32) self.filter_label = QLabel('Noise Rejection Filter:') self.filter_combo = QComboBox() self.filter_combo.addItem('50 Hz', BrickletThermocouple.FILTER_OPTION_50HZ) self.filter_combo.addItem('60 Hz', BrickletThermocouple.FILTER_OPTION_60HZ) hlayout = QHBoxLayout() hlayout.addWidget(self.averaging_label) hlayout.addWidget(self.averaging_combo) hlayout.addStretch() hlayout.addWidget(self.type_label) hlayout.addWidget(self.type_combo) hlayout.addStretch() hlayout.addWidget(self.filter_label) hlayout.addWidget(self.filter_combo) line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(hlayout) self.averaging_combo.currentIndexChanged.connect( self.configuration_changed) self.type_combo.currentIndexChanged.connect(self.configuration_changed) self.filter_combo.currentIndexChanged.connect( self.configuration_changed) def start(self): async_call(self.thermo.get_temperature, None, self.cb_temperature, self.increase_error_count) async_call(self.thermo.get_configuration, None, self.cb_configuration, self.increase_error_count) async_call(self.thermo.get_error_state, None, lambda e: self.cb_error_state(e.over_under, e.open_circuit)) self.cbe_temperature.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_temperature.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletThermocouple.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def configuration_changed(self, _): conf_averaging = self.averaging_combo.itemData( self.averaging_combo.currentIndex()) conf_type = self.type_combo.itemData(self.type_combo.currentIndex()) conf_filter = self.filter_combo.itemData( self.filter_combo.currentIndex()) self.thermo.set_configuration(conf_averaging, conf_type, conf_filter) def cb_temperature(self, temperature): self.current_temperature = temperature / 100.0 def cb_configuration(self, conf): self.averaging_combo.blockSignals(True) self.averaging_combo.setCurrentIndex( self.averaging_combo.findData(conf.averaging)) self.averaging_combo.blockSignals(False) self.type_combo.blockSignals(True) self.type_combo.setCurrentIndex( self.type_combo.findData(conf.thermocouple_type)) self.type_combo.blockSignals(False) self.filter_combo.blockSignals(True) self.filter_combo.setCurrentIndex( self.filter_combo.findData(conf.filter)) self.filter_combo.blockSignals(False) def cb_error_state(self, over_under, open_circuit): if over_under or open_circuit: text = 'Current Errors: ' if over_under: text += 'Over/Under Voltage' if over_under and open_circuit: text += ' and ' if open_circuit: text += 'Open Circuit\n(defective thermocouple or nothing connected)' self.error_label.setStyleSheet('QLabel { color : red }') self.error_label.setText(text) else: self.error_label.setStyleSheet('') self.error_label.setText('Current Errors: None')
def __init__(self, *args): super().__init__(BrickletBarometer, *args) self.barometer = self.device # the firmware version of a EEPROM Bricklet can (under common circumstances) # not change during the lifetime of an EEPROM Bricklet plugin. therefore, # it's okay to make final decisions based on it here self.has_averaging = self.firmware_version >= (2, 0, 2) self.moving_average_pressure = 25 self.average_pressure = 10 self.average_temperature = 10 self.cbe_air_pressure = CallbackEmulator( self.barometer.get_air_pressure, None, self.cb_air_pressure, self.increase_error_count) self.cbe_altitude = CallbackEmulator(self.barometer.get_altitude, None, self.cb_altitude, self.increase_error_count) self.cbe_chip_temperature = CallbackEmulator( self.barometer.get_chip_temperature, None, self.cb_chip_temperature, self.increase_error_count) self.chip_temperature_label = ChipTemperatureLabel() self.current_air_pressure = CurveValueWrapper() # float, hPa self.current_altitude = CurveValueWrapper() # float, m self.clear_graphs_button = QPushButton('Clear Graphs') plots = [('Air Pressure', Qt.red, self.current_air_pressure, '{:.3f} hPa (QFE)'.format)] self.air_pressure_plot_widget = PlotWidget('Air Pressure [hPa]', plots, self.clear_graphs_button, y_resolution=0.001) plots = [('Altitude', Qt.darkGreen, self.current_altitude, lambda value: '{:.2f} m ({:.2f} ft)'.format( value, value / METER_TO_FEET_DIVISOR))] self.altitude_plot_widget = PlotWidget('Altitude [m]', plots, self.clear_graphs_button, y_resolution=0.01) self.reference_label = QLabel('Reference Air Pressure [hPa]:') self.reference_box = QDoubleSpinBox() self.reference_box.setMinimum(10) self.reference_box.setMaximum(1200) self.reference_box.setDecimals(3) self.reference_box.setValue(1013.25) self.reference_box.editingFinished.connect(self.reference_box_finished) self.use_current_button = QPushButton('Use Current') self.use_current_button.clicked.connect(self.use_current_clicked) if self.has_averaging: self.avg_pressure_box = QSpinBox() self.avg_pressure_box.setMinimum(0) self.avg_pressure_box.setMaximum(10) self.avg_pressure_box.setSingleStep(1) self.avg_pressure_box.setValue(10) self.avg_pressure_box.editingFinished.connect( self.avg_pressure_box_finished) self.avg_temperature_box = QSpinBox() self.avg_temperature_box.setMinimum(0) self.avg_temperature_box.setMaximum(255) self.avg_temperature_box.setSingleStep(1) self.avg_temperature_box.setValue(10) self.avg_temperature_box.editingFinished.connect( self.avg_temperature_box_finished) self.avg_moving_pressure_box = QSpinBox() self.avg_moving_pressure_box.setMinimum(0) self.avg_moving_pressure_box.setMaximum(25) self.avg_moving_pressure_box.setSingleStep(1) self.avg_moving_pressure_box.setValue(25) self.avg_moving_pressure_box.editingFinished.connect( self.avg_moving_pressure_box_finished) layout_h1 = QHBoxLayout() layout_h1.addWidget(self.air_pressure_plot_widget) layout_h1.addWidget(self.altitude_plot_widget) layout = QVBoxLayout(self) layout.addLayout(layout_h1) line = QFrame() line.setObjectName("line") line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) layout.addWidget(line) layout_h2 = QHBoxLayout() layout_h2.addWidget(self.reference_label) layout_h2.addWidget(self.reference_box) layout_h2.addWidget(self.use_current_button) layout_h2.addStretch() layout_h2.addWidget(self.chip_temperature_label) layout_h2.addStretch() layout_h2.addWidget(self.clear_graphs_button) layout.addLayout(layout_h2) if self.has_averaging: layout_h3 = QHBoxLayout() layout_h3.addWidget(QLabel('Air Pressure Moving Average Length:')) layout_h3.addWidget(self.avg_moving_pressure_box) layout_h3.addStretch() layout_h3.addWidget(QLabel('Air Pressure Average Length:')) layout_h3.addWidget(self.avg_pressure_box) layout_h3.addStretch() layout_h3.addWidget(QLabel('Temperate Average Length:')) layout_h3.addWidget(self.avg_temperature_box) layout.addLayout(layout_h3)
class VoltageCurrentV2(COMCUPluginBase, Ui_VoltageCurrentV2): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletVoltageCurrentV2, *args) self.setupUi(self) self.vc = self.device self.cbe_voltage = CallbackEmulator(self.vc.get_voltage, None, self.cb_voltage, self.increase_error_count) self.cbe_current = CallbackEmulator(self.vc.get_current, None, self.cb_current, self.increase_error_count) self.cbe_power = CallbackEmulator(self.vc.get_power, None, self.cb_power, self.increase_error_count) self.current_voltage = CurveValueWrapper() # float, V self.current_current = CurveValueWrapper() # float, A self.current_power = CurveValueWrapper() # float, W plots_voltage = [('Voltage', Qt.red, self.current_voltage, format_voltage)] plots_current = [('Current', Qt.blue, self.current_current, format_current)] plots_power = [('Power', Qt.darkGreen, self.current_power, format_power)] self.plot_widget_voltage = PlotWidget( 'Voltage [V]', plots_voltage, clear_button=self.button_clear_graphs, y_resolution=0.001) self.plot_widget_current = PlotWidget( 'Current [A]', plots_current, clear_button=self.button_clear_graphs, y_resolution=0.001) self.plot_widget_power = PlotWidget( 'Power [W]', plots_power, clear_button=self.button_clear_graphs, y_resolution=0.001) self.save_conf_button.clicked.connect(self.save_conf_clicked) self.calibration = None self.button_calibration.clicked.connect(self.calibration_clicked) hlayout = QHBoxLayout() hlayout.addWidget(self.plot_widget_voltage) hlayout.addWidget(self.plot_widget_current) hlayout.addWidget(self.plot_widget_power) self.main_layout.insertLayout(0, hlayout) def get_configuration_async(self, conf): avg, vol, cur = conf self.averaging_box.setCurrentIndex(avg) self.voltage_box.setCurrentIndex(vol) self.current_box.setCurrentIndex(cur) def start(self): async_call(self.vc.get_configuration, None, self.get_configuration_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 def stop(self): self.cbe_current.set_period(0) self.cbe_voltage.set_period(0) self.cbe_power.set_period(0) self.plot_widget_current.stop = True self.plot_widget_voltage.stop = True self.plot_widget_power.stop = True def destroy(self): if self.calibration != None: self.calibration.close() @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletVoltageCurrentV2.DEVICE_IDENTIFIER def get_url_part(self): return 'voltage_current_v2' def cb_current(self, current): self.current_current.value = current / 1000.0 def cb_voltage(self, voltage): self.current_voltage.value = voltage / 1000.0 def cb_power(self, power): self.current_power.value = power / 1000.0 def save_cal_clicked(self): gainmul = self.gainmul_spinbox.value() gaindiv = self.gaindiv_spinbox.value() self.vc.set_calibration(gainmul, gaindiv) def save_conf_clicked(self): avg = self.averaging_box.currentIndex() vol = self.voltage_box.currentIndex() cur = self.current_box.currentIndex() self.vc.set_configuration(avg, vol, cur) def calibration_clicked(self): if self.calibration == None: self.calibration = Calibration(self) self.button_calibration.setEnabled(False) self.calibration.show()
class DC(PluginBase, Ui_DC): qtcb_velocity_reached = pyqtSignal(int) qtcb_under_voltage = pyqtSignal(int) qtcb_emergency_shutdown = pyqtSignal() def __init__(self, *args): PluginBase.__init__(self, BrickDC, *args) self.setupUi(self) self.dc = self.device # the firmware version of a Brick can (under common circumstances) not # change during the lifetime of a Brick plugin. therefore, it's okay to # make final decisions based on it here self.has_status_led = self.firmware_version >= (2, 3, 1) self.encoder_hide_all() self.update_timer = QTimer(self) self.update_timer.timeout.connect(self.update_data) self.new_value = 0 self.update_counter = 0 self.full_brake_time = 0 self.velocity_syncer = SliderSpinSyncer(self.velocity_slider, self.velocity_spin, self.velocity_changed) self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider, self.acceleration_spin, self.acceleration_changed) self.frequency_syncer = SliderSpinSyncer(self.frequency_slider, self.frequency_spin, self.frequency_changed) self.radio_mode_brake.toggled.connect(self.brake_value_changed) self.radio_mode_coast.toggled.connect(self.coast_value_changed) self.minimum_voltage_button.clicked.connect(self.minimum_voltage_button_clicked) self.full_brake_button.clicked.connect(self.full_brake_clicked) self.enable_checkbox.stateChanged.connect(self.enable_state_changed) self.emergency_signal = None self.under_signal = None self.current_velocity_signal = None self.velocity_reached_signal = None self.qem = QErrorMessage(self) self.qtcb_under_voltage.connect(self.cb_under_voltage) self.dc.register_callback(self.dc.CALLBACK_UNDER_VOLTAGE, self.qtcb_under_voltage.emit) self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown) self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN, self.qtcb_emergency_shutdown.emit) self.qtcb_velocity_reached.connect(self.update_velocity) self.dc.register_callback(self.dc.CALLBACK_VELOCITY_REACHED, self.qtcb_velocity_reached.emit) self.cbe_current_velocity = CallbackEmulator(self.dc.get_current_velocity, None, self.update_velocity, self.increase_error_count) if self.has_status_led: self.status_led_action = QAction('Status LED', self) self.status_led_action.setCheckable(True) self.status_led_action.toggled.connect(lambda checked: self.dc.enable_status_led() if checked else self.dc.disable_status_led()) self.set_configs([(0, None, [self.status_led_action])]) else: self.status_led_action = None reset = QAction('Reset', self) reset.triggered.connect(lambda: self.dc.reset()) self.set_actions([(0, None, [reset])]) def start(self): if self.has_status_led: async_call(self.dc.is_status_led_enabled, None, self.status_led_action.setChecked, self.increase_error_count) self.update_timer.start(1000) self.cbe_current_velocity.set_period(100) self.update_start() self.update_data() def stop(self): self.update_timer.stop() self.cbe_current_velocity.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickDC.DEVICE_IDENTIFIER def cb_emergency_shutdown(self): if not self.qem.isVisible(): self.qem.setWindowTitle("Emergency Shutdown") self.qem.showMessage("Emergency Shutdown: Short-Circuit or Over-Temperature") def cb_under_voltage(self, ov): mv_str = self.minimum_voltage_label.text() ov_str = "%gV" % round(ov/1000.0, 1) if not self.qem.isVisible(): self.qem.setWindowTitle("Under Voltage") self.qem.showMessage("Under Voltage: Output Voltage of " + ov_str + " is below minimum voltage of " + mv_str, "DC_UnderVoltage") def encoder_hide_all(self): self.enable_encoder_checkbox.hide() self.encoder_hide() def encoder_hide(self): self.p_label.hide() self.p_spinbox.hide() self.i_label.hide() self.i_spinbox.hide() self.d_label.hide() self.d_spinbox.hide() self.st_label.hide() self.st_spinbox.hide() self.cpr_label.hide() self.cpr_spinbox.hide() self.encoder_spacer.hide() def encoder_show(self): self.p_label.show() self.p_spinbox.show() self.i_label.show() self.i_spinbox.show() self.d_label.show() self.d_spinbox.show() self.st_label.show() self.st_spinbox.show() self.cpr_label.show() self.cpr_spinbox.show() self.encoder_spacer.show() def enable_encoder_state_changed(self, state): try: if state == Qt.Checked: self.dc.enable_encoder() self.update_encoder() elif state == Qt.Unchecked: self.dc.disable_encoder() except ip_connection.Error: return def enable_state_changed(self, state): try: if state == Qt.Checked: self.dc.enable() elif state == Qt.Unchecked: self.dc.disable() except ip_connection.Error: return def brake_value_changed(self, checked): if checked: try: self.dc.set_drive_mode(0) except ip_connection.Error: return def coast_value_changed(self, checked): if checked: try: self.dc.set_drive_mode(1) except ip_connection.Error: return def full_brake_clicked(self): try: self.dc.full_brake() except ip_connection.Error: return def minimum_voltage_selected(self, value): try: self.dc.set_minimum_voltage(value) except ip_connection.Error: return def minimum_voltage_button_clicked(self): qid = QInputDialog(self) qid.setInputMode(QInputDialog.IntInput) qid.setIntMinimum(5000) qid.setIntMaximum(0xFFFF) qid.setIntStep(100) async_call(self.dc.get_minimum_voltage, None, qid.setIntValue, self.increase_error_count) qid.intValueSelected.connect(self.minimum_voltage_selected) qid.setLabelText("Choose minimum motor voltage in mV.") qid.open() def stack_input_voltage_update(self, sv): sv_str = "%gV" % round(sv/1000.0, 1) self.stack_voltage_label.setText(sv_str) def external_input_voltage_update(self, ev): ev_str = "%gV" % round(ev/1000.0, 1) self.external_voltage_label.setText(ev_str) def minimum_voltage_update(self, mv): mv_str = "%gV" % round(mv/1000.0, 1) self.minimum_voltage_label.setText(mv_str) def drive_mode_update(self, dm): if dm == 0: self.radio_mode_brake.setChecked(True) self.radio_mode_coast.setChecked(False) else: self.radio_mode_brake.setChecked(False) self.radio_mode_coast.setChecked(True) def current_consumption_update(self, cc): if cc >= 1000: cc_str = "%gA" % round(cc / 1000.0, 1) else: cc_str = "%gmA" % cc self.current_label.setText(cc_str) def update_velocity(self, velocity): self.speedometer.set_velocity(velocity) self.current_velocity_label.setText('{0} ({1}%)'.format(velocity, round(abs(velocity) * 100 / 32768.0, 1))) def get_velocity_async(self, velocity): if not self.velocity_slider.isSliderDown(): if velocity != self.velocity_slider.sliderPosition(): self.velocity_slider.setSliderPosition(velocity) self.velocity_spin.setValue(velocity) self.update_velocity(velocity) def get_acceleration_async(self, acceleration): if not self.acceleration_slider.isSliderDown(): if acceleration != self.acceleration_slider.sliderPosition(): self.acceleration_slider.setSliderPosition(acceleration) self.acceleration_spin.setValue(acceleration) def get_pwm_frequency_async(self, frequency): if not self.frequency_slider.isSliderDown(): if frequency != self.frequency_slider.sliderPosition(): self.frequency_slider.setSliderPosition(frequency) self.frequency_spin.setValue(frequency) def is_enabled_async(self, enabled): self.enable_checkbox.setChecked(enabled) def is_encoder_enabled_async(self, enabled): self.enable_encoder_checkbox.setChecked(enabled) def get_encoder_config_async(self, cpr): self.cpr_spinbox.setValue(cpr) def get_encoder_pid_config_async(self, pid_config): self.p_spinbox.setValue(pid_config.p) self.i_spinbox.setValue(pid_config.i) self.d_spinbox.setValue(pid_config.d) self.st_spinbox.setValue(pid_config.sample_time) def update_encoder(self): async_call(self.dc.get_encoder_config, None, self.get_encoder_config_async, self.increase_error_count) async_call(self.dc.get_encoder_pid_config, None, self.get_encoder_pid_config_async, self.increase_error_count) async_call(self.dc.is_encoder_enabled, None, self.is_encoder_enabled_async, self.increase_error_count) 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) def update_data(self): async_call(self.dc.get_stack_input_voltage, None, self.stack_input_voltage_update, self.increase_error_count) async_call(self.dc.get_external_input_voltage, None, self.external_input_voltage_update, self.increase_error_count) async_call(self.dc.get_minimum_voltage, None, self.minimum_voltage_update, self.increase_error_count) async_call(self.dc.get_current_consumption, None, self.current_consumption_update, self.increase_error_count) def acceleration_changed(self, value): try: self.dc.set_acceleration(value) except ip_connection.Error: return def velocity_changed(self, value): try: self.dc.set_velocity(value) except ip_connection.Error: return def frequency_changed(self, value): try: self.dc.set_pwm_frequency(value) except ip_connection.Error: return
def __init__(self, *args): PluginBase.__init__(self, BrickDC, *args) self.setupUi(self) self.dc = self.device # the firmware version of a Brick can (under common circumstances) not # change during the lifetime of a Brick plugin. therefore, it's okay to # make final decisions based on it here self.has_status_led = self.firmware_version >= (2, 3, 1) self.encoder_hide_all() self.update_timer = QTimer(self) self.update_timer.timeout.connect(self.update_data) self.new_value = 0 self.update_counter = 0 self.full_brake_time = 0 self.velocity_syncer = SliderSpinSyncer(self.velocity_slider, self.velocity_spin, self.velocity_changed) self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider, self.acceleration_spin, self.acceleration_changed) self.frequency_syncer = SliderSpinSyncer(self.frequency_slider, self.frequency_spin, self.frequency_changed) self.radio_mode_brake.toggled.connect(self.brake_value_changed) self.radio_mode_coast.toggled.connect(self.coast_value_changed) self.minimum_voltage_button.clicked.connect(self.minimum_voltage_button_clicked) self.full_brake_button.clicked.connect(self.full_brake_clicked) self.enable_checkbox.stateChanged.connect(self.enable_state_changed) self.emergency_signal = None self.under_signal = None self.current_velocity_signal = None self.velocity_reached_signal = None self.qem = QErrorMessage(self) self.qtcb_under_voltage.connect(self.cb_under_voltage) self.dc.register_callback(self.dc.CALLBACK_UNDER_VOLTAGE, self.qtcb_under_voltage.emit) self.qtcb_emergency_shutdown.connect(self.cb_emergency_shutdown) self.dc.register_callback(self.dc.CALLBACK_EMERGENCY_SHUTDOWN, self.qtcb_emergency_shutdown.emit) self.qtcb_velocity_reached.connect(self.update_velocity) self.dc.register_callback(self.dc.CALLBACK_VELOCITY_REACHED, self.qtcb_velocity_reached.emit) self.cbe_current_velocity = CallbackEmulator(self.dc.get_current_velocity, None, self.update_velocity, self.increase_error_count) if self.has_status_led: self.status_led_action = QAction('Status LED', self) self.status_led_action.setCheckable(True) self.status_led_action.toggled.connect(lambda checked: self.dc.enable_status_led() if checked else self.dc.disable_status_led()) self.set_configs([(0, None, [self.status_led_action])]) else: self.status_led_action = None reset = QAction('Reset', self) reset.triggered.connect(lambda: self.dc.reset()) self.set_actions([(0, None, [reset])])
class JoystickV2(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletJoystickV2, *args) self.js = self.device self.cbe_position = CallbackEmulator( self, self.js.get_position, None, self.cb_position, self.increase_error_count, expand_result_tuple_for_callback=True) self.cbe_pressed = CallbackEmulator(self, self.js.is_pressed, None, self.cb_pressed, self.increase_error_count) self.joystick_frame = JoystickFrame(self) self.joystick_frame.setMinimumSize(220, 220) self.joystick_frame.setMaximumSize(220, 220) self.joystick_frame.set_position(0, 0) self.calibrate_button = QPushButton('Calibrate Zero') self.calibrate_button.clicked.connect(self.calibrate_clicked) self.current_x = CurveValueWrapper() self.current_y = CurveValueWrapper() plots = [('X', Qt.darkGreen, self.current_x, str), ('Y', Qt.blue, self.current_y, str)] self.plot_widget = PlotWidget('Position', plots, update_interval=0.025, y_resolution=1.0) vlayout = QVBoxLayout() vlayout.addStretch() vlayout.addWidget(self.joystick_frame) vlayout.addWidget(self.calibrate_button) vlayout.addStretch() layout = QHBoxLayout(self) layout.addWidget(self.plot_widget) layout.addLayout(vlayout) def start(self): self.cbe_position.set_period(50) self.cbe_pressed.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_position.set_period(0) self.cbe_pressed.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletJoystickV2.DEVICE_IDENTIFIER def calibrate_clicked(self): try: self.js.calibrate() except ip_connection.Error: return def cb_position(self, x, y): self.current_x.value = x self.current_y.value = y self.joystick_frame.set_position(x, y) def cb_pressed(self, pressed): self.joystick_frame.set_pressed(pressed)
class ServoV2(COMCUPluginBase, Ui_ServoV2): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletServoV2, *args) self.setupUi(self) self.servo = self.device self.cbe_status = CallbackEmulator(self, self.servo.get_status, None, self.cb_status, self.increase_error_count) self.position_list = [] self.velocity_list = [] self.current_list = [] self.enable_list = [] self.up_cur = 0 self.up_siv = 0 self.up_eiv = 0 self.up_opv = 0 self.up_mv = 0 self.up_ena = [0]*10 self.up_pos = [0]*10 self.up_vel = [0]*10 self.up_acc = [0]*10 self.alive = True for i in range(1, 11): label = QLabel() label.setText('Off') self.enable_list.append(label) self.status_grid.addWidget(label, i, 1) for i in range(1, 11): pk = PositionKnob() self.position_list.append(pk) self.status_grid.addWidget(pk, i, 2) for i in range(1, 11): cb = ColorBar(Qt.Vertical) self.velocity_list.append(cb) self.status_grid.addWidget(cb, i, 3) for i in range(1, 11): cb = ColorBar(Qt.Vertical) self.current_list.append(cb) self.status_grid.addWidget(cb, i, 4) self.servo_dropbox.currentIndexChanged.connect(lambda x: self.update_servo_specific()) self.enable_checkbox.stateChanged.connect(self.enable_state_changed) self.position_syncer = SliderSpinSyncer(self.position_slider, self.position_spin, self.position_changed) self.velocity_syncer = SliderSpinSyncer(self.velocity_slider, self.velocity_spin, self.motion_changed) self.acceleration_syncer = SliderSpinSyncer(self.acceleration_slider, self.acceleration_spin, self.motion_changed) self.deceleration_syncer = SliderSpinSyncer(self.deceleration_slider, self.deceleration_spin, self.motion_changed) self.period_syncer = SliderSpinSyncer(self.period_slider, self.period_spin, self.period_changed) self.pulse_width_min_spin.editingFinished.connect(self.pulse_width_spin_finished) self.pulse_width_max_spin.editingFinished.connect(self.pulse_width_spin_finished) self.degree_min_spin.editingFinished.connect(self.degree_spin_finished) self.degree_max_spin.editingFinished.connect(self.degree_spin_finished) def start(self): self.cbe_status.set_period(100) self.update_servo_specific() def stop(self): self.cbe_status.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletServoV2.DEVICE_IDENTIFIER def get_period_async(self, period): self.period_spin.blockSignals(True) self.period_spin.setValue(period) self.period_spin.blockSignals(False) self.period_slider.blockSignals(True) self.period_slider.setValue(period) self.period_slider.blockSignals(False) def get_enabled_async(self, enabled): self.enable_checkbox.blockSignals(True) self.enable_checkbox.setChecked(enabled) self.enable_checkbox.blockSignals(False) def get_position_async(self, position): self.position_spin.blockSignals(True) self.position_spin.setValue(position) self.position_spin.blockSignals(False) self.position_slider.blockSignals(True) self.position_slider.setValue(position) self.position_slider.blockSignals(False) def get_motion_configuration_async(self, motion): self.velocity_spin.blockSignals(True) self.velocity_spin.setValue(motion.velocity) self.velocity_spin.blockSignals(False) self.velocity_slider.blockSignals(True) self.velocity_slider.setValue(motion.velocity) self.velocity_slider.blockSignals(False) self.acceleration_spin.blockSignals(True) self.acceleration_spin.setValue(motion.acceleration) self.acceleration_spin.blockSignals(False) self.acceleration_slider.blockSignals(True) self.acceleration_slider.setValue(motion.acceleration) self.acceleration_slider.blockSignals(False) self.deceleration_spin.blockSignals(True) self.deceleration_spin.setValue(motion.deceleration) self.deceleration_spin.blockSignals(False) self.deceleration_slider.blockSignals(True) self.deceleration_slider.setValue(motion.deceleration) self.deceleration_slider.blockSignals(False) def get_degree_async(self, servo, degree_min, degree_max): self.degree_min_spin.blockSignals(True) self.degree_min_spin.setValue(degree_min) self.degree_min_spin.blockSignals(False) self.degree_max_spin.blockSignals(True) self.degree_max_spin.setValue(degree_max) self.degree_max_spin.blockSignals(False) self.position_slider.setMinimum(degree_min) self.position_slider.setMaximum(degree_max) self.position_spin.setMinimum(degree_min) self.position_spin.setMaximum(degree_max) self.position_list[servo].set_total_angle((degree_max - degree_min) / 100) self.position_list[servo].set_range(degree_min / 100, degree_max / 100) def get_pulse_width_async(self, pulse_width_min, pulse_width_max): self.pulse_width_min_spin.blockSignals(True) self.pulse_width_min_spin.setValue(pulse_width_min) self.pulse_width_min_spin.blockSignals(False) self.pulse_width_max_spin.blockSignals(True) self.pulse_width_max_spin.setValue(pulse_width_max) self.pulse_width_max_spin.blockSignals(False) def update_servo_specific(self): servo = self.selected_servo() if servo == 0xFFFF: self.enable_checkbox.setChecked(False) return async_call(self.servo.get_enabled, servo, self.get_enabled_async, self.increase_error_count) async_call(self.servo.get_position, servo, self.get_position_async, self.increase_error_count) async_call(self.servo.get_motion_configuration, servo, self.get_motion_configuration_async, self.increase_error_count) async_call(self.servo.get_period, servo, self.get_period_async, self.increase_error_count) async_call(self.servo.get_degree, servo, self.get_degree_async, self.increase_error_count, pass_arguments_to_result_callback=True, expand_result_tuple_for_callback=True) async_call(self.servo.get_pulse_width, servo, self.get_pulse_width_async, self.increase_error_count, expand_result_tuple_for_callback=True) def servo_current_update(self, value): self.current_label.setText(str(value) + "mA") def input_voltage_update(self, sv): sv_str = "%gV" % round(sv / 1000.0, 1) self.input_voltage_label.setText(sv_str) def position_update(self, servo, position): self.position_list[servo].set_value(position / 100) def velocity_update(self, servo, velocity): self.velocity_list[servo].set_height(velocity * 100 // 0xFFFF) def current_update(self, servo, current): self.current_list[servo].set_height(min(100, current * 100 // 200)) def enable_update(self, servo, enabled): if enabled: if self.enable_list[servo].text().replace('&', '') != 'On': self.enable_list[servo].setText('On') self.velocity_list[servo].color() self.current_list[servo].color() else: if self.enable_list[servo].text().replace('&', '') != 'Off': self.enable_list[servo].setText('Off') self.velocity_list[servo].grey() self.current_list[servo].grey() def selected_servo(self): try: return int(self.servo_dropbox.currentText()[-1:]) except: return 0xFFFF def enable_state_changed(self, state): try: self.servo.set_enable(self.selected_servo(), state == Qt.Checked) except ip_connection.Error: return def position_changed(self, value): try: self.servo.set_position(self.selected_servo(), value) except ip_connection.Error: return def motion_changed(self, _): try: self.servo.set_motion_configuration(self.selected_servo(), self.velocity_spin.value(), self.acceleration_spin.value(), self.deceleration_spin.value()) except ip_connection.Error: return def period_changed(self, value): try: self.servo.set_period(self.selected_servo(), value) except ip_connection.Error: return def pulse_width_spin_finished(self): try: self.servo.set_pulse_width(self.selected_servo(), self.pulse_width_min_spin.value(), self.pulse_width_max_spin.value()) except ip_connection.Error: return def degree_spin_finished(self): degree_min = self.degree_min_spin.value() degree_max = self.degree_max_spin.value() servo = self.selected_servo() self.position_slider.setMinimum(degree_min) self.position_slider.setMaximum(degree_max) self.position_spin.setMinimum(degree_min) self.position_spin.setMaximum(degree_max) if servo == 0xFFFF: for i in range(7): self.position_list[i].set_total_angle((degree_max - degree_min) / 100) self.position_list[i].set_range(degree_min / 100, degree_max / 100) else: self.position_list[servo].set_total_angle((degree_max - degree_min) / 100) self.position_list[servo].set_range(degree_min / 100, degree_max / 100) try: self.servo.set_degree(servo, degree_min, degree_max) except ip_connection.Error: return def cb_status(self, status): servo = self.selected_servo() self.input_voltage_update(status.input_voltage) if servo == 0xFFFF: self.servo_current_update(sum(status.current)) else: self.servo_current_update(status.current[servo]) for servo in range(10): self.enable_update(servo, status.enabled[servo]) self.position_update(servo, status.current_position[servo]) self.velocity_update(servo, status.current_velocity[servo]) self.current_update(servo, status.current[servo])
class IndustrialDualAnalogInV2(COMCUPluginBase): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletIndustrialDualAnalogInV2, *args) self.analog_in = self.device self.cbe_voltage0 = CallbackEmulator(functools.partial(self.analog_in.get_voltage, 0), functools.partial(self.cb_voltage, 0), self.increase_error_count) self.cbe_voltage1 = CallbackEmulator(functools.partial(self.analog_in.get_voltage, 1), functools.partial(self.cb_voltage, 1), self.increase_error_count) self.calibration = None self.sample_rate_label = QLabel('Sample Rate:') self.sample_rate_combo = QComboBox() self.sample_rate_combo.addItem('976 Hz') self.sample_rate_combo.addItem('488 Hz') self.sample_rate_combo.addItem('244 Hz') self.sample_rate_combo.addItem('122 Hz') self.sample_rate_combo.addItem('61 Hz') self.sample_rate_combo.addItem('4 Hz') self.sample_rate_combo.addItem('2 Hz') self.sample_rate_combo.addItem('1 Hz') self.current_voltage = [None, None] # float, V self.calibration_button = QPushButton('Calibration...') self.sample_rate_combo.currentIndexChanged.connect(self.sample_rate_combo_index_changed) self.calibration_button.clicked.connect(self.calibration_button_clicked) plots = [('Channel 0', Qt.red, lambda: self.current_voltage[0], format_voltage), ('Channel 1', Qt.blue, lambda: self.current_voltage[1], format_voltage)] self.plot_widget = PlotWidget('Voltage [V]', plots) # Define lines line = QFrame() line.setFrameShape(QFrame.HLine) line.setFrameShadow(QFrame.Sunken) line1 = QFrame() line1.setFrameShape(QFrame.HLine) line1.setFrameShadow(QFrame.Sunken) line2 = QFrame() line2.setFrameShape(QFrame.HLine) line2.setFrameShadow(QFrame.Sunken) # Define channel LED status config widgets self.led_config_ch0_label = QLabel('Channel 0') self.led_config_ch1_label = QLabel('Channel 1') self.led_config_label = QLabel('LED Config:') self.led_status_config_label = QLabel('LED Status Config:') self.led_status_config_ch0_min_label = QLabel('Min:') self.led_status_config_ch0_max_label = QLabel('Max:') self.led_status_config_ch1_min_label = QLabel('Min:') self.led_status_config_ch1_max_label = QLabel('Max:') self.led_config_ch0_combo = QComboBox() self.led_config_ch0_combo.addItem('Off') self.led_config_ch0_combo.addItem('On') self.led_config_ch0_combo.addItem('Show Heartbeat') self.led_config_ch0_combo.addItem('Show Channel Status') self.led_config_ch0_combo.currentIndexChanged.connect(self.led_config_ch0_combo_changed) self.led_config_ch1_combo = QComboBox() self.led_config_ch1_combo.addItem('Off') self.led_config_ch1_combo.addItem('On') self.led_config_ch1_combo.addItem('Show Heartbeat') self.led_config_ch1_combo.addItem('Show Channel Status') self.led_config_ch1_combo.currentIndexChanged.connect(self.led_config_ch1_combo_changed) self.led_status_config_ch0_combo = QComboBox() self.led_status_config_ch0_combo.addItem('Threshold') self.led_status_config_ch0_combo.addItem('Intensity') self.led_status_config_ch0_combo.currentIndexChanged.connect(self.led_status_config_ch0_combo_changed) self.led_status_config_ch1_combo = QComboBox() self.led_status_config_ch1_combo.addItem('Threshold') self.led_status_config_ch1_combo.addItem('Intensity') self.led_status_config_ch1_combo.currentIndexChanged.connect(self.led_status_config_ch1_combo_changed) self.led_status_config_ch0_min_sbox = QSpinBox() self.led_status_config_ch0_min_sbox.setMinimum(-35000) self.led_status_config_ch0_min_sbox.setMaximum(35000) self.led_status_config_ch0_min_sbox.setValue(0) self.led_status_config_ch0_min_sbox.setSingleStep(1) self.led_status_config_ch0_min_sbox.setSuffix(' mV') self.led_status_config_ch0_min_sbox.valueChanged.connect(self.led_status_config_ch0_min_sbox_changed) self.led_status_config_ch0_max_sbox = QSpinBox() self.led_status_config_ch0_max_sbox.setMinimum(-35000) self.led_status_config_ch0_max_sbox.setMaximum(35000) self.led_status_config_ch0_max_sbox.setValue(0) self.led_status_config_ch0_max_sbox.setSingleStep(1) self.led_status_config_ch0_max_sbox.setSuffix(' mV') self.led_status_config_ch0_max_sbox.valueChanged.connect(self.led_status_config_ch0_max_sbox_changed) self.led_status_config_ch1_min_sbox = QSpinBox() self.led_status_config_ch1_min_sbox.setMinimum(-35000) self.led_status_config_ch1_min_sbox.setMaximum(35000) self.led_status_config_ch1_min_sbox.setValue(0) self.led_status_config_ch1_min_sbox.setSingleStep(1) self.led_status_config_ch1_min_sbox.setSuffix(' mV') self.led_status_config_ch1_min_sbox.valueChanged.connect(self.led_status_config_ch1_min_sbox_changed) self.led_status_config_ch1_max_sbox = QSpinBox() self.led_status_config_ch1_max_sbox.setMinimum(-35000) self.led_status_config_ch1_max_sbox.setMaximum(35000) self.led_status_config_ch1_max_sbox.setValue(0) self.led_status_config_ch1_max_sbox.setSingleStep(1) self.led_status_config_ch1_max_sbox.setSuffix(' mV') self.led_status_config_ch1_max_sbox.valueChanged.connect(self.led_status_config_ch1_max_sbox_changed) # Define size policies h_sp = QSizePolicy() h_sp.setHorizontalPolicy(QSizePolicy.Expanding) # Set size policies self.sample_rate_combo.setSizePolicy(h_sp) self.led_config_ch0_combo.setSizePolicy(h_sp) self.led_config_ch1_combo.setSizePolicy(h_sp) self.led_status_config_ch0_combo.setSizePolicy(h_sp) self.led_status_config_ch1_combo.setSizePolicy(h_sp) self.led_status_config_ch0_min_sbox.setSizePolicy(h_sp) self.led_status_config_ch0_max_sbox.setSizePolicy(h_sp) self.led_status_config_ch1_min_sbox.setSizePolicy(h_sp) self.led_status_config_ch1_max_sbox.setSizePolicy(h_sp) # Define layouts hlayout = QHBoxLayout() vlayout = QVBoxLayout() glayout = QGridLayout() layout = QVBoxLayout(self) hlayout_ch0_min_max = QHBoxLayout() hlayout_ch1_min_max = QHBoxLayout() # Populate layouts vlayout.addWidget(self.calibration_button) hlayout.addWidget(self.sample_rate_label) hlayout.addWidget(self.sample_rate_combo) vlayout.addLayout(hlayout) vlayout.addWidget(line1) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_min_label) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_min_sbox) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_max_label) hlayout_ch0_min_max.addWidget(self.led_status_config_ch0_max_sbox) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_min_label) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_min_sbox) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_max_label) hlayout_ch1_min_max.addWidget(self.led_status_config_ch1_max_sbox) glayout.addWidget(self.led_config_ch0_label, 0, 1, 1, 1) # R, C, RS, CS glayout.addWidget(self.led_config_ch1_label, 0, 2, 1, 1) glayout.addWidget(line2, 1, 0, 1, 3) glayout.addWidget(self.led_config_label, 2, 0, 1, 1) glayout.addWidget(self.led_config_ch0_combo, 2, 1, 1, 1) glayout.addWidget(self.led_config_ch1_combo, 2, 2, 1, 1) glayout.addWidget(self.led_status_config_label, 3, 0, 1, 1) glayout.addWidget(self.led_status_config_ch0_combo, 3, 1, 1, 1) glayout.addWidget(self.led_status_config_ch1_combo, 3, 2, 1, 1) glayout.addLayout(hlayout_ch0_min_max, 4, 1, 1, 1) glayout.addLayout(hlayout_ch1_min_max, 4, 2, 1, 1) layout.addWidget(self.plot_widget) layout.addWidget(line) layout.addLayout(vlayout) layout.addLayout(glayout) self.ui_group_ch_status_ch0 = [self.led_status_config_ch0_combo, self.led_status_config_ch0_min_sbox, self.led_status_config_ch0_max_sbox] self.ui_group_ch_status_ch1 = [self.led_status_config_ch1_combo, self.led_status_config_ch1_min_sbox, self.led_status_config_ch1_max_sbox] def start(self): async_call(self.analog_in.get_voltage, 0, lambda x: self.cb_voltage(0, x), self.increase_error_count) async_call(self.analog_in.get_voltage, 1, lambda x: self.cb_voltage(1, x), self.increase_error_count) async_call(self.analog_in.get_sample_rate, None, self.get_sample_rate_async, self.increase_error_count) async_call(self.analog_in.get_channel_led_config, CH_0, lambda config: self.get_channel_led_config_async(CH_0, config), self.increase_error_count) async_call(self.analog_in.get_channel_led_status_config, CH_0, lambda config: self.get_channel_led_status_config_async(CH_0, config), self.increase_error_count) async_call(self.analog_in.get_channel_led_config, CH_1, lambda config: self.get_channel_led_config_async(CH_1, config), self.increase_error_count) async_call(self.analog_in.get_channel_led_status_config, CH_1, lambda config: self.get_channel_led_status_config_async(CH_1, config), self.increase_error_count) self.cbe_voltage0.set_period(100) self.cbe_voltage1.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_voltage0.set_period(0) self.cbe_voltage1.set_period(0) self.plot_widget.stop = True def destroy(self): if self.calibration != None: self.calibration.close() @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletIndustrialDualAnalogInV2.DEVICE_IDENTIFIER def calibration_button_clicked(self): if self.calibration == None: self.calibration = Calibration(self) self.calibration_button.setEnabled(False) self.calibration.show() def sample_rate_combo_index_changed(self, index): async_call(self.analog_in.set_sample_rate, index, None, self.increase_error_count) def led_config_ch0_combo_changed(self, index): if index != self.analog_in.CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS: for e in self.ui_group_ch_status_ch0: e.setEnabled(False) else: for e in self.ui_group_ch_status_ch0: e.setEnabled(True) self.analog_in.set_channel_led_config(CH_0, index) def led_config_ch1_combo_changed(self, index): if index != self.analog_in.CHANNEL_LED_CONFIG_SHOW_CHANNEL_STATUS: for e in self.ui_group_ch_status_ch1: e.setEnabled(False) else: for e in self.ui_group_ch_status_ch1: e.setEnabled(True) self.analog_in.set_channel_led_config(CH_1, index) def led_status_config_ch0_combo_changed(self, index): self.analog_in.set_channel_led_status_config(CH_0, self.led_status_config_ch0_min_sbox.value(), self.led_status_config_ch0_max_sbox.value(), index) def led_status_config_ch1_combo_changed(self, index): self.analog_in.set_channel_led_status_config(CH_1, self.led_status_config_ch1_min_sbox.value(), self.led_status_config_ch1_max_sbox.value(), index) def led_status_config_ch0_min_sbox_changed(self, value): QObject.sender(self).blockSignals(True) self.analog_in.set_channel_led_status_config(CH_0, self.led_status_config_ch0_min_sbox.value(), self.led_status_config_ch0_max_sbox.value(), self.led_status_config_ch0_combo.currentIndex()) QObject.sender(self).blockSignals(False) def led_status_config_ch0_max_sbox_changed(self, value): QObject.sender(self).blockSignals(True) self.analog_in.set_channel_led_status_config(CH_0, self.led_status_config_ch0_min_sbox.value(), self.led_status_config_ch0_max_sbox.value(), self.led_status_config_ch0_combo.currentIndex()) QObject.sender(self).blockSignals(False) def led_status_config_ch1_min_sbox_changed(self, value): QObject.sender(self).blockSignals(True) self.analog_in.set_channel_led_status_config(CH_1, self.led_status_config_ch1_min_sbox.value(), self.led_status_config_ch1_max_sbox.value(), self.led_status_config_ch1_combo.currentIndex()) QObject.sender(self).blockSignals(False) def led_status_config_ch1_max_sbox_changed(self, value): QObject.sender(self).blockSignals(True) self.analog_in.set_channel_led_status_config(CH_1, self.led_status_config_ch1_min_sbox.value(), self.led_status_config_ch1_max_sbox.value(), self.led_status_config_ch1_combo.currentIndex()) QObject.sender(self).blockSignals(False) def get_voltage_value0(self): return self.voltage_value[0] def get_voltage_value1(self): return self.voltage_value[1] def get_sample_rate_async(self, rate): self.sample_rate_combo.blockSignals(True) self.sample_rate_combo.setCurrentIndex(rate) self.sample_rate_combo.blockSignals(False) def get_channel_led_config_async(self, channel, config): self.led_config_ch0_combo.blockSignals(True) self.led_config_ch1_combo.blockSignals(True) if channel == CH_0: self.led_config_ch0_combo.setCurrentIndex(config) elif channel == CH_1: self.led_config_ch1_combo.setCurrentIndex(config) self.led_config_ch0_combo.blockSignals(False) self.led_config_ch1_combo.blockSignals(False) def get_channel_led_status_config_async(self, channel, config): self.led_status_config_ch0_combo.blockSignals(True) self.led_status_config_ch1_combo.blockSignals(True) if channel == CH_0: self.led_status_config_ch0_combo.setCurrentIndex(config.config) self.led_status_config_ch0_max_sbox.setValue(config.max) self.led_status_config_ch0_min_sbox.setValue(config.min) elif channel == CH_1: self.led_status_config_ch1_combo.setCurrentIndex(config.config) self.led_status_config_ch1_max_sbox.setValue(config.max) self.led_status_config_ch1_min_sbox.setValue(config.min) self.led_status_config_ch0_combo.blockSignals(False) self.led_status_config_ch1_combo.blockSignals(False) def cb_voltage(self, sensor, voltage): self.current_voltage[sensor] = voltage / 1000.0