mirror of
https://github.com/modelec/tirette.git
synced 2026-03-18 21:50:31 +01:00
Omg somethings work
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "MyClient.h"
|
||||
|
||||
MyClient::MyClient(bool* tiretteState, const char* host, int port) : TCPClient(host, port), tiretteState(tiretteState)
|
||||
MyClient::MyClient(const char* host, int port) : TCPClient(host, port), tiretteState(false)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -17,7 +17,7 @@ void MyClient::handleMessage(const std::string& message)
|
||||
}
|
||||
}
|
||||
|
||||
void MyClient::setTiretteState(bool* tiretteState)
|
||||
void MyClient::setTiretteState(bool tiretteState)
|
||||
{
|
||||
this->tiretteState = tiretteState;
|
||||
}
|
||||
|
||||
@@ -6,11 +6,11 @@
|
||||
class MyClient : public TCPClient {
|
||||
|
||||
public:
|
||||
MyClient(bool* tiretteState, const char* host, int port);
|
||||
MyClient(const char* host, int port);
|
||||
|
||||
void handleMessage(const std::string& message) override;
|
||||
|
||||
void setTiretteState(bool* tiretteState);
|
||||
void setTiretteState(bool tiretteState);
|
||||
private:
|
||||
bool* tiretteState;
|
||||
bool tiretteState;
|
||||
};
|
||||
|
||||
14
main.cpp
14
main.cpp
@@ -17,22 +17,26 @@ int main() {
|
||||
pinMode(TIRETTE_GPIO, INPUT);
|
||||
|
||||
pullUpDnControl(TIRETTE_GPIO, PUD_UP);
|
||||
bool* tiretteState = new bool(true);
|
||||
|
||||
MyClient client(tiretteState, "127.0.0.1", 8080);
|
||||
MyClient client("127.0.0.1", 8080);
|
||||
|
||||
client.setTiretteState(tiretteState);
|
||||
|
||||
client.start();
|
||||
|
||||
int lastEtat = digitalRead(TIRETTE_GPIO);
|
||||
// Boucle principale
|
||||
while (true) {
|
||||
int etat = digitalRead(TIRETTE_GPIO);
|
||||
|
||||
if (etat == LOW) {
|
||||
std::cout << "Les aimants sont en contact." << std::endl;
|
||||
client.sendMessage("tirette;start;set tirette_state;1");
|
||||
client.setTiretteState(true);
|
||||
} else
|
||||
{
|
||||
std::cout << "Les aimants ne sont pas en contact." << std::endl;
|
||||
client.setTiretteState(false);
|
||||
if (lastEtat != etat) {
|
||||
client.sendMessage("tirette;strat;set tirette_state;0");
|
||||
}
|
||||
}
|
||||
|
||||
// Attendre un court délai avant de vérifier à nouveau
|
||||
|
||||
Reference in New Issue
Block a user