class Master(PluginBase, Ui_Master): def __init__(self, ipcon, uid, version): PluginBase.__init__(self, ipcon, uid, 'Master Brick', version) self.setupUi(self) self.master = BrickMaster(uid, ipcon) self.device = self.master self.update_timer = QTimer() self.update_timer.timeout.connect(self.update_data) self.extension_type = None self.extensions = [] self.num_extensions = 0 self.extension_label.setText("None Present") # Chibi widget if self.version >= (1, 1, 0): self.extension_type_button.pressed.connect(self.extension_pressed) async_call(self.master.is_chibi_present, None, self.is_chibi_present_async, self.increase_error_count) else: self.extension_type_button.setEnabled(False) # RS485 widget if self.version >= (1, 2, 0): async_call(self.master.is_rs485_present, None, self.is_rs485_present_async, self.increase_error_count) # Wifi widget if self.version >= (1, 3, 0): async_call(self.master.is_wifi_present, None, self.is_wifi_present_async, self.increase_error_count) def is_wifi_present_async(self, present): if present: wifi = Wifi(self) self.extensions.append(wifi) self.extension_layout.addWidget(wifi) self.num_extensions += 1 self.extension_label.setText("" + str(self.num_extensions) + " Present") def is_rs485_present_async(self, present): if present: rs485 = RS485(self) self.extensions.append(rs485) self.extension_layout.addWidget(rs485) self.num_extensions += 1 self.extension_label.setText("" + str(self.num_extensions) + " Present") def is_chibi_present_async(self, present): if present: chibi = Chibi(self) self.extensions.append(chibi) self.extension_layout.addWidget(chibi) self.num_extensions += 1 self.extension_label.setText("" + str(self.num_extensions) + " Present") def start(self): self.update_timer.start(100) def stop(self): self.update_timer.stop() def destroy(self): for extension in self.extensions: extension.destroy() if self.extension_type: self.extension_type.close() def has_reset_device(self): return self.version >= (1, 2, 1) def reset_device(self): if self.has_reset_device(): self.master.reset() def is_brick(self): return True def is_hardware_version_relevant(self, hardware_version): return True def get_url_part(self): return 'master' @staticmethod def has_device_identifier(device_identifier): return device_identifier == BrickMaster.DEVICE_IDENTIFIER def update_data(self): async_call(self.master.get_stack_voltage, None, self.stack_voltage_update, self.increase_error_count) async_call(self.master.get_stack_current, None, self.stack_current_update, self.increase_error_count) for extension in self.extensions: extension.update_data() def stack_voltage_update(self, sv): sv_str = "%gV" % round(sv/1000.0, 1) self.stack_voltage_label.setText(sv_str) def stack_current_update(self, sc): if sc < 999: sc_str = "%gmA" % sc else: sc_str = "%gA" % round(sc/1000.0, 1) self.stack_current_label.setText(sc_str) def extension_pressed(self): if self.extension_type is None: self.extension_type = ExtensionType(self) self.extension_type.show()
def extension_pressed(self): if self.extension_type is None: self.extension_type = ExtensionType(self) self.extension_type.show()