From f3c90fad0689629352e16d5f4d4ffafff32e75b4 Mon Sep 17 00:00:00 2001 From: Geoffrey Frogeye Date: Tue, 1 May 2018 09:03:33 +0200 Subject: [PATCH] Gestion des signaux --- chef/src/ihm.c | 2 +- chef/src/movement.c | 11 ++++++----- chef/src/premier.c | 28 +++++++++++++++++++++++----- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/chef/src/ihm.c b/chef/src/ihm.c index 9585a30..96b6fef 100644 --- a/chef/src/ihm.c +++ b/chef/src/ihm.c @@ -23,7 +23,6 @@ void startIHM() { configureButtons(); pthread_create(&tIHM, NULL, TaskIHM, NULL); - pthread_join(tIHM, NULL); } // t1 - t2 @@ -203,6 +202,7 @@ void* TaskIHM(void* pdata) void deconfigureIHM() { + pthread_cancel(tIHM); clearLCD(); printToLCD(LCD_LINE_1, "Bye bye!"); } diff --git a/chef/src/movement.c b/chef/src/movement.c index 5a07f12..59bb7c6 100644 --- a/chef/src/movement.c +++ b/chef/src/movement.c @@ -71,13 +71,14 @@ int freewheel() sendCF(C2FD_PWM, &msgFree, sizeof(struct C2FD_PWMs)); } -void deconfigureMovement() -{ - -} - int stop() { brake(); // TODO Actionneurs } + +void deconfigureMovement() +{ + stop(); +} + diff --git a/chef/src/premier.c b/chef/src/premier.c index 0c962d8..ac3503b 100644 --- a/chef/src/premier.c +++ b/chef/src/premier.c @@ -1,4 +1,5 @@ #include +#include #include #include #include // random seed @@ -7,34 +8,51 @@ #include "CF.h" #include "debug.h" +#include "i2c.h" #include "ihm.h" #include "movement.h" #include "position.h" +pthread_mutex_t sRunning; + +void endRunning(int signal) +{ + (void)signal; + printf("21\n"); + pthread_mutex_unlock(&sRunning); +} + int main() { - printf("Démarrage...\n"); if (wiringPiSetup() < 0) { fprintf(stderr, "Impossible d'initialiser WiringPi\n"); exit(EXIT_FAILURE); } initI2C(); - configureIHM(); - srand(time(NULL)); + + configureIHM(); configureDebug(); configureCF(); configureMovement(); configurePosition(); startDebug(); - startIHM(); + // Bloque jusqu'à l'arrivée d'un signal + pthread_mutex_init(&sRunning, NULL); + signal(SIGINT, endRunning); + signal(SIGTERM, endRunning); + signal(SIGQUIT, endRunning); + pthread_mutex_lock(&sRunning); + pthread_mutex_lock(&sRunning); + + deconfigureMovement(); deconfigureMovement(); deconfigurePosition(); deconfigureCF(); - deconfigureIHM(); deconfigureDebug(); + deconfigureIHM(); return EXIT_SUCCESS; }