def __init__(self, ipcon, uid, version): PluginBase.__init__(self, ipcon, uid, 'Hall Effect Bricklet', version) self.setupUi(self) self.hf = BrickletHallEffect(uid, ipcon) self.qtcb_edge_count.connect(self.cb_edge_count) self.hf.register_callback(self.hf.CALLBACK_EDGE_COUNT, self.qtcb_edge_count.emit) self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] axis_scales = [(Qwt.QwtPlot.yLeft, 0, 1, 1)] self.plot_widget = PlotWidget('Value', plot_list, axis_scales=axis_scales) self.combo_edge_type.activated.connect(self.edge_changed) self.spin_debounce.editingFinished.connect(self.debounce_changed) self.main_layout.insertWidget(1, self.plot_widget)
class HallEffect(PluginBase, Ui_HallEffect): qtcb_edge_count = pyqtSignal(int, bool) def __init__(self, ipcon, uid, version): PluginBase.__init__(self, ipcon, uid, 'Hall Effect Bricklet', version) self.setupUi(self) self.hf = BrickletHallEffect(uid, ipcon) self.qtcb_edge_count.connect(self.cb_edge_count) self.hf.register_callback(self.hf.CALLBACK_EDGE_COUNT, self.qtcb_edge_count.emit) self.current_value = None plot_list = [['', Qt.red, self.get_current_value]] axis_scales = [(Qwt.QwtPlot.yLeft, 0, 1, 1)] self.plot_widget = PlotWidget('Value', plot_list, axis_scales=axis_scales) self.combo_edge_type.activated.connect(self.edge_changed) self.spin_debounce.editingFinished.connect(self.debounce_changed) self.main_layout.insertWidget(1, self.plot_widget) def debounce_changed(self): self.hf.set_edge_count_config(self.combo_edge_type.currentIndex(), self.spin_debounce.value()) def edge_changed(self, value): self.hf.set_edge_count_config(self.combo_edge_type.currentIndex(), self.spin_debounce.value()) def cb_edge_count(self, count, value): self.label_edge_count.setText(str(count)) if value: self.current_value = 1 else: self.current_value = 0 def get_current_value(self): return self.current_value def cb_edge_count_config(self, conf): edge_type, debounce = conf self.combo_edge_type.setCurrentIndex(edge_type) self.spin_debounce.setValue(debounce) def get_edge_count_async(self, count): self.label_edge_count.setText(str(count)) def get_value_async(self, value): if value: self.current_value = 1 else: self.current_value = 0 def start(self): async_call(self.hf.get_edge_count_config, None, self.cb_edge_count_config, self.increase_error_count) async_call(self.hf.set_edge_count_callback_period, 50, None, self.increase_error_count) async_call(self.hf.get_edge_count, False, self.get_edge_count_async, self.increase_error_count) async_call(self.hf.get_value, None, self.get_value_async, self.increase_error_count) self.plot_widget.stop = False def stop(self): async_call(self.hf.set_edge_count_callback_period, 0, None, self.increase_error_count) self.plot_widget.stop = True def get_url_part(self): return 'hall_effect' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickletHallEffect.DEVICE_IDENTIFIER