From d9798f1ff010e20dae10191f7bf1c6019fb35303 Mon Sep 17 00:00:00 2001 From: pfaure Date: Mon, 19 Oct 2020 10:32:15 +0200 Subject: [PATCH] =?UTF-8?q?Mise=20en=20place=20allure.h,=20impl=C3=A9menta?= =?UTF-8?q?tion=20de=20la=20fonction=20toString,=20cr=C3=A9ation=20d'une?= =?UTF-8?q?=20lib=20maths.=20impl=C3=A9mentation=20d'une=20fonction=20abs?= =?UTF-8?q?=20dans=20cette=20lib=20(valeur=20absolue)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MDK-ARM/Project.uvoptx | 64 +++++++++++++++++++++++++++++++++++------ MDK-ARM/Project.uvprojx | 40 ++++++++++++++++++++++++++ Src/Allure.c | 32 +++++++++++++++++++++ Src/Allure.h | 39 +++++++++++++++++++++++++ Src/Voilier.c | 2 +- Src/maths.c | 8 ++++++ Src/maths.h | 11 +++++++ 7 files changed, 187 insertions(+), 9 deletions(-) create mode 100644 Src/maths.c create mode 100644 Src/maths.h diff --git a/MDK-ARM/Project.uvoptx b/MDK-ARM/Project.uvoptx index 9d9a90f..e958edb 100644 --- a/MDK-ARM/Project.uvoptx +++ b/MDK-ARM/Project.uvoptx @@ -549,19 +549,67 @@ 0 0 + + 2 + 10 + 5 + 0 + 0 + 0 + ..\Src\Allure.h + Allure.h + 0 + 0 + + + 2 + 11 + 5 + 0 + 0 + 0 + ..\MyDrivers\MyTimer.h + MyTimer.h + 0 + 0 + + + 2 + 12 + 5 + 0 + 0 + 0 + ..\Src\maths.h + maths.h + 0 + 0 + + + 2 + 13 + 1 + 0 + 0 + 0 + ..\Src\maths.c + maths.c + 0 + 0 + Drivers/STM32f1xx_LL_Driver - 1 + 0 0 0 0 3 - 10 + 14 1 - 0 + 1 0 0 ..\LLDrivers\src\stm32f1xx_ll_rcc.c @@ -571,7 +619,7 @@ 3 - 11 + 15 1 0 0 @@ -593,13 +641,13 @@ Drivers/CMSIS - 1 + 0 0 0 0 5 - 12 + 16 1 0 0 @@ -613,13 +661,13 @@ Example/MDK-ARM - 1 + 0 0 0 0 6 - 13 + 17 2 0 0 diff --git a/MDK-ARM/Project.uvprojx b/MDK-ARM/Project.uvprojx index d5a288a..7c73e5a 100644 --- a/MDK-ARM/Project.uvprojx +++ b/MDK-ARM/Project.uvprojx @@ -432,6 +432,26 @@ 1 ..\Src\Voile.c + + Allure.h + 5 + ..\Src\Allure.h + + + MyTimer.h + 5 + ..\MyDrivers\MyTimer.h + + + maths.h + 5 + ..\Src\maths.h + + + maths.c + 1 + ..\Src\maths.c + @@ -903,6 +923,26 @@ 1 ..\Src\Voile.c + + Allure.h + 5 + ..\Src\Allure.h + + + MyTimer.h + 5 + ..\MyDrivers\MyTimer.h + + + maths.h + 5 + ..\Src\maths.h + + + maths.c + 1 + ..\Src\maths.c + diff --git a/Src/Allure.c b/Src/Allure.c index e69de29..7dc2ced 100644 --- a/Src/Allure.c +++ b/Src/Allure.c @@ -0,0 +1,32 @@ +#include "maths.h" + +void ConfAllure() { + +} + +int RecupAllure() { + return 0; +} + +char * ToString(int alpha) { + int alpha_abs = abs(alpha); + if (alpha_abs < 45) { + return "Vent debout"; + } else if (alpha < 55) { + return "Près"; + } else if (alpha < 65) { + return "Bon plein"; + } else if (alpha < 80) { + return "Petit largue"; + } else if (alpha < 100) { + return "Travers"; + } else if (alpha < 115) { + return "Largue"; + } else if (alpha < 155) { + return "Grand largue"; + } else if (alpha < 180) { + return "Vent arrière"; + } else { + return "ERROR"; + } +} diff --git a/Src/Allure.h b/Src/Allure.h index e69de29..ec3e31f 100644 --- a/Src/Allure.h +++ b/Src/Allure.h @@ -0,0 +1,39 @@ +#ifndef ALLURE_H +#define ALLURE_H + +/** + * @brief Configure la girouette pour la détection de l'allure (sens du vent). + * @note Configuration des ports PA6 et 7 en alternate input pour récupérer les signaux + Configuration des deux channels du TIM3 pour le compteur incrementeur + Configuration du PA5 avec une interruption pour capter les tours de girouette + * @param None + * @retval None + */ +void ConfAllure(); + +/** + * @brief Renvoi la valeur de l'allure actuelle + * @note Représentation de la donnée en degrès -> int entre -180 et 180 + * @param None + * @retval L'allure, représenté en degrès par un entier entre -180 et 180 + */ +int RecupAllure(); + +/** + * @brief Associe un chaine de caractère a une valeur d'allure. + * @note Une chaine de caractère est associé a des intervalles de alpha : + [-45, 45] -> "Vent debout" + [45, 55] -> "Près" (et intervalle opposé) + [55, 65] -> "Bon plein" (et intervalle opposé) + [65, 80] -> "Petit largue" (et intervalle opposé) + [80, 100] -> "Travers" (et intervalle opposé) + [100, 115] -> "Largue" (et intervalle opposé) + [115, 155] -> "Grand largue" (et intervalle opposé) + [155, -155] -> "Vent arrière" + Autre -> "ERROR" + * @param alpha : un entier représentant l'allure en ° (-180 à 180) + * @retval Une chaine de caractère représentant l'allure + */ +char * ToString(int alpha); + +#endif diff --git a/Src/Voilier.c b/Src/Voilier.c index 43f7119..ade4548 100644 --- a/Src/Voilier.c +++ b/Src/Voilier.c @@ -1,3 +1,3 @@ int main(){ return 0; -} \ No newline at end of file +} diff --git a/Src/maths.c b/Src/maths.c new file mode 100644 index 0000000..a2d860d --- /dev/null +++ b/Src/maths.c @@ -0,0 +1,8 @@ + +int abs(int a) { + if (a<0) { + return -a; + } else { + return a; + } +} diff --git a/Src/maths.h b/Src/maths.h new file mode 100644 index 0000000..d6d7b78 --- /dev/null +++ b/Src/maths.h @@ -0,0 +1,11 @@ +#ifndef MATHS_H +#define MATHS_H + +/** + * @brief Valeur absolue. + * @note Si a < 0 renvoi -a, sinon, a + * @param a : un entier + * @retval La valeur absolue de a + */ +int abs(int a); +#endif