chti23_grpC_Aittaleb_Barnavon/PjtKEIL_Final/Src/principal.c

211 lines
4.3 KiB
C
Raw Blame History

#include "DriverJeuLaser.h"
#include "stdio.h"
#include "Affichage_Valise.h"
# define PERIODE4 6552
# define PERIODE_PWM 720
# define F1 17
# define F2 18
# define F3 19
# define F4 20
# define F5 23
# define F6 24
# define NBJOUEURS 4
extern int DFT_ModuleAuCarre(short int* , char);
extern int DFT_reel(short int* , char);
extern int DFT_imag(short int* , char);
extern void CallbackSon(void);
extern short int TabCos[];
extern short int TabSin[];
extern short int SortieSon;
int resultat_module_carre [64];
short int dma_buf [64];
int score [NBJOUEURS];
int vrai_score [NBJOUEURS];
int bouclage=0;
int dft;
int frequences[]={F1,F2,F3,F4};
int nombre_tirs = 0;
int numero_capteur=1;
int Leds[]= {LED_Cible_1,LED_Cible_2,LED_Cible_3,LED_Cible_4};
//void DFT_ModuleAuCarre( short int * Signal64ech, char k, long int * resultat){
// int acumReel = 0;
// int acumImag = 0;
// for (int i= 0; i< 64; i++){
// acumReel += Signal64ech[i]*TabCos[(i*k)%64];
// acumImag += Signal64ech[i]*TabSin[(i*k)%64];
// }
// *resultat = acumReel*acumReel + acumImag*acumImag;
//}
void callback_SysTick(){
Start_DMA1(64);
Wait_On_End_Of_DMA1();
Stop_DMA1;
}
//void changerCapteur(){
// Choix_Capteur(numero_capteur);
//
//
// Prepare_Clear_LED(Leds[(numero_capteur)%4]);
// Prepare_Clear_LED(Leds[(numero_capteur+1)%4]);
// Prepare_Clear_LED(Leds[(numero_capteur+2)%4]);
//
// Prepare_Set_LED(Leds[numero_capteur-1]);
//
// numero_capteur=(numero_capteur+1)%4 + 1 ;
//
//}
void changerCapteur(int i){
Choix_Capteur(i+1);
//
// Prepare_Clear_LED(Leds[(i)%4]);
// Prepare_Clear_LED(Leds[(i+1)%4]);
// Prepare_Clear_LED(Leds[(i+2)%4]);
Prepare_Clear_LED(Leds[0]);
Prepare_Clear_LED(Leds[1]);
Prepare_Clear_LED(Leds[2]);
Prepare_Clear_LED(Leds[3]);
Prepare_Set_LED(Leds[i]);
}
int main(void)
{
// ===========================================================================
// ============= INIT PERIPH (faites qu'une seule fois) =====================
// ===========================================================================
// Apr<70>s ex<65>cution : le coeur CPU est clock<63> <20> 72MHz ainsi que tous les timers
CLOCK_Configure();
// ------------------------ Config DFT ------------------------------
// Config Timer (Interruptions toutes les 5ms)
int periode_ticks = 360000; // pour avoir une interruption toutes les 5ms
char prio = 0; // Eventuellement <20> changer quand fusion avec le son
Systick_Period_ff(periode_ticks);
Systick_Prio_IT(prio, callback_SysTick);
SysTick_On;
SysTick_Enable_IT;
// Config ADC (mesure pendant 200 <20>s)
Init_TimingADC_ActiveADC_ff(ADC1, 72);
Single_Channel_ADC(ADC1, 2);
Init_Conversion_On_Trig_Timer_ff(ADC1, TIM2_CC2, 225);
Init_ADC1_DMA1(0, dma_buf);
// ------------------------ Config Son ------------------------------
Timer_1234_Init_ff(TIM4,PERIODE4);
Active_IT_Debordement_Timer(TIM4, 2, CallbackSon);
//Timer 1 d<>ja utilis<69> pour MAJ affichage (prio 8)
//Timer_1234_Init_ff(TIM3,PERIODE_PWM);
PWM_Init_ff( TIM3, 3, 720);
GPIO_Configure(GPIOB, 0, OUTPUT, ALT_PPULL);
// ----------------------- Config Affichage --------------------------
Init_Affichage();
for (int i = 1; i<5; i++){
Prepare_Afficheur(i, 0);
//Prepare_Set_LED(Leds[i-1]);
}
//Choix_Capteur(2);
//Choix_Capteur(1);
Mise_A_Jour_Afficheurs_LED();
// ----------------------- Config capteur ---------------------------
// -----------------------------------------------------------------
for(int i = 0; i < NBJOUEURS ; i ++){
score[i] = 0;
vrai_score[i] = 0;
}
// test son :
while (1)
{
// capteur = capteur + 1 % 4;
// Choix_Capteur((int)capteur+1);
for (int i = 0; i<4; i++){
resultat_module_carre[frequences[i]] = DFT_ModuleAuCarre(dma_buf,frequences[i]);
if (resultat_module_carre[frequences[i]]>5000000){
score[i]++;
}
if (resultat_module_carre[frequences[i]]<30000){
score[i]=0;
}
}
for (int i = 0; i<4; i++){
if (score[i]>90) {
vrai_score[i]++;
Prepare_Afficheur(i+1, vrai_score[i]);
//CallbackSon();
//PWM_Set_Value_TIM3_Ch3(SortieSon);
score[i]=0;
score[(i+1)%4]=0;
score[(i+2)%4]=0;
score[(i+3)%4]=0;
changerCapteur(numero_capteur);
numero_capteur = (numero_capteur + 1) % 4;
}
}
Mise_A_Jour_Afficheurs_LED();
}
}