Exemplo n.º 1
0
 def run(self):
     self.fromSys = True
     self.serialManager = SerialManager()
     while (1):
         if (not (self.fromSys)):
             date = self.serialManager.receive()
             self.change_value.emit(date)
         delay(0.5)
Exemplo n.º 2
0
    def startGame(self):
        playing = True;
        isPlayer1Turn = True;
        self.board.initBoard();
        print("Serial initial!!!");
        sendManager = SerialManager();
        sendManager.sendNumber('c');
        while playing:
            self.board.printBoard();
            toMove = -1;
            if isPlayer1Turn:
                print("P1 turn...")
                while not self.board.addChip(self.p1.identifier, toMove):
                    toMove = self.p1.getPlayerMove(self.board);
            else:
                print("Computer turn...")
                while not self.board.addChip(self.p2.identifier, toMove):
                    toMove = self.p2.getPlayerMove(self.board);
            if toMove >= 0:
                print("Serial!!!");
                sendManager = SerialManager();
                sendManager.sendNumber(toMove);

            isPlayer1Turn = not isPlayer1Turn;
            score = self.board.getScore();
            if self.board.isFinished():
                playing = False;
                print("Alguien gano");
                if score > 1000:
                    print("Gano la computadora");
                else:
                    print("Ganaste");
Exemplo n.º 3
0
 def __init__(self, host, port):
     self.stop_event = threading.Event()
     self.to_serial = Queue.Queue()
     self.from_serial = Queue.Queue()
     self.to_web = Queue.Queue()
     self.from_web = Queue.Queue()
     self.serial_manager = SerialManager("/dev/ttyACM0", 9600, "/dev/ttyUSB0", 9600,
                                         self.stop_event,
                                         self.to_serial, self.from_serial)
     self.web_com = WebComunication(host, port, self.to_web, self.from_web, self.stop_event)
Exemplo n.º 4
0
class ReceiveTime(QThread):
    change_value = pyqtSignal(str)

    def run(self):
        self.fromSys = True
        self.serialManager = SerialManager()
        while (1):
            if (not (self.fromSys)):
                date = self.serialManager.receive()
                self.change_value.emit(date)
            delay(0.5)
Exemplo n.º 5
0
class Manager():
    def __init__(self, host, port):
        self.stop_event = threading.Event()
        self.to_serial = Queue.Queue()
        self.from_serial = Queue.Queue()
        self.to_web = Queue.Queue()
        self.from_web = Queue.Queue()
        self.serial_manager = SerialManager("/dev/ttyACM0", 9600, "/dev/ttyUSB0", 9600,
                                            self.stop_event,
                                            self.to_serial, self.from_serial)
        self.web_com = WebComunication(host, port, self.to_web, self.from_web, self.stop_event)

    def run(self):
        self.serial_manager.start()
        self.web_com.start()
        while True:
            if not self.from_serial.empty():
                data = ("error", "error")
                event = self.from_serial.get(block=False)
                if event["event_type"] == EventTypes.rfid_event:
                    #print("debug: getPattern")
                    self.time_start = time.time()
                    data = ("getPattern", event["e"])
                if event["event_type"] == EventTypes.mcu_event:
                    if event["e"] == Events.player_won:
                        #print("debug: end")
                        data = ("end", time.time() - self.time_start)
                    elif event["e"] == Events.player_error:
                        data = ("playerError", time.time() - self.time_start)

                if data[1] != "error":
                    self.to_web.put(data)

            if not self.from_web.empty():
                self.to_serial.put(self.from_web.get())

            time.sleep(0.01)
Exemplo n.º 6
0
class HandHandler(object):
    def __init__(self):
        self.sm = SerialManager()
        self.sm.connect('/dev/ttyACM1')

    def openHand(self):
        self.sm.writeLine('o')

    def closeHand(self):
        self.sm.writeLine('c')
Exemplo n.º 7
0
class WebServer(BaseHTTPRequestHandler):
    serialManager = SerialManager()
    fileManager = FileManager()

    def do_POST(self):
        self.protocol_version = "HTTP/1.1"
        self.send_response(200)
        self.send_header("Content-Length", 0)
        self.end_headers()

        content_len = int(self.headers.get('Content-Length'))
        body = self.rfile.read(content_len).decode("utf-8")
        if (body.isnumeric() and len(body) == 36):
            print("--- PLAYING SINGLE FRAME ---")
            self.serialManager.sendData(body)
        elif ("\n" in body):
            print("--- SAVING ANIMATION ---")
            self.fileManager.saveAnimation(body)
        else:
            print("--- PLAYING ANIMATION ---")
            self.serialManager.sendAnimation(
                self.fileManager.readAnimation(body), 0.2)
        return
Exemplo n.º 8
0
    def startApp(self):
        self.app = QtWidgets.QApplication(sys.argv)
        self.MainWindow = QtWidgets.QMainWindow()
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self.MainWindow)

        app_icon = QtGui.QIcon()
        app_icon.addFile('Logo.jpg', QtCore.QSize(256, 256))
        self.MainWindow.setWindowIcon(app_icon)
        self.MainWindow.show()

        self.translate = self.ui.translate
        self.portSelector = self.ui.portSelector
        self.baudSelector = self.ui.baudSelector
        self.hexBox = self.ui.hexBox
        self.console = self.ui.console_thread

        #Buttons
        self.connectButton = self.ui.connectButton
        self.flashButton = self.ui.flashButton
        self.eraseButton = self.ui.eraseButton
        self.sendButton = self.ui.sendButton
        #acciotns
        self.openFile = self.ui.actionOpen

        # Init Managers
        delay(1)
        self.consoleManager = ConsoleManager(self.console)
        self.serialManager = SerialManager(self.consoleManager, self.ui,
                                           self.app)
        self.fileManager = FileManager(self.hexBox, self.ui)
        self.burnerManager = BurnerManager(self.serialManager,
                                           self.fileManager,
                                           self.ui.progressBar,
                                           self.consoleManager)
        self.startSignals()
        self.startThreads()
Exemplo n.º 9
0
 def __init__(self):
     self.serialM = SerialManager()
     self.cam = CameraManager()
Exemplo n.º 10
0
    def __init__(self, interType, ui):  #Construtor da classe
        self.ui = ui
        self.interType = interType

        self.timer = QtCore.QTimer()

        self.ser1 = SerialManager(interType)

        self.ySize = 500

        if self.interType == 0:
            self.x_scale = 10
            self.nCurves = 2
            self.y_min = [0, 0]
            self.y_max = [32700, 10000]
            self.xSize = 780

            self.color = ['r', 'g']
            self.name = ["Força", "Tensão no Calibrante"]
            self.unit = ["Tonf", "mV"]

        elif self.interType == 1:
            self.x_scale = 10
            self.nCurves = 3
            self.y_min = [0, 0, 0]
            self.y_max = [32700, 10000, 5000]

            self.color = ['r', 'g', 'y']
            self.name = ["Temperatura", "Força", "Potência"]
            self.unit = ["ºC", "N", "W"]
            self.xSize = 735

        self.ser1.startPort(str(self.ser1.portList[1].device), 115200)
        self.ser1.serialListPanel(self.ui)

        self.layout = GraphicsLayout()

        self.updateTimer()

        self.scene = QtGui.QGraphicsScene()

        self.scene.addItem(self.layout)
        self.updateScale()

        #self.layout.setMaximumSize(770,550)
        self.scene.focusItem()

        self.sceneSelector(self.scene)

        self.ui.menuPlay_Pause = QtWidgets.QAction(self.ui.MainWindow)
        self.ui.menuPlay_Pause.setText("Play")
        self.ui.menuPlay_Pause.setObjectName("menuPlay_Pause")

        self.ui.menuBar.addAction(self.ui.menuPlay_Pause)
        self.ui.menuPlay_Pause.setCheckable(True)

        self.ui.menuPlay_Pause.triggered.connect(self.playPauseButtonAnimation)

        self.ui.linkActions()

        self.ui.t_max.returnPressed.connect(self.updateScale)
        self.ui.f_max.returnPressed.connect(self.updateScale)
        self.ui.f_min.returnPressed.connect(self.updateScale)
        self.ui.p_max.returnPressed.connect(self.updateScale)
        self.ui.p_min.returnPressed.connect(self.updateScale)

        if self.interType == 1:
            self.ui.temp_max.returnPressed.connect(self.updateScale)
            self.ui.temp_min.returnPressed.connect(self.updateScale)

        self.ui.samplingCBox.currentIndexChanged.connect(self.updateTimer)
        self.timeant = time.time()
        self.timer.timeout.connect(self.updateData)

        thread_instance = QtCore.QThread()
        thread_instance.start()
        thread_instance.exec_()
        self.timer.start(100)
Exemplo n.º 11
0
class SystemEngine(object):
    def __init__(self, interType, ui):  #Construtor da classe
        self.ui = ui
        self.interType = interType

        self.timer = QtCore.QTimer()

        self.ser1 = SerialManager(interType)

        self.ySize = 500

        if self.interType == 0:
            self.x_scale = 10
            self.nCurves = 2
            self.y_min = [0, 0]
            self.y_max = [32700, 10000]
            self.xSize = 780

            self.color = ['r', 'g']
            self.name = ["Força", "Tensão no Calibrante"]
            self.unit = ["Tonf", "mV"]

        elif self.interType == 1:
            self.x_scale = 10
            self.nCurves = 3
            self.y_min = [0, 0, 0]
            self.y_max = [32700, 10000, 5000]

            self.color = ['r', 'g', 'y']
            self.name = ["Temperatura", "Força", "Potência"]
            self.unit = ["ºC", "N", "W"]
            self.xSize = 735

        self.ser1.startPort(str(self.ser1.portList[1].device), 115200)
        self.ser1.serialListPanel(self.ui)

        self.layout = GraphicsLayout()

        self.updateTimer()

        self.scene = QtGui.QGraphicsScene()

        self.scene.addItem(self.layout)
        self.updateScale()

        #self.layout.setMaximumSize(770,550)
        self.scene.focusItem()

        self.sceneSelector(self.scene)

        self.ui.menuPlay_Pause = QtWidgets.QAction(self.ui.MainWindow)
        self.ui.menuPlay_Pause.setText("Play")
        self.ui.menuPlay_Pause.setObjectName("menuPlay_Pause")

        self.ui.menuBar.addAction(self.ui.menuPlay_Pause)
        self.ui.menuPlay_Pause.setCheckable(True)

        self.ui.menuPlay_Pause.triggered.connect(self.playPauseButtonAnimation)

        self.ui.linkActions()

        self.ui.t_max.returnPressed.connect(self.updateScale)
        self.ui.f_max.returnPressed.connect(self.updateScale)
        self.ui.f_min.returnPressed.connect(self.updateScale)
        self.ui.p_max.returnPressed.connect(self.updateScale)
        self.ui.p_min.returnPressed.connect(self.updateScale)

        if self.interType == 1:
            self.ui.temp_max.returnPressed.connect(self.updateScale)
            self.ui.temp_min.returnPressed.connect(self.updateScale)

        self.ui.samplingCBox.currentIndexChanged.connect(self.updateTimer)
        self.timeant = time.time()
        self.timer.timeout.connect(self.updateData)

        thread_instance = QtCore.QThread()
        thread_instance.start()
        thread_instance.exec_()
        self.timer.start(100)

    def playPauseButtonAnimation(self):
        if (self.ui.menuPlay_Pause.text() == "Play"):
            self.ui.menuPlay_Pause.setText("Pause")
            self.ui.startTimeLabel.setText(self.ui.currentTimeLabel.text())
        else:
            self.ui.menuPlay_Pause.setText("Play")

    def sceneSelector(self, scene):
        scene.setSceneRect(0, 0, 1000, 600)
        self.ui.CentralGraph.setScene(scene)
        self.ui.CentralGraph.setSceneRect(scene.sceneRect())
        self.ui.CentralGraph.setBackgroundBrush(QtCore.Qt.black)
        self.ui.CentralGraph.setInteractive(False)

    def updateData(self):
        #print(time.time()-self.timeant)
        if (self.ui.menuPlay_Pause.isChecked() == True):
            readData = self.ser1.read()  # Lê o dado da serial
            readData = readData.decode('utf8')
            #print(readData)
            dado = readData.split(' ', self.nCurves + 1)

            dado[len(dado) - 1] = dado[len(dado) - 1].split('\n', 2)[0]
            try:
                if self.interType == 0:
                    self.ui.forceLabel.setText(str(dado[0]) + " Tonf")
                    self.ui.calibratorLabel.setText(
                        str(dado[1].split()[0]) + " mV")

                elif self.interType == 1:
                    self.ui.tempLabel.setText(str(dado[0]) + "ºC")
                    self.ui.forceLabel.setText(str(dado[1].split()[0]) + " kN")
                    self.ui.powLabel.setText(str(dado[2].split()[0]) + " kW")

            except IndexError:
                print("Erro no Indice do Array Enviado pela Serial")
            try:
                self.graph.updateGraph(dado)

            except IndexError:
                print("Erro: Array inválido")
                print(dado)

        else:
            pass
        self.timeant = time.time()

    def updateScale(self):
        try:
            self.x_scale = int(self.ui.t_max.text())

            if self.interType == 0:
                self.y_min[0] = int(self.ui.f_min.text())
                self.y_max[0] = int(self.ui.f_max.text())
                self.y_min[1] = int(self.ui.p_min.text())
                self.y_max[1] = int(self.ui.p_max.text())

            elif self.interType == 1:
                self.y_min[0] = int(self.ui.temp_min.text())
                self.y_max[0] = int(self.ui.temp_max.text())
                self.y_min[1] = int(self.ui.f_min.text())
                self.y_max[1] = int(self.ui.f_max.text())
                self.y_max[2] = int(self.ui.p_max.text())
                self.y_min[2] = int(self.ui.p_min.text())

        except ValueError:
            self.x_scale = 100
            self.y_min[0] = 0
            self.y_max[0] = 32700
            self.y_min[1] = 0
            self.y_max[1] = 10000

            if self.interType == 1:
                self.y_min[2] = 0
                self.y_max[2] = 5000

            print("Erro!: Campos de Escala Vazios")

        if (self.x_scale == "0"):
            self.x_scale = "1"

        self.layout.clear()
        self.layout.setMinimumSize(500, 600)
        self.layout.setMaximumSize(500, 600)
        self.graph = Graph(self.time[0] / 1000, self.x_scale, self.nCurves,
                           self.y_min, self.y_max, self.xSize, self.ySize,
                           self.color, self.name, self.unit)

        self.layout.addItem(self.graph.axis[0],
                            row=1,
                            col=1,
                            rowspan=1,
                            colspan=1)
        for n in range(1, self.nCurves):
            self.layout.addItem(self.graph.axis[n],
                                row=1,
                                col=n + 2,
                                rowspan=1,
                                colspan=1)

        self.layout.addItem(self.graph, row=1, col=2, rowspan=1, colspan=1)
        self.layout.addItem(self.graph.axisTime,
                            row=2,
                            col=2,
                            rowspan=1,
                            colspan=1)

        self.scene.focusItem()

    def updateTimer(self):
        self.time = self.ui.samplingCBox.currentText().split(" ")
        self.time[0] = int(self.time[0])
        #print(self.time[0])
        if (self.time[0] < 100):
            self.time[0] = 1000 * self.time[0]

        self.timer.stop()
        self.timer.start(self.time[0])
Exemplo n.º 12
0
 def __init__(self, shape=1, qr=1):
     self.serialM = SerialManager()
     self.cam = CameraManager((shape, qr))
Exemplo n.º 13
0
 def __init__(self):
     self.sm = SerialManager()
     self.sm.connect('/dev/ttyACM1')
Exemplo n.º 14
0
import subprocess
import socket
from SerialManager import SerialManager

HOST = ""
PORT = 2727
PACKET_LENGTH = 18

print("Starting serial communication...")
serialManager = SerialManager()
print("Serial communication started successfully")

print("Starting control socket...")
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.bind((HOST, PORT))
print("Control socket started")
while True:
    try:
        data, address = s.recvfrom(1024)
        print("Length: " + str(len(data)))
        if (len(data) == PACKET_LENGTH):
            serialManager.sendData(data)
    except Exception as e:
        print(e)
if (s != null):
    s.close()