def run(self): self.predicted_items = [] try: with picamera.PiCamera(resolution=(1280, 720), framerate=30) as camera: # camera.start_preview() stream = BytesIO() for _ in camera.capture_continuous(stream, format='jpeg', use_video_port=True): if window.delivery_state in ['recognize', 'enter']: print('capturing...') stream.seek(0) label, score = window.image_classifier(stream) if score > window.predict_item_threshold: self.predicted_items.append(label) print(label, score) stream.seek(0) stream.truncate() else: # camera.stop_preview() break except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In AutoDeliveryItemsThread')
def endDeliveryItem(self): print('endDeliveryItem') if self.delivery_state == 'end': try: # self.showNotification(RECYCLE_MESSAGE) sleep(0.01) self.cancel_delivery_item_timer.cancel() self.playSound('audio3') self.selected_item['count'] += 1 self.ui.lbl_selected_item_count.setText( str(self.selected_item['count'])) for user_item in self.user_items: if self.selected_item['id'] == user_item['id']: break else: self.user_items.append(self.selected_item) # self.conveyor_motor.stop() try: self.press_motor.forward(True) except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In press_motor_stop_timer startDeliveryItem Method') sleep(1) self.delivery_state = 'ready' except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In endDeliveryItem Method')
def playSound(self, path): try: path = os.path.join('sounds', path + '.mp3') if os.path.isfile(path): mixer.music.load(path) mixer.music.play() except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In playSound Method')
def run(self): try: print("Now place your tag to write") id, old_data = window.rfid_sensor.read() new_data = window.ui.lbl_transfer_to_rfid.text() if old_data.isdigit(): data = int(new_data) + int(old_data) else: data = int(new_data) window.rfid_sensor.write(str(data)) print("Written") self.success_signal.emit() except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In transferToRFIDCard Method') self.fail_signal.emit()
def stackAfterDelivery(self): try: # self.total_price = sum(user_item['price'] * user_item['count'] for user_item in window.user_items) self.delivery_state = 'default' self.playSound('audio12') # self.setButton(self.ui.btn_left, show=False) # self.setButton(self.ui.btn_right, show=False) self.ui.lbl_notification.hide() # gif_afterDelivery = QMovie("animations/earth.gif") # self.ui.lbl_gif_after_delivery.setMovie(gif_afterDelivery) # gif_afterDelivery.start() # self.ui.lbl_total_price.setText(str(self.total_price)) self.printReceipt() except: self.showNotification(SERVER_ERROR_MESSAGE) ErrorLog.writeToFile('Server Error Message') try: self.press_motor.stop() self.conveyor_motor.stop() except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In stackAfterDelivery Method')
def manualDeliveryRecycleItem(self): try: self.showNotification(RECYCLE_MESSAGE) try: self.conveyor_motor.forward(timer=True) except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In press_motor_stop_timer startDeliveryItem Method') self.playSound('audio3') self.ui.btn_right.show() self.selected_item['count'] += 1 self.ui.lbl_selected_item_count.setText( str(self.selected_item['count'])) for user_item in self.user_items: if self.selected_item['id'] == user_item['id']: break else: self.user_items.append(self.selected_item) self.total_price = sum(user_item['price'] * user_item['count'] for user_item in self.user_items) self.ui.lbl_total.setText(str(self.total_price)) try: self.press_motor.forward(timer=True) except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In press_motor_stop_timer startDeliveryItem Method') except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In endDeliveryItem Method')
def stopSound(self): try: mixer.music.stop() except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In stopSound Method')
def initHardwares(self): try: if hasattr(self, 'press_motor'): self.press_motor.close() if hasattr(self, 'conveyor_motor'): self.conveyor_motor.close() if hasattr(self, 'distance_sensor1'): self.distance_sensor1.close() print("distance sensor 1 close") if hasattr(self, 'distance_sensor2'): self.distance_sensor2.close() print("distance sensor 2 close") except Exception as e: print("error:", e) try: self.press_motor = Motor(name='press_motor', pin_factory=factory) self.setButton(self.ui.btn_press_motor_forward_on, function=self.press_motor.forward) self.setButton(self.ui.btn_press_motor_backward_on, function=self.press_motor.backward) self.setButton(self.ui.btn_press_motor_off, function=self.press_motor.stop) except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In press_motor initHardwares Method') try: # normal # self.conveyor_motor = Motor(name='conveyor_motor', pin_factory=factory) # red relay self.conveyor_motor = Motor(name='conveyor_motor', pin_factory=factory, active_high=True) self.conveyor_motor_time_2 = float( DataBase.select('conveyor_motor_time_2')) self.setButton(self.ui.btn_conveyor_motor_forward_on, function=self.conveyor_motor.forward) self.setButton(self.ui.btn_conveyor_motor_backward_on, function=self.conveyor_motor.backward) self.setButton(self.ui.btn_conveyor_motor_off, function=self.conveyor_motor.stop) except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In conveyor_motor initHardwares Method') try: distance_sensor1_trig_port = int( DataBase.select('distance_sensor1_trig_port')) distance_sensor1_echo_port = int( DataBase.select('distance_sensor1_echo_port')) distance_sensor1_threshold_distance = float( DataBase.select('distance_sensor1_threshold_distance')) self.distance_sensor1 = DistanceSensor( distance_sensor1_echo_port, distance_sensor1_trig_port, max_distance=1, threshold_distance=distance_sensor1_threshold_distance / 100, pin_factory=factory) self.distance_sensor1.when_in_range = self.distanceSensor1WhenInRange self.distance_sensor1.when_out_of_range = self.distanceSensor1WhenOutOfRange print('distance sensor 1 ready') except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In distance_sensor1 initHardwares Method') try: distance_sensor2_trig_port = int( DataBase.select('distance_sensor2_trig_port')) distance_sensor2_echo_port = int( DataBase.select('distance_sensor2_echo_port')) distance_sensor2_threshold_distance = float( DataBase.select('distance_sensor2_threshold_distance')) self.distance_sensor2 = DistanceSensor( distance_sensor2_echo_port, distance_sensor2_trig_port, max_distance=1, threshold_distance=distance_sensor2_threshold_distance / 100, pin_factory=factory) self.distance_sensor2.when_in_range = self.distanceSensor2WhenInRange self.distance_sensor2.when_out_of_range = self.distanceSensor2WhenOutOfRange print('distance sensor 2 ready') except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In distance_sensor2 initHardwares Method') try: if not hasattr(self, 'rfid_sensor'): self.rfid_sensor = SimpleMFRC522() print('RFID sensor ready') except Exception as e: print("error:", e) ErrorLog.writeToFile( str(e) + ' In rfid_sensor initHardwares Method')
def exitProgram(self): # Server.turnOffSystemSMS(self.owner, self.system) self.delivery_item_flag = False self.close() QApplication.quit() if __name__ == '__main__': os.environ["QT_QPA_FB_FORCE_FULLSCREEN"] = "0" os.environ["QT_IM_MODULE"] = "qtvirtualkeyboard" os.environ["QT_QPA_FONTDIR"] = "/fonts" # os.environ["ESCPOS_CAPABILITIES_FILE"] = "/usr/python-escpos/capabilities.json" mixer.init() qr = qrcode.QRCode(version=2, error_correction=qrcode.constants.ERROR_CORRECT_L, box_size=10, border=4) try: factory = NativeFactory() except Exception as e: print("error:", e) ErrorLog.writeToFile(str(e) + ' In NativeFactory') app = QApplication(sys.argv) window = MainWindow() #timer = QTimer() #timer.start(10000) #it's aboat 1 seconds app.exec_()