diff --git a/arduino/arduino.ino b/arduino/arduino.ino index c202a7b..8c73d10 100644 --- a/arduino/arduino.ino +++ b/arduino/arduino.ino @@ -66,60 +66,64 @@ void loop() bool codeInconnu = false; switch (lettre) { - case 'L': // Ouverture loquet - servoLoquet.write(100); - delay(500); - break; - case 'F': // Fermeture loquet - servoLoquet.write(0); - delay(500); - break; - case 'A': // Position attente balle - servoPositionBalle.write(70); - delay(500); - break; - case 'V': // Position évacuation balle - servoPositionBalle.write(0); - delay(500); - break; - case 'O': // Pousser balle - // Position basse - servoPoussoir.write(0); - //delay(500); - // Position haute - servoPoussoir.write(120); - delay(1000); - break; - case 'B': // Tourner barillet d'un cran - barilletUnCran(); - delay(500); - break; - case 'H': // Tourner de deux crans - barilletDeuxCrans(); - delay(500); - break; - case 'R': // Reset barillet - // ax12a.setEndless(ID, OFF); - ax12a.setEndless(ID, ON); - ax12a.turn(ID, LEFT, 0); - ax12a.setEndless(ID, OFF); - ax12a.move(ID, pos_initial); - delay(500); - break; - case 'T': // Propulsion on - digitalWrite(relai_IN1, HIGH); - digitalWrite(relai_IN2, LOW); - //delay(4000); - break; - case 'U': // Propulsion off - digitalWrite(relai_IN1, LOW); - digitalWrite(relai_IN2, HIGH); - //delay(4000); - break; - case 'P': // Ping - break; - default: - codeInconnu = true; + case 'L': // Ouverture loquet + servoLoquet.write(100); + delay(500); + break; + case 'F': // Fermeture loquet + servoLoquet.write(0); + delay(500); + break; + case 'A': // Position attente balle + servoPositionBalle.write(70); + delay(500); + break; + case 'V': // Position évacuation balle + servoPositionBalle.write(0); + delay(500); + break; + case 'J': // Position ejection balle + servoPositionBalle.write(180); + delay(500); + break; + case 'O': // Pousser balle + // Position basse + servoPoussoir.write(0); + delay(500); + // Position haute + servoPoussoir.write(120); + delay(1000); + break; + case 'B': // Tourner barillet d'un cran + barilletUnCran(); + delay(500); + break; + case 'H': // Tourner de deux crans + barilletDeuxCrans(); + delay(500); + break; + case 'R': // Reset barillet + // ax12a.setEndless(ID, OFF); + ax12a.setEndless(ID, ON); + ax12a.turn(ID, LEFT, 0); + ax12a.setEndless(ID, OFF); + ax12a.move(ID, pos_initial); + delay(500); + break; + case 'T': // Propulsion on + digitalWrite(relai_IN1, HIGH); + digitalWrite(relai_IN2, LOW); + //delay(4000); + break; + case 'U': // Propulsion off + digitalWrite(relai_IN1, LOW); + digitalWrite(relai_IN2, HIGH); + //delay(4000); + break; + case 'P': // Ping + break; + default: + codeInconnu = true; } if (codeInconnu) { diff --git a/chef/src/position.c b/chef/src/position.c index b551a15..9590e35 100644 --- a/chef/src/position.c +++ b/chef/src/position.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "debug.h" @@ -29,14 +30,20 @@ void onF2CI_CODER() pthread_mutex_unlock(&posPolling); } +struct timespec maxDelayDelta = { 0, 10000000 }; + void updateDelta() { - // Sending + int ret = -1; pthread_mutex_lock(&posPolling); - sendCF(F2CI_CODER, NULL, 0); - // Waiting for reception - pthread_mutex_lock(&posPolling); + while (ret != 0) { + // Sending + sendCF(F2CI_CODER, NULL, 0); + // Waiting for reception + ret = pthread_mutex_timedlock(&posPolling, &maxDelayDelta); + } + pthread_mutex_unlock(&posPolling); } diff --git a/chef/src/securite.c b/chef/src/securite.c index 2db5fa8..4b715c1 100644 --- a/chef/src/securite.c +++ b/chef/src/securite.c @@ -19,15 +19,22 @@ void onF2CI_CAPT() pthread_mutex_unlock(&secPolling); } +struct timespec maxDelaySecu = { 0, 10000000 }; + void* TaskSecurite(void* pData) { (void)pData; for (;;) { + + int ret = -1; pthread_mutex_lock(&secPolling); - sendCF(F2CI_CAPT, NULL, 0); - // Waiting for reception - pthread_mutex_lock(&secPolling); + while (ret != 0) { + // Sending + sendCF(F2CI_CAPT, NULL, 0); + // Waiting for reception + ret = pthread_mutex_timedlock(&secPolling, &maxDelaySecu); + } pthread_mutex_unlock(&secPolling); pthread_mutex_lock(&secData); @@ -54,8 +61,8 @@ void configureSecurite() pthread_mutex_init(&secPolling, NULL); pthread_mutex_init(&secData, NULL); registerRxHandlerCF(F2CI_CAPT, onF2CI_CAPT); - registerDebugVar("secFront", ld, &secFront); - registerDebugVar("secBack", ld, &secBack); + registerDebugVar("secFront", f, &secFront); + registerDebugVar("secBack", f, &secBack); pthread_create(&tSecurite, NULL, TaskSecurite, NULL); } @@ -63,4 +70,3 @@ void deconfigureSecurite() { pthread_cancel(tSecurite); } -