From 3771f3d2d75006f7f3f023ab04c62b5ed969275a Mon Sep 17 00:00:00 2001 From: ackimixs Date: Tue, 2 Apr 2024 16:59:31 +0200 Subject: [PATCH] open / close pince with tcp --- MainWindow.cpp | 20 +++++++++++++++----- tcp/MyTCPClient.cpp | 12 ++++++++---- tcp/MyTCPClient.h | 9 ++------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/MainWindow.cpp b/MainWindow.cpp index 382d2ae..59591cc 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -48,12 +48,22 @@ MainWindow::MainWindow(const char *address, int port, QWidget *parent) : QMainWi this->homologation = new Homologation(centralWidget); connect(this->homologation, &Homologation::deplierClicked, this, [&]() { - // TODO servo moteur - this->tcpClient->sendMessage("ihm;strat;deplier;1"); + this->tcpClient->sendMessage("ihm;servo_pot;baisser bras;1"); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + this->tcpClient->sendMessage("ihm;servo_pot;ouvrir pince;1"); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + this->tcpClient->sendMessage("ihm;servo_pot;ouvrir pince;2"); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + this->tcpClient->sendMessage("ihm;servo_pot;ouvrir pince;3"); }); connect(this->homologation, &Homologation::replierClicked, [&]() { - // TODO servo moteur - this->tcpClient->sendMessage("ihm;strat;replier;1"); + this->tcpClient->sendMessage("ihm;servo_pot;lever bras;1"); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + this->tcpClient->sendMessage("ihm;servo_pot;fermer pince;1"); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + this->tcpClient->sendMessage("ihm;servo_pot;fermer pince;2"); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + this->tcpClient->sendMessage("ihm;servo_pot;fermer pince;3"); }); this->teamChooser = new TeamChooser(centralWidget); @@ -80,7 +90,7 @@ MainWindow::MainWindow(const char *address, int port, QWidget *parent) : QMainWi this->testMode = new TestMode(centralWidget); connect(this->testMode, &TestMode::goPressed, [&](int x, int y, int theta) { - this->tcpClient->sendMessage("ihm;strat;go;" + std::to_string(x) + "," + std::to_string(y) + "," + std::to_string(theta)); + this->tcpClient->sendMessage("ihm;arduino;go;" + std::to_string(x) + "," + std::to_string(y) + "," + std::to_string(theta)); }); this->inGame = new InGame(teamChooser); diff --git a/tcp/MyTCPClient.cpp b/tcp/MyTCPClient.cpp index 6eac3b0..1e13e06 100644 --- a/tcp/MyTCPClient.cpp +++ b/tcp/MyTCPClient.cpp @@ -1,5 +1,9 @@ -// -// Created by acki on 3/30/24. -// - #include "MyTCPClient.h" + +MyTCPClient::MyTCPClient(const char *address, int port, QObject *parent) : TCPClient(address, port), QObject(parent) { + this->start(); +} + +void MyTCPClient::handleMessage(const std::string &message) { + emit messageReceived(message); +} diff --git a/tcp/MyTCPClient.h b/tcp/MyTCPClient.h index 4acaf4e..d4f3727 100644 --- a/tcp/MyTCPClient.h +++ b/tcp/MyTCPClient.h @@ -7,14 +7,9 @@ class MyTCPClient : public QObject, public TCPClient { Q_OBJECT public: - explicit MyTCPClient(const char* address = "127.0.0.1", int port = 8080, QObject* parent = nullptr) : TCPClient(address, port), QObject(parent) { - this->start(); - } - - void handleMessage(const std::string &message) override { - emit messageReceived(message); - }; + explicit MyTCPClient(const char* address = "127.0.0.1", int port = 8080, QObject* parent = nullptr); + void handleMessage(const std::string &message) override; signals: void messageReceived(const std::string &message); };