def __init__(self, parent=None): super(FaceDection, self).__init__(parent) # gui connections self.ui = Ui_FaceDetection() self.ui.setupUi(self) self.ui.speed_dial.sliderMoved.connect(self.set_fan_speed) self.ui.horizontal_speed.sliderReleased.connect(self.horizontal_stop) self.ui.vertical_speed.sliderReleased.connect(self.vertical_stop) self.ui.horizontal_speed.valueChanged.connect(self.set_hor_speed) self.ui.vertical_speed.valueChanged.connect(self.set_ver_speed) self.ui.serial_select.currentIndexChanged.connect(self.port_select) self.ui.command_edit.returnPressed.connect(self.command_send) # video and face recognition self.faces = [] self.ui.video.face_callback = self.video_face_callback self.ui.video.image_callback = self.video_image_callback # serial connection self.serial = SerialConnection() for port in self.serial.list_ports(): self.ui.serial_select.addItem(port) self.listener_timer = QTimer(self) self.listener_timer.timeout.connect(self.serial_read) self.listener_timer.start(50)
def __init__(self): threading.Thread.__init__(self) self.SerialConnection = SerialConnection() self.WifiConnection = WifiConnection() self.BluetoothConnection = Bluetooth_Connection() self.WifiConnection.connect() self.wifiIsConnected = True self.BluetoothConnection.setupConnection() self.bluetoothIsConnected = True self.SerialConnection.connect() self.serialIsConnected = True
'INTERNAL ERROR with power switch detection', 4) state = WAIT_TO_RESET first_time_here_flag = True return state, first_time_here_flag if __name__ == "__main__": IDLE = 0 # ready for the card to be swiped WAIT_FOR_FIRST_DATABASE_RESPONSE = 1 # database has been quiried, waiting for it to respond WAIT_TO_RESET = 2 DATABASE_QUERY_TIMED_OUT = 3 SUPERVISOR_NEEDED = 4 TIMEING_ACCESS = 5 EXTEND_TIME_PROMPT = 6 CHECK_FOR_CLOSED_POWER_SWITCH = 7 # SerConn = SerialConnection.SerialClass() Data = DataBase.DataBase() timeoutTimer1 = timeoutTimer.timeoutTimer() timeoutTimer2 = timeoutTimer.timeoutTimer() displayscreen = tk.Tk() displayscreen.overrideredirect(True) Dis = DisplayStuff.Display(displayscreen) state = IDLE flag = True while True: SerConn.attempt_to_get_readings() if flag: print("STATE=", state) (s, f) = mainloop(state, flag) if f: print("newstate=", s)
class FaceDection(QMainWindow): def __init__(self, parent=None): super(FaceDection, self).__init__(parent) # gui connections self.ui = Ui_FaceDetection() self.ui.setupUi(self) self.ui.speed_dial.sliderMoved.connect(self.set_fan_speed) self.ui.horizontal_speed.sliderReleased.connect(self.horizontal_stop) self.ui.vertical_speed.sliderReleased.connect(self.vertical_stop) self.ui.horizontal_speed.valueChanged.connect(self.set_hor_speed) self.ui.vertical_speed.valueChanged.connect(self.set_ver_speed) self.ui.serial_select.currentIndexChanged.connect(self.port_select) self.ui.command_edit.returnPressed.connect(self.command_send) # video and face recognition self.faces = [] self.ui.video.face_callback = self.video_face_callback self.ui.video.image_callback = self.video_image_callback # serial connection self.serial = SerialConnection() for port in self.serial.list_ports(): self.ui.serial_select.addItem(port) self.listener_timer = QTimer(self) self.listener_timer.timeout.connect(self.serial_read) self.listener_timer.start(50) def set_fan_speed(self, speed, update_dial=False): self.ui.speed_label.setText("%d %%" % speed) self.serial.send("VENT " + str(speed)) if update_dial: self.ui.speed_dial.setValue(speed) def horizontal_stop(self): self.serial.send("STOP") self.ui.horizontal_speed.setValue(0) # snap back def vertical_stop(self): self.serial.send("STOP") self.ui.vertical_speed.setValue(0) # snap back def set_hor_speed(self, value): if not value == 0: self.serial.send("IBASE " + str(value)) def set_ver_speed(self, value): if not value == 0: self.serial.send("IELBOW " + str(value)) def serial_read(self): message_queue = self.serial.queue while not message_queue.empty(): message = message_queue.get_nowait() if message[0] == "#": self.ui.log.append("<b>" + message + "</b>") elif message[0] == "!": self.ui.log.append("<font color=red>" + message + "</font>") message_queue.task_done() def command_send(self): command = self.ui.command_edit.text() self.serial.send(command) self.ui.command_edit.clear() def port_select(self, index): # disconnect if index == 0: self.serial.stop() self.ui.log.clear() self.ui.command_edit.clear() self.ui.command_edit.setEnabled(False) self.ui.fanbox.setEnabled(False) self.ui.movementbox.setEnabled(False) # connect else: try: port = self.ui.serial_select.currentText() self.serial.connect(port=port, baud=19200) self.ui.command_edit.setEnabled(True) self.ui.fanbox.setEnabled(True) self.ui.movementbox.setEnabled(True) except Exception, e: QMessageBox.warning(self, "Error", e.message)
return OK def send_relay_mainpowerOFF(self): OK = self.initiate_arduino_command("write", str(self.MAINPOWER_RELAY_PIN), "1") return OK def send_relay_mainpowerON(self): OK = self.initiate_arduino_command("write", str(self.MAINPOWER_RELAY_PIN), "0") return OK if __name__ == "__main__": print('HI there') # define the serial port sport = SerialConnection.SerialClass() sio = io.TextIOWrapper(io.BufferedRWPair(sport.ser, sport.ser)) sio.write(("hello\n")) sio.flush() # it is buffering. required to get the data out *now* # define the command processor ACommandProc = ArdCommandResponse(sport) stophere = True while stophere: sport.attempt_to_get_readings() if sport.cardID_available: print("cardID=", sport.get_cardID()) if sport.alive_available: print("alive=", sport.get_alive()) stophere = False print('Arduino is alive ') i = 0
class RPIInit(threading.Thread): def __init__(self): threading.Thread.__init__(self) self.SerialConnection = SerialConnection() self.WifiConnection = WifiConnection() self.BluetoothConnection = Bluetooth_Connection() self.WifiConnection.connect() self.wifiIsConnected = True self.BluetoothConnection.setupConnection() self.bluetoothIsConnected = True self.SerialConnection.connect() self.serialIsConnected = True def readFromWifiConnection(self): while True: try: msg = self.WifiConnection.read() if msg == '': print('Wifi Connection is Lost') self.wifiIsConnected = False break command = msg[0:1] print(command) print('From PC: ' + str(msg)) if command == 'A': self.SerialConnection.write(str(msg[1:])) elif command == 'T': self.BluetoothConnection.clientWrite(str(msg[1:])) elif command == ';': self.WifiConnection.write('RPi3: connection closed') self.wifiIsConnected = False break else: self.WifiConnection.write('Rpi3: Message received') except Exception as e: print('readFromWifiConnection Error' + str(e)) def readFromBluetoothConnection(self): while True: try: msg = self.BluetoothConnection.clientRead() if msg == '': print('bluetooth connection lost') self.bluetoothIsConnected = False break command = msg[0:1] print(command) print('From Bluetooth:' + str(msg)) if command == 'P': self.WifiConnection.write(str(msg[1:])) elif command == 'A': self.SerialConnection.write(str(msg[1:])) elif msg == ';': self.BluetoothConnection.clientWrite( 'RPi3: Connection closed') self.bluetoothIsConnected = False break else: self.BluetoothConnection.clientWrite('RPi3: Msg received') except Exception as e: print('readFromBluetoothConnection Error' + str(e)) def readFromSerialConnection(self): while True: try: msg = self.SerialConnection.read() if msg == '': print('serial conncetion is lost') self.serialIsConnected = False break command = msg[0:1] print(command) print('From Arduino:' + str(msg)) if command == 'P': self.WifiConnection.write(str(msg[1:])) elif command == 'T': self.BluetoothConnection.write('RPi3: Instruction ' + str(msg[1:]) + ' Sent to Tablet') elif msg == ';': self.SerialConnection.Write('RPi3: Connection Closed') self.serialIsConnected = False break else: print('works') except Exception as e: print('readFromSerialConnection Error' + str(e)) def startThreads(self): bluetoothThread = threading.Thread( target=self.readFromBluetoothConnection, name='Bluetooth Thread') wifiThread = threading.Thread(target=self.readFromBluetoothConnection, name="Bluetooth Thread") serialThread = threading.Thread(target=self.readFromSerialConnection, name="Serial Thread") bluetoothThread.daemon = True wifiThread.daemon = True serialThread.daemon = True print('Susccessfully initialized threads') bluetoothThread.start() wifiThread.start() serialThread.start() print("Worker Threads started") def cleanup(self): try: self.WifiConnection.close() self.BluetoothConnection.close() self.SerialConnection.close() except Exception as e: print("Cleanup Error:" + str(e))
self.pan = msg.getRelativePan() self.tilt = msg.getRelativeTilt() # print("pan=" + str(self.pan) + ", tilt=" + str(self.tilt)) self.putMessage(msg) self.update() def update(self): with self.lock: if (self.timer is None): self.timer = threading.Timer(0.05, self.doCommunication) self.timer.start() def doCommunication(self): with self.lock: self.serialConnection.setPan(self.pan) self.serialConnection.setTilt(self.tilt) self.timer.cancel() self.timer = None if __name__ == "__main__": serialConnection = SerialConnection.SerialConnection() serialConnection.requestUserConnection() # cv = CurrentValue.CurrentValue() handler = MessageHandler(serialConnection) # app = defaultWebsocketApp.defaultWebsocketApp(handler.handleMessage) # app.start() lpc = longPollClient.longPollClient() while (True): point = lpc.getLatestPoint() handler.handleMessage(point)
class FaceDection(QMainWindow): def __init__(self, parent=None): super(FaceDection, self).__init__(parent) # gui connections self.ui = Ui_FaceDetection() self.ui.setupUi(self) self.ui.speed_dial.sliderMoved.connect(self.set_fan_speed) self.ui.horizontal_speed.sliderReleased.connect(self.horizontal_stop) self.ui.vertical_speed.sliderReleased.connect(self.vertical_stop) self.ui.horizontal_speed.valueChanged.connect(self.set_hor_speed) self.ui.vertical_speed.valueChanged.connect(self.set_ver_speed) self.ui.serial_select.currentIndexChanged.connect(self.port_select) self.ui.command_edit.returnPressed.connect(self.command_send) # video and face recognition self.faces = [] self.ui.video.face_callback = self.video_face_callback self.ui.video.image_callback = self.video_image_callback # serial connection self.serial = SerialConnection() for port in self.serial.list_ports(): self.ui.serial_select.addItem(port) self.listener_timer = QTimer(self) self.listener_timer.timeout.connect(self.serial_read) self.listener_timer.start(50) def set_fan_speed(self, speed, update_dial=False): self.ui.speed_label.setText("%d %%" % speed) self.serial.send("VENT " + str(speed)) if update_dial: self.ui.speed_dial.setValue(speed) def horizontal_stop(self): self.serial.send("STOP") self.ui.horizontal_speed.setValue(0) # snap back def vertical_stop(self): self.serial.send("STOP") self.ui.vertical_speed.setValue(0) # snap back def set_hor_speed(self, value): if not value == 0: self.serial.send("IBASE "+str(value)) def set_ver_speed(self, value): if not value == 0: self.serial.send("IELBOW "+str(value)) def serial_read(self): message_queue = self.serial.queue while not message_queue.empty(): message = message_queue.get_nowait() if message[0] == "#": self.ui.log.append("<b>"+message+"</b>") elif message[0] == "!": self.ui.log.append("<font color=red>"+message+"</font>") message_queue.task_done() def command_send(self): command = self.ui.command_edit.text() self.serial.send(command) self.ui.command_edit.clear() def port_select(self, index): # disconnect if index == 0: self.serial.stop() self.ui.log.clear() self.ui.command_edit.clear() self.ui.command_edit.setEnabled(False) self.ui.fanbox.setEnabled(False) self.ui.movementbox.setEnabled(False) # connect else: try: port = self.ui.serial_select.currentText() self.serial.connect(port=port, baud=19200) self.ui.command_edit.setEnabled(True) self.ui.fanbox.setEnabled(True) self.ui.movementbox.setEnabled(True) except Exception, e: QMessageBox.warning(self, "Error", e.message)