mirror of
https://github.com/RobotechLille/cdf2018-principal
synced 2024-11-24 00:56:04 +01:00
Peut ignorer si l'Arduino n'est pas connecté
This commit is contained in:
parent
f0778e621f
commit
de62a72457
|
@ -1,10 +1,14 @@
|
||||||
// Robotech Lille 2017-2018
|
// Robotech Lille 2017-2018
|
||||||
|
|
||||||
#include "actionneurs.h"
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "CA.h"
|
#include "CA.h"
|
||||||
|
#include "actionneurs.h"
|
||||||
|
|
||||||
pthread_mutex_t receptionActionMutex;
|
pthread_mutex_t receptionActionMutex;
|
||||||
pthread_cond_t receptionActionCond;
|
pthread_cond_t receptionActionCond;
|
||||||
|
bool actionneursConfigured = false;
|
||||||
|
|
||||||
// On fait un truc de malpropre : étant donné que l'Arduino
|
// On fait un truc de malpropre : étant donné que l'Arduino
|
||||||
// peut faire qu'une seule tache à la fois on suppose que le
|
// peut faire qu'une seule tache à la fois on suppose que le
|
||||||
|
@ -12,6 +16,8 @@ pthread_cond_t receptionActionCond;
|
||||||
|
|
||||||
void configureActionneurs()
|
void configureActionneurs()
|
||||||
{
|
{
|
||||||
|
actionneursConfigured = true;
|
||||||
|
configureCA();
|
||||||
pthread_mutex_init(&receptionActionMutex, NULL);
|
pthread_mutex_init(&receptionActionMutex, NULL);
|
||||||
pthread_cond_init(&receptionActionCond, NULL);
|
pthread_cond_init(&receptionActionCond, NULL);
|
||||||
resetActionneurs();
|
resetActionneurs();
|
||||||
|
@ -26,15 +32,15 @@ void setPositionBalle(enum positionBalle pos)
|
||||||
{
|
{
|
||||||
unsigned char code;
|
unsigned char code;
|
||||||
switch (pos) {
|
switch (pos) {
|
||||||
case attente:
|
case attente:
|
||||||
code = C2AD_POS_BALLE_ATTENTE;
|
code = C2AD_POS_BALLE_ATTENTE;
|
||||||
break;
|
break;
|
||||||
case ejection:
|
case ejection:
|
||||||
code = C2AD_POS_BALLE_EJECTION;
|
code = C2AD_POS_BALLE_EJECTION;
|
||||||
break;
|
break;
|
||||||
case evacuation:
|
case evacuation:
|
||||||
code = C2AD_POS_BALLE_EVACUATION;
|
code = C2AD_POS_BALLE_EVACUATION;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
attendAction(code);
|
attendAction(code);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +70,6 @@ void setPropulsion(bool state)
|
||||||
attendAction(state ? C2AD_PROPULSION_ON : C2AD_PROPULSION_OFF);
|
attendAction(state ? C2AD_PROPULSION_ON : C2AD_PROPULSION_OFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void resetActionneurs()
|
void resetActionneurs()
|
||||||
{
|
{
|
||||||
setLoquet(false);
|
setLoquet(false);
|
||||||
|
@ -87,14 +92,22 @@ void receptionAction()
|
||||||
|
|
||||||
void attendAction(unsigned char code)
|
void attendAction(unsigned char code)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&receptionActionMutex);
|
if (actionneursConfigured) {
|
||||||
registerRxHandlerCA(code, receptionAction);
|
pthread_mutex_lock(&receptionActionMutex);
|
||||||
sendCA(code, NULL, 0);
|
registerRxHandlerCA(code, receptionAction);
|
||||||
pthread_cond_wait(&receptionActionCond, &receptionActionMutex);
|
sendCA(code, NULL, 0);
|
||||||
pthread_mutex_unlock(&receptionActionMutex);
|
pthread_cond_wait(&receptionActionCond, &receptionActionMutex);
|
||||||
|
pthread_mutex_unlock(&receptionActionMutex);
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "Action demandée sans Arduino configuré\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deconfigureActionneurs()
|
void deconfigureActionneurs()
|
||||||
{
|
{
|
||||||
stopActionneurs();
|
if (actionneursConfigured) {
|
||||||
|
stopActionneurs();
|
||||||
|
deconfigureCA();
|
||||||
|
actionneursConfigured = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue