151 lines
3.3 KiB
C
151 lines
3.3 KiB
C
#include "MyRF.h"
|
|
#include "MyTimer.h"
|
|
#include "MyPWM.h"
|
|
#include "MyUSART.h"
|
|
|
|
#include "stm32f1xx_ll_tim.h"
|
|
#include "stm32f1xx_ll_gpio.h"
|
|
#include "stm32f1xx_ll_usart.h"
|
|
|
|
|
|
void MyRF_Conf(void) {
|
|
|
|
//RX
|
|
//Configuration et lancement du Timer PWM Input
|
|
MyTimer_Conf(TimerCC,0xFFAD,0x15);
|
|
MyPWM_Conf_Input(TimerCC, channelCC1, channelCC2);
|
|
MyTimer_Start(TimerCC);
|
|
|
|
//TX
|
|
//Configuration de l'USART
|
|
MyUSART_Conf(USARTOut, TransferDirTX);
|
|
|
|
}
|
|
|
|
|
|
int MyRF_Input_Duty_Cycle(void) {
|
|
int duty_cycle_RC = MyPWM_Duty_Cycle_Permilles(TimerCC, channelCC1, channelCC2);
|
|
//Seuil de +-10% autour de la valeur centrale
|
|
if (74<duty_cycle_RC && duty_cycle_RC<77) {
|
|
return 0;
|
|
}
|
|
else {
|
|
//Conversion : 50 à 100 => -100 à 100
|
|
return (duty_cycle_RC - 75) * 4;
|
|
}
|
|
}
|
|
|
|
void MyRF_Transmit_3s(int bordage_pc, int angle_vent) {
|
|
|
|
//Conversion bordage int => chaîne de char
|
|
char bordage[3] = {bordage_pc/100+48,(bordage_pc%100-bordage_pc%10)/10+48,bordage_pc%100+48};
|
|
|
|
//Conversion angle du vent int => dénomination de l'allure
|
|
int allure_ref;
|
|
if(angle_vent <45) {
|
|
allure_ref = 0;
|
|
}
|
|
else if (angle_vent == 45) {
|
|
allure_ref = 1;
|
|
}
|
|
else if (angle_vent < 60) {
|
|
allure_ref = 2;
|
|
}
|
|
else if (angle_vent < 90) {
|
|
allure_ref = 3;
|
|
}
|
|
else if (angle_vent < 120) {
|
|
allure_ref = 4;
|
|
}
|
|
else if (angle_vent < 160) {
|
|
allure_ref = 5;
|
|
}
|
|
else {
|
|
allure_ref = 6;
|
|
}
|
|
char allure[7][16]= {"vent debout.",
|
|
"au plus près.",
|
|
"au près.",
|
|
"au bon plein.",
|
|
"au travers.",
|
|
"au grand largue.",
|
|
"au vent arrière."
|
|
};
|
|
|
|
char heure[2] = "xx";
|
|
char min[2] = "xx";
|
|
char sec[2] = "xx";
|
|
|
|
char data1[14] = "\" - Bordage : ";
|
|
char data2[24] = " === Le voilier navigue ";
|
|
|
|
int i;
|
|
|
|
//Activation de l'émetteur RF
|
|
LL_GPIO_SetOutputPin(GPIOOut ,PinTXEn);
|
|
|
|
//Heure
|
|
MyUSART_Transmit_Data_8b(USARTOut, heure[0]);
|
|
MyUSART_Transmit_Data_8b(USARTOut, heure[1]);
|
|
MyUSART_Transmit_Data_8b(USARTOut, 'h');
|
|
//Minutes
|
|
MyUSART_Transmit_Data_8b(USARTOut, min[0]);
|
|
MyUSART_Transmit_Data_8b(USARTOut, min[1]);
|
|
MyUSART_Transmit_Data_8b(USARTOut, '\'');
|
|
//Secondes
|
|
MyUSART_Transmit_Data_8b(USARTOut, sec[0]);
|
|
MyUSART_Transmit_Data_8b(USARTOut, sec[1]);
|
|
//Texte 1 (bordage)
|
|
for(i=0; i<14; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, data1[i]);
|
|
}
|
|
//Bordage
|
|
for(i=0; i<3; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, bordage[i]);
|
|
}
|
|
MyUSART_Transmit_Data_8b(USARTOut, '%');
|
|
//Texte 2 (allure)
|
|
for(i=0; i<24; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, data2[i]);
|
|
}
|
|
//Allure
|
|
for(i=0; i<16; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, allure[allure_ref][i]);
|
|
}
|
|
//Newline (fin)
|
|
MyUSART_Transmit_Data_8b(USARTOut, '\n');
|
|
|
|
//Désactivation de l'émetteur RF
|
|
LL_GPIO_ResetOutputPin(GPIOOut ,PinTXEn);
|
|
|
|
}
|
|
|
|
void MyRF_Transmit_Batterie_Faible(void) {
|
|
|
|
//Activation de l'émetteur RF
|
|
LL_GPIO_SetOutputPin(GPIOOut ,PinTXEn);
|
|
|
|
char data[24] = "/!\\ BATTERIE FAIBLE /!\\\n";
|
|
for(int i = 0; i<24; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, data[i]);
|
|
}
|
|
|
|
//Désactivation de l'émetteur RF
|
|
LL_GPIO_ResetOutputPin(GPIOOut ,PinTXEn);
|
|
|
|
}
|
|
|
|
void MyRF_Transmit_Limite_Roulis(void) {
|
|
|
|
//Activation de l'émetteur RF
|
|
LL_GPIO_SetOutputPin(GPIOOut ,PinTXEn);
|
|
|
|
char data[30] = "/!\\ RISQUE DE CHAVIREMENT /!\\\n";
|
|
for(int i = 0; i<30; i++) {
|
|
MyUSART_Transmit_Data_8b(USARTOut, data[i]);
|
|
}
|
|
|
|
//Désactivation de l'émetteur RF
|
|
LL_GPIO_ResetOutputPin(GPIOOut ,PinTXEn);
|
|
|
|
}
|