diff --git a/chef/Makefile b/chef/Makefile index 042796f..1563198 100644 --- a/chef/Makefile +++ b/chef/Makefile @@ -11,7 +11,7 @@ CFLAGS_CUSTOM += -g ## Générateurs de drapeaux pour les bibliothèques PKG_CONFIG=pkg-config ## Nom des objets communs -OBJS=actionneurs buttons CA CF debug diagnostics i2c imu ihm lcd motor movement parcours points position +OBJS=actionneurs buttons CA CF debug diagnostics i2c imu ihm lcd motor movement parcours points position securite OBJS_O=$(addprefix obj/,$(addsuffix .o,$(OBJS))) # VARIABLES AUTOMATIQUES diff --git a/chef/src/securite.c b/chef/src/securite.c new file mode 100644 index 0000000..09d174e --- /dev/null +++ b/chef/src/securite.c @@ -0,0 +1,66 @@ +#include +#include +#include +#include + +#include "debug.h" +#include "securite.h" + +// Globales +pthread_t tSecurite; +pthread_mutex_t secPolling; +pthread_mutex_t secData; +struct F2CI_CAPTs secRaw; +float secFront, secBack; + +void onF2CI_CAPT() +{ + readCF(&secRaw, sizeof(struct F2CI_CAPTs)); + pthread_mutex_unlock(&secPolling); +} + +void* TaskSecurite(void* pData) +{ + (void)pData; + + for (;;) { + pthread_mutex_lock(&secPolling); + sendCF(F2CI_CAPT, NULL, 0); + // Waiting for reception + pthread_mutex_lock(&secPolling); + pthread_mutex_unlock(&secPolling); + + pthread_mutex_lock(&secData); + secFront = (float)secRaw.front * SOUND_MM_P_MS; + secBack = (float)secRaw.back * SOUND_MM_P_MS; + pthread_mutex_unlock(&secData); + + usleep(SENSOR_SAMPLING_INTERVAL * 1000); + } + + return NULL; +} + +void getDistance(float* front, float* back) +{ + pthread_mutex_lock(&secData); + *front = secFront; + *back = secBack; + pthread_mutex_unlock(&secData); +} + +void configureSecurite() +{ + pthread_mutex_init(&secPolling, NULL); + pthread_mutex_init(&secData, NULL); + registerRxHandlerCF(F2CI_CODER, onF2CI_CAPT); + registerDebugVar("secFront", ld, &secFront); + registerDebugVar("secBack", ld, &secBack); + pthread_create(&tSecurite, NULL, TaskSecurite, NULL); +} + +void deconfigureSecurite() +{ + pthread_cancel(tSecurite); +} + diff --git a/chef/src/securite.h b/chef/src/securite.h new file mode 100644 index 0000000..11b51a7 --- /dev/null +++ b/chef/src/securite.h @@ -0,0 +1,16 @@ +#ifndef __SECURITE_H_ +#define __SECURITE_H_ + +#include "CF.h" +#include + +#define SOUND_MM_P_MS 0.3312 +#define SENSOR_SAMPLING_INTERVAL 60 + +// Fonctions +void configureSecurite(); +void deconfigureSecurite(); +void getDistance(float* avant, float* arriere); + +#endif + diff --git a/chef/src/testSecu.c b/chef/src/testSecu.c new file mode 100644 index 0000000..afbb587 --- /dev/null +++ b/chef/src/testSecu.c @@ -0,0 +1,24 @@ +#include +#include +#include + +#include "CF.h" +#include "securite.h" + +int main(int argc, char* argv[]) +{ + + (void)argc; + (void)argv; + + configureCF(); + configureSecurite(); + + float f, b; + + for (;;) { + getDistance(&f, &b); + printf("Av: %6f Ar: %6f\n", f, b); + sleep(1); + } +}