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
class TNGDI8(TNGPluginBase, Ui_TNGDI8): def __init__(self, *args): TNGPluginBase.__init__(self, TNGDI8Bindings, *args) self.setupUi(self) self.di8 = self.device self.cbe_values = CallbackEmulator(self, self.di8.get_values, None, self.cb_values, self.increase_error_count) def cb_values(self, values): s = '' for x in values.values: if x: s += '1' else: s += '0' self.label.setText('{0}: {1}'.format(values.timestamp, s)) def start(self): self.cbe_values.set_period(50) def stop(self): self.cbe_values.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == TNGDI8Bindings.DEVICE_IDENTIFIER
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 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 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)
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 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 HeartRate(PluginBase): qtcb_beat_state_changed = pyqtSignal(int) def __init__(self, *args): PluginBase.__init__(self, BrickletHeartRate, *args) self.hr = self.device self.cbe_heart_rate = CallbackEmulator(self.hr.get_heart_rate, 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 = None plots = [('Heart Rate', Qt.red, lambda: self.current_heart_rate, '{} BPM'.format)] self.plot_widget = PlotWidget('Heart Rate [BPM]', plots, extra_key_widgets=[self.heart_icon]) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): async_call(self.hr.get_heart_rate, None, self.cb_heart_rate, self.increase_error_count) self.cbe_heart_rate.set_period(100) async_call(self.hr.enable_beat_state_changed_callback, None, None, self.increase_error_count) 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 = 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)
class AmbientLight(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletAmbientLight, *args) self.al = self.device self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance, self.cb_illuminance, self.increase_error_count) self.illuminance_label = IlluminanceLabel('Illuminance: ') self.alf = AmbientLightFrame() self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] self.plot_widget = PlotWidget('Illuminance [lx]', plot_list) layout_h = QHBoxLayout() layout_h.addStretch() layout_h.addWidget(self.illuminance_label) layout_h.addWidget(self.alf) layout_h.addStretch() layout = QVBoxLayout(self) layout.addLayout(layout_h) layout.addWidget(self.plot_widget) def start(self): async_call(self.al.get_illuminance, None, self.cb_illuminance, self.increase_error_count) self.cbe_illuminance.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_illuminance.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'ambient_light' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletAmbientLight.DEVICE_IDENTIFIER def get_current_value(self): return self.current_value def cb_illuminance(self, illuminance): self.current_value = illuminance/10.0 self.illuminance_label.setText(str(self.current_value)) value = illuminance*255/9000 self.alf.set_color(value, value, value)
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, self.cb_get_statistics, self.increase_error_count) self.last_connected = None def cb_get_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
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 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
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 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 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 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
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 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 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 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
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 @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)
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)
class XMC1400Breakout(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletXMC1400Breakout, *args) self.xmc1400 = self.device self.cbe_count = CallbackEmulator(self, self.xmc1400.get_count, None, self.cb_count, self.increase_error_count) self.label_count = QLabel() self.label_count.setText('Count: TBD') self.label_desc = QLabel() self.label_desc.setText( """This is the Brick Viewer plugin for the XMC1400 Breakout Bricklet. The Bricklet is intended for development of new Bricklets. You can modify this plugin for your own tests with the Bricklet. Below you can find the count that is returned by the get_count() example. If the Bricklet is working it should increase once per second. """) layout = QVBoxLayout() layout.addStretch() layout.addWidget(self.label_desc) layout.addWidget(self.label_count) layout.addStretch() layout_main = QHBoxLayout(self) layout_main.addStretch() layout_main.addLayout(layout) layout_main.addStretch() def start(self): self.cbe_count.set_period(100) def stop(self): self.cbe_count.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletXMC1400Breakout.DEVICE_IDENTIFIER def cb_count(self, count): self.label_count.setText('Count: {0}'.format(count))
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.slider.setMinimumWidth(200) self.current_position = None plots = [('Position', Qt.red, lambda: self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], curve_motion_granularity=40, update_interval=0.025) layout = QVBoxLayout(self) 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLinearPoti.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position = position self.slider.setValue(position)
class AmbientLight(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletAmbientLight, *args) self.al = self.device self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance, self.cb_illuminance, self.increase_error_count) self.alf = AmbientLightFrame() self.current_illuminance = None # float, lx plots = [('Illuminance', Qt.red, lambda: self.current_illuminance, '{} lx (Lux)'.format)] self.plot_widget = PlotWidget('Illuminance [lx]', plots, extra_key_widgets=[self.alf]) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): async_call(self.al.get_illuminance, None, self.cb_illuminance, self.increase_error_count) self.cbe_illuminance.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_illuminance.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletAmbientLight.DEVICE_IDENTIFIER def cb_illuminance(self, illuminance): self.current_illuminance = illuminance / 10.0 value = illuminance * 255 / 9000 self.alf.set_color(value, value, value)
class RotaryPotiV2(COMCUPluginBase): 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 start(self): 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletRotaryPotiV2.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position.value = position self.position_knob.set_value(position)
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.slider.setMinimumWidth(200) self.current_position = None plots = [('Position', Qt.red, lambda: self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], curve_motion_granularity=40, update_interval=0.025) layout = QVBoxLayout(self) 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 cb_position(self, position): self.current_position = position self.slider.setValue(position)
class AmbientLight(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletAmbientLight, *args) self.al = self.device self.cbe_illuminance = CallbackEmulator(self.al.get_illuminance, self.cb_illuminance, self.increase_error_count) self.alf = AmbientLightFrame() self.current_illuminance = None # float, lx plots = [('Illuminance', Qt.red, lambda: self.current_illuminance, '{} lx (Lux)'.format)] self.plot_widget = PlotWidget('Illuminance [lx]', plots, extra_key_widgets=[self.alf]) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): async_call(self.al.get_illuminance, None, self.cb_illuminance, self.increase_error_count) self.cbe_illuminance.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_illuminance.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'ambient_light' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletAmbientLight.DEVICE_IDENTIFIER def cb_illuminance(self, illuminance): self.current_illuminance = illuminance / 10.0 value = illuminance * 255 / 9000 self.alf.set_color(value, value, value)
class LinearPotiV2(COMCUPluginBase): def __init__(self, *args): super().__init__(BrickletLinearPotiV2, *args) self.lp = self.device self.cbe_position = CallbackEmulator(self, self.lp.get_position, None, self.cb_position, self.increase_error_count) self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 100) self.slider.setMinimumWidth(200) self.current_position = CurveValueWrapper() plots = [('Position', Qt.red, self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], update_interval=0.025, y_resolution=1.0) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLinearPotiV2.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position.value = position self.slider.setValue(position)
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.current_intensity = None self.thermo = TuningThermo() plots = [('Intensity Value', Qt.red, lambda: self.current_intensity, str)] self.plot_widget = PlotWidget('Intensity Value', plots, curve_motion_granularity=40, update_interval=0.025, extra_key_widgets=[self.thermo]) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def cb_intensity(self, intensity): self.thermo.set_value(intensity) self.current_intensity = 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletSoundIntensity.DEVICE_IDENTIFIER
class Line(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletLine, *args) self.line = self.device self.cbe_reflectivity = CallbackEmulator( self.line.get_reflectivity, self.cb_reflectivity, self.increase_error_count ) self.rf = ReflectivityFrame() self.current_reflectivity = None plots = [("Reflectivity", Qt.red, lambda: self.current_reflectivity, str)] self.plot_widget = PlotWidget("Reflectivity", plots) layout = QHBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(self.rf) def cb_reflectivity(self, reflectivity): self.current_reflectivity = reflectivity self.rf.set_reflectivity(reflectivity) def start(self): async_call(self.line.get_reflectivity, None, self.cb_reflectivity, self.increase_error_count) self.cbe_reflectivity.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_reflectivity.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return "line" @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLine.DEVICE_IDENTIFIER
class Line(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletLine, *args) self.line = self.device self.cbe_reflectivity = CallbackEmulator(self.line.get_reflectivity, self.cb_reflectivity, self.increase_error_count) self.rf = ReflectivityFrame() self.current_reflectivity = None plots = [('Reflectivity', Qt.red, lambda: self.current_reflectivity, str)] self.plot_widget = PlotWidget('Reflectivity', plots) layout = QHBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(self.rf) def cb_reflectivity(self, reflectivity): self.current_reflectivity = reflectivity self.rf.set_reflectivity(reflectivity) def start(self): async_call(self.line.get_reflectivity, None, self.cb_reflectivity, self.increase_error_count) self.cbe_reflectivity.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_reflectivity.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLine.DEVICE_IDENTIFIER
class AnalogOutV3(COMCUPluginBase, Ui_AnalogOutV3): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletAnalogOutV3, *args) self.setupUi(self) self.ao = self.device 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 start(self): async_call(self.ao.get_output_voltage, None, self.cb_get_output_voltage, self.increase_error_count) async_call(self.ao.get_input_voltage, None, self.cb_get_input_voltage, self.increase_error_count) self.cbe_input_voltage.set_period(1000) def stop(self): self.cbe_input_voltage.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletAnalogOutV3.DEVICE_IDENTIFIER def cb_get_output_voltage(self, voltage): self.output_voltage_box.setValue(voltage / 1000.0) def cb_get_input_voltage(self, voltage): self.input_voltage_label.setText("{:.3f} V".format( round(voltage / 1000.0, 2))) def voltage_finished(self): value = int(round(self.output_voltage_box.value() * 1000, 0)) try: print(value) self.ao.set_output_voltage(value) except ip_connection.Error: return
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.current_intensity = None self.thermo = TuningThermo() plots = [('Intensity Value', Qt.red, lambda: self.current_intensity, str)] self.plot_widget = PlotWidget('Intensity Value', plots, curve_motion_granularity=40, update_interval=0.025, extra_key_widgets=[self.thermo]) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def cb_intensity(self, intensity): self.thermo.set_value(intensity) self.current_intensity = 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 LinearPoti(PluginBase): def __init__(self, *args): super().__init__(BrickletLinearPoti, *args) self.lp = self.device self.cbe_position = CallbackEmulator(self.lp.get_position, None, self.cb_position, self.increase_error_count) self.slider = QSlider(Qt.Horizontal) self.slider.setRange(0, 100) self.slider.setMinimumWidth(200) self.current_position = CurveValueWrapper() plots = [('Position', Qt.red, self.current_position, str)] self.plot_widget = PlotWidget('Position', plots, extra_key_widgets=[self.slider], update_interval=0.025, y_resolution=1.0) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLinearPoti.DEVICE_IDENTIFIER def cb_position(self, position): self.current_position.value = position self.slider.setValue(position)
class TNGAI4U4I(TNGPluginBase, Ui_TNGAI4U4I): def __init__(self, *args): TNGPluginBase.__init__(self, TNGAI4U4IBindings, *args) self.setupUi(self) self.ai_4u_4i = self.device self.voltages = [ self.label_voltage_ch0, self.label_voltage_ch1, self.label_voltage_ch2, self.label_voltage_ch3, ] self.currents = [ self.label_current_ch0, self.label_current_ch1, self.label_current_ch2, self.label_current_ch3, ] self.cbe_values = CallbackEmulator(self, self.ai_4u_4i.get_values, None, self.cb_values, self.increase_error_count) def cb_values(self, values): for i, v in enumerate(values.voltages): self.voltages[i].setText('{}mV'.format(v)) for i, c in enumerate(values.currents): self.currents[i].setText('{}uA'.format(c)) def start(self): self.cbe_values.set_period(50) def stop(self): self.cbe_values.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == TNGAI4U4IBindings.DEVICE_IDENTIFIER
class Line(PluginBase): def __init__(self, *args): super().__init__(BrickletLine, *args) self.line = self.device self.cbe_reflectivity = CallbackEmulator(self.line.get_reflectivity, None, self.cb_reflectivity, self.increase_error_count) self.rf = ReflectivityFrame() self.current_reflectivity = CurveValueWrapper() plots = [('Reflectivity', Qt.red, self.current_reflectivity, str)] self.plot_widget = PlotWidget('Reflectivity', plots, y_resolution=1.0) layout = QHBoxLayout(self) layout.addWidget(self.plot_widget) layout.addWidget(self.rf) def cb_reflectivity(self, reflectivity): self.current_reflectivity.value = reflectivity self.rf.set_reflectivity(reflectivity) def start(self): self.cbe_reflectivity.set_period(25) self.plot_widget.stop = False def stop(self): self.cbe_reflectivity.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletLine.DEVICE_IDENTIFIER
class AnalogOutV3(COMCUPluginBase, Ui_AnalogOutV3): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletAnalogOutV3, *args) self.setupUi(self) self.ao = self.device self.output_voltage_box.editingFinished.connect(self.voltage_finished) self.cbe_input_voltage = CallbackEmulator(self.ao.get_input_voltage, None, self.cb_input_voltage, self.increase_error_count) def start(self): async_call(self.ao.get_output_voltage, None, self.get_output_voltage_async, self.increase_error_count) self.cbe_input_voltage.set_period(1000) def stop(self): self.cbe_input_voltage.set_period(0) def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletAnalogOutV3.DEVICE_IDENTIFIER def get_output_voltage_async(self, voltage): self.output_voltage_box.setValue(voltage / 1000.0) def cb_input_voltage(self, voltage): self.input_voltage_label.setText("{:.3f} V".format(round(voltage / 1000.0, 2))) def voltage_finished(self): value = int(round(self.output_voltage_box.value() * 1000, 0)) try: self.ao.set_output_voltage(value) except ip_connection.Error: return
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.current_dust_density = None plots = [('Dust Density', Qt.red, lambda: self.current_dust_density, u'{} µg/m³'.format)] self.plot_widget = PlotWidget(u'Dust Density [µg/m³]', plots) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def cb_dust_density(self, dust_density): self.current_dust_density = 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
class Moisture(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletMoisture, *args) self.moisture = self.device self.cbe_moisture = CallbackEmulator(self.moisture.get_moisture_value, self.cb_moisture, self.increase_error_count) self.current_moisture = None plots = [('Moisture Value', Qt.red, lambda: self.current_moisture, str)] self.plot_widget = PlotWidget('Moisture Value', plots) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def cb_moisture(self, moisture): self.current_moisture = moisture def start(self): async_call(self.moisture.get_moisture_value, None, self.cb_moisture, self.increase_error_count) self.cbe_moisture.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_moisture.set_period(0) self.plot_widget.stop = True def destroy(self): pass def get_url_part(self): return 'moisture' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletMoisture.DEVICE_IDENTIFIER
class SoundIntensity(PluginBase): def __init__(self, *args): super().__init__(BrickletSoundIntensity, *args) self.si = self.device self.cbe_intensity = CallbackEmulator(self.si.get_intensity, None, self.cb_intensity, self.increase_error_count) self.current_intensity = CurveValueWrapper() self.thermo = TuningThermo() plots = [('Intensity Value', Qt.red, self.current_intensity, str)] self.plot_widget = PlotWidget('Intensity Value', plots, update_interval=0.025, extra_key_widgets=[self.thermo], y_resolution=1.0) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def cb_intensity(self, intensity): self.thermo.set_value(intensity) self.current_intensity.value = intensity def start(self): 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletSoundIntensity.DEVICE_IDENTIFIER
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.current_co2_concentration = None # int, ppm plots = [('CO2 Concentration', Qt.red, lambda: self.current_co2_concentration, '{} ppm'.format)] self.plot_widget = PlotWidget('CO2 Concentration [ppm]', plots) layout = QVBoxLayout(self) 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 cb_co2_concentration(self, co2_concentration): self.current_co2_concentration = 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.current_temperature = None # float, °C plots = [('Temperature', Qt.red, lambda: self.current_temperature, u'{:.2f} °C'.format)] self.plot_widget = PlotWidget(u'Temperature [°C]', plots) layout = QVBoxLayout(self) 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 cb_temperature(self, temperature): self.current_temperature = 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.current_humidity = None # float, %RH plots = [('Relative Humidity', Qt.red, lambda: self.current_humidity, '{} %RH'.format)] self.plot_widget = PlotWidget('Relative Humidity [%RH]', plots) layout = QVBoxLayout(self) 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 cb_humidity(self, humidity): self.current_humidity = humidity / 10.0
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.current_voltage = None # float, V plots = [('Voltage', Qt.red, lambda: self.current_voltage, format_voltage)] self.plot_widget = PlotWidget('Voltage [V]', plots) layout = QVBoxLayout(self) 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 cb_voltage(self, voltage): self.current_voltage = voltage / 1000.0
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.current_temperature = None # float, °C plots = [('Temperature', Qt.red, lambda: self.current_temperature, u'{:.2f} °C'.format)] self.plot_widget = PlotWidget(u'Temperature [°C]', plots) layout = QVBoxLayout(self) 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletTemperature.DEVICE_IDENTIFIER def cb_temperature(self, temperature): self.current_temperature = temperature / 100.0
class Humidity(PluginBase): def __init__(self, *args): super().__init__(BrickletHumidity, *args) self.hum = self.device self.cbe_humidity = CallbackEmulator(self.hum.get_humidity, None, self.cb_humidity, self.increase_error_count) self.current_humidity = CurveValueWrapper() # float, %RH plots = [('Relative Humidity', Qt.red, self.current_humidity, '{} %RH'.format)] self.plot_widget = PlotWidget('Relative Humidity [%RH]', plots, y_resolution=0.1) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def start(self): 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletHumidity.DEVICE_IDENTIFIER def cb_humidity(self, humidity): self.current_humidity.value = humidity / 10.0
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.current_co2_concentration = None # int, ppm plots = [('CO2 Concentration', Qt.red, lambda: self.current_co2_concentration, '{} ppm'.format)] self.plot_widget = PlotWidget('CO2 Concentration [ppm]', plots) layout = QVBoxLayout(self) 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletCO2.DEVICE_IDENTIFIER def cb_co2_concentration(self, co2_concentration): self.current_co2_concentration = co2_concentration
class Moisture(PluginBase): def __init__(self, *args): PluginBase.__init__(self, BrickletMoisture, *args) self.moisture = self.device self.cbe_moisture = CallbackEmulator(self.moisture.get_moisture_value, self.cb_moisture, self.increase_error_count) self.current_moisture = None plots = [('Moisture Value', Qt.red, lambda: self.current_moisture, str) ] self.plot_widget = PlotWidget('Moisture Value', plots) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def cb_moisture(self, moisture): self.current_moisture = moisture def start(self): async_call(self.moisture.get_moisture_value, None, self.cb_moisture, self.increase_error_count) self.cbe_moisture.set_period(100) self.plot_widget.stop = False def stop(self): self.cbe_moisture.set_period(0) self.plot_widget.stop = True def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletMoisture.DEVICE_IDENTIFIER
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.current_voltage = None # float, V plots = [('Voltage', Qt.red, lambda: self.current_voltage, format_voltage)] self.plot_widget = PlotWidget('Voltage [V]', plots) layout = QVBoxLayout(self) 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletVoltage.DEVICE_IDENTIFIER def cb_voltage(self, voltage): self.current_voltage = voltage / 1000.0
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.current_dust_density = None plots = [('Dust Density', Qt.red, lambda: self.current_dust_density, u'{} µg/m³'.format)] self.plot_widget = PlotWidget(u'Dust Density [µg/m³]', plots) layout = QVBoxLayout(self) layout.addWidget(self.plot_widget) def cb_dust_density(self, dust_density): self.current_dust_density = 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 @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletDustDetector.DEVICE_IDENTIFIER
class OutdoorWeather(COMCUPluginBase, Ui_OutdoorWeather): def __init__(self, *args): COMCUPluginBase.__init__(self, BrickletOutdoorWeather, *args) self.outdoor_weather = self.device self.setupUi(self) self.cbe_identifiers_station = CallbackEmulator( self, self.outdoor_weather.get_station_identifiers, None, self.cb_station_identifiers, self.increase_error_count) self.cbe_identifiers_sensor = CallbackEmulator( self, 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.combo_identifier_station.setEnabled(False) self.combo_identifier_sensor.setEnabled(False) 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 update_station(self): if self.combo_identifier_station.isEnabled(): try: identifier = int(self.combo_identifier_station.currentText()) except: return async_call(self.outdoor_weather.get_station_data, identifier, self.get_station_data_async, self.increase_error_count) else: self.label_temperature_station.setText('---') self.label_humidity_station.setText('---') self.label_wind_speed_station.setText('---') self.label_gust_speed_station.setText('---') self.label_rain_level_station.setText('---') self.label_battery_level_station.setText('---') self.label_wind_direction_station.setText('---') self.label_last_change_station.setText('---') def update_sensor(self): if self.combo_identifier_sensor.isEnabled(): try: identifier = int(self.combo_identifier_sensor.currentText()) except: return async_call(self.outdoor_weather.get_sensor_data, identifier, self.get_sensor_data_async, self.increase_error_count) else: self.label_temperature_sensor.setText('---') self.label_humidity_sensor.setText('---') self.label_last_change_sensor.setText('---') def cb_station_identifiers(self, identifiers): old_text = self.combo_identifier_station.currentText() self.combo_identifier_station.setEnabled(False) self.combo_identifier_station.clear() for index, identifier in enumerate(identifiers): new_text = str(identifier) self.combo_identifier_station.addItem(new_text) if new_text == old_text: self.combo_identifier_station.setCurrentIndex(index) if self.combo_identifier_station.count() > 0: self.combo_identifier_station.setEnabled(True) else: self.combo_identifier_station.addItem('No Stations found') self.update_station() def cb_sensor_identifiers(self, identifiers): old_text = self.combo_identifier_sensor.currentText() self.combo_identifier_sensor.setEnabled(False) self.combo_identifier_sensor.clear() for index, identifier in enumerate(identifiers): new_text = str(identifier) self.combo_identifier_sensor.addItem(new_text) if new_text == old_text: self.combo_identifier_sensor.setCurrentIndex(index) if self.combo_identifier_sensor.count() > 0: self.combo_identifier_sensor.setEnabled(True) else: self.combo_identifier_sensor.addItem('No Sensors found') self.update_sensor() def get_station_data_async(self, data): self.label_temperature_station.setText("{:.1f}".format( data.temperature / 10.0)) self.label_humidity_station.setText("{}".format(data.humidity)) self.label_wind_speed_station.setText("{:.1f}".format(data.wind_speed / 10.0)) self.label_gust_speed_station.setText("{:.1f}".format(data.gust_speed / 10.0)) self.label_rain_level_station.setText("{:.1f}".format(data.rain / 10.0)) self.label_last_change_station.setText("{}".format(data.last_change)) if data.battery_low: self.label_battery_level_station.setText( "<font color='red'>Low</font>") else: self.label_battery_level_station.setText("OK") try: wind_direction = [ 'N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW' ][data.wind_direction] except: wind_direction = "<font color='red'>Unknown (Station Error)</font>" self.label_wind_direction_station.setText(wind_direction) def get_sensor_data_async(self, data): self.label_temperature_sensor.setText("{:.1f}".format( data.temperature / 10.0)) self.label_humidity_sensor.setText("{}".format(data.humidity)) self.label_last_change_sensor.setText("{}".format(data.last_change)) def start(self): self.cbe_identifiers_station.set_period(10000) self.cbe_identifiers_sensor.set_period(10000) self.data_timer_station.start(250) self.data_timer_sensor.start(250) def stop(self): self.cbe_identifiers_station.set_period(0) self.cbe_identifiers_sensor.set_period(0) self.data_timer_station.stop() self.data_timer_sensor.stop() def destroy(self): pass @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletOutdoorWeather.DEVICE_IDENTIFIER
class Calibration(QDialog, Ui_Calibration): def __init__(self, parent): QDialog.__init__(self, parent) 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: if self.parent.firmware_version >= ( 2, 0, 1): #fixed computation in 2.0.1 measured0 = (sum(self.values0) / 10.0) * 244 / 44983 measured1 = (sum(self.values1) / 10.0) * 244 / 44983 else: measured0 = (sum(self.values0) / 10.0) * 244 / 38588 measured1 = (sum(self.values1) / 10.0) * 244 / 38588 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 Accelerometer(PluginBase): def __init__(self, *args): super().__init__(BrickletAccelerometer, *args) self.accelerometer = self.device self.cbe_acceleration = CallbackEmulator( self.accelerometer.get_acceleration, None, self.cb_acceleration, self.increase_error_count, expand_result_tuple_for_callback=True) self.cbe_temperature = CallbackEmulator( 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
class IndustrialDualAnalogIn(PluginBase): 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) 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) self.cbe_voltage0.set_period(100) self.cbe_voltage1.set_period(100) async_call(self.analog_in.get_sample_rate, None, self.get_sample_rate_async, self.increase_error_count) 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() def get_url_part(self): return 'industrial_dual_analog_in' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletIndustrialDualAnalogIn.DEVICE_IDENTIFIER def get_voltage_value0(self): return self.voltage_value[0] def get_voltage_value1(self): return self.voltage_value[1] 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 get_sample_rate_async(self, rate): self.sample_rate_combo.setCurrentIndex(rate) def cb_voltage(self, sensor, voltage): value = voltage / 1000.0 self.voltage_label[sensor].setText('%6.03f' % round(value, 3)) self.voltage_value[sensor] = value