def _pump_emit(self, bot_id, instruct, is_open): self._ui.ui_log_pump.setText(f'{bot_id} {instruct} {is_open}') if instruct in [ 'WATER_HIGH', 'CHEM_ALKALI', 'CHEM_ACID', 'WHEEL', 'WATER_WAX' ]: QTools.set_led_style(ui_btn=self._leds[instruct], color='GREEN' if is_open else 'RED') elif instruct == 'ALL STOP': for instruct in [ 'WATER_HIGH', 'CHEM_ALKALI', 'CHEM_ACID', 'WHEEL', 'WATER_WAX' ]: QTools.set_led_style(ui_btn=self._leds[instruct + str(bot_id)], color='RED')
def __init__(self, ui: Ui_MainWindow, one_pump: OnePump, bot_id=1): self._ui = ui self._bot_id = bot_id self._one_pump = one_pump # UI: TABLE self._ui.table_liquids.verticalHeader().setFixedWidth(66) QTools.table_init(table=self._ui.table_liquids) for liquid_id in [0, 1, 2, 3, 4]: self._ui.table_liquids.item( liquid_id, 0).setText(f"{self._one_pump.get_liquid_ts_remain(liquid_id)}") # UI LED self._leds = { 1: { 0: self._ui.led_water_high, 1: self._ui.led_ch_a, 2: self._ui.led_ch_b, 3: self._ui.led_ch_whl, 4: self._ui.led_ch_wax }, 2: { 0: self._ui.led_water_high, 1: self._ui.led_ch_a, 2: self._ui.led_ch_b, 3: self._ui.led_ch_whl, 4: self._ui.led_ch_wax } } # UI: SIGNAL self._one_pump.sign_tcp_online.connect(self._signal_tcp_online) self._one_pump.sign_sensor_level.connect(self._signal_one_liquid_level) self._one_pump.sign_pump_shooting.connect(self._signal_pump_shooting) self._one_pump.sign_pump_remain_ts.connect(self._signal_pump_remain_ts) # TEST_BTN self._ui.btn_stop_all.clicked.connect(self._stop_all) self._ui.btn_ch_whl.stateChanged.connect( lambda x: self._one_pump.set_liquid_shooting(3, x, 0)) self._ui.btn_ch_a.stateChanged.connect( lambda x: self._one_pump.set_liquid_shooting(1, x, 0)) self._ui.btn_ch_b.stateChanged.connect( lambda x: self._one_pump.set_liquid_shooting(2, x, 0)) self._ui.btn_water.stateChanged.connect( lambda x: self._one_pump.set_liquid_shooting(0, x, 0)) self._ui.btn_ch_wax.stateChanged.connect( lambda x: self._one_pump.set_liquid_shooting(4, x, 0))
def _liquid_raw_data(self, liquid_raw_data): self._ui.ui_water_data.setText(f"{liquid_raw_data['WATER']}") self._ui.ui_alkali_data.setText(f"{liquid_raw_data['ALKALI']}") self._ui.ui_acid_data.setText(f"{liquid_raw_data['ACID']}") self._ui.ui_wheel_data.setText(f"{liquid_raw_data['WHEEL']}") self._ui.ui_wax_data.setText(f"{liquid_raw_data['WAX']}") for liquid_type in liquid_raw_data.keys(): liquid_height = 100 if liquid_type == 'WATER' else 60 container_height = 900 if liquid_type == 'WATER' else 250 color = 'RED' if liquid_raw_data[ liquid_type] <= liquid_height else 'GREEN' text = 'WARNING' if liquid_raw_data[ liquid_type] <= liquid_height else ' ' QTools.set_led_style(ui_btn=self._leds[liquid_type], color=color) self._leds[liquid_type].setText(text) percent = liquid_raw_data[liquid_type] / container_height progress = QTools.set_style_sheet(percent=percent) self._leds[liquid_type].setStyleSheet(progress)
def _stop_all(self): self._one_pump.stop_all() for liquid_id in [0, 1, 2, 3, 4]: QTools.set_led_style(ui_btn=self._leds[self._bot_id][liquid_id], color='GREEN') self._leds[self._bot_id][liquid_id].setChecked(0) # 未启动
def _signal_pump_shooting(self, bot_id, liquid_id, switch): QTools.set_led_style(self._leds[bot_id][liquid_id], color='DARK_GREEN' if switch else 'GREEN')
def _signal_tcp_online(self, is_online, ip, port): QTools.set_led_style(ui_btn=self._ui.led_tcp_pump, color='GREEN' if is_online else 'RED') for liquid_id in [0, 1, 2, 3, 4]: QTools.set_led_style(ui_btn=self._leds[self._bot_id][liquid_id], color='GREEN' if is_online else 'RED')
def _tcp_online(self, is_online, ip, port): QTools.set_led_style(ui_btn=self._ui.led_pump_station, color='GREEN' if is_online else 'RED') self._ui.led_pump_station.setText('ON' if is_online else 'OFF') self._ui.ip_nuc.setText(f'NUC_IP {ip}') self._ui.log_network.append(f'{ip} {port}')