#include "DriverJeuLaser.h" #include "GestionSon.h" #include "Affichage_Valise.h" extern int DFT_ModuleAuCarre(short int* Signal64ech, char k); extern int16_t LeSignal; #define seuil_activation 350000 unsigned int test = 0; short int dma_buf[64]; int coeff[7]; int score[6]; int attendre[6]; int changed[6]; int curr_cible = 0; void mesure() { Start_DMA1(64); Wait_On_End_Of_DMA1(); Stop_DMA1; coeff[0] = DFT_ModuleAuCarre(&(dma_buf[0]), 17); coeff[1] = DFT_ModuleAuCarre(&(dma_buf[0]), 18); coeff[2] = DFT_ModuleAuCarre(&(dma_buf[0]), 19); coeff[3] = DFT_ModuleAuCarre(&(dma_buf[0]), 20); //coeff[4] = DFT_ModuleAuCarre(&(dma_buf[0]), 23); //coeff[5] = DFT_ModuleAuCarre(&(dma_buf[0]), 24); coeff[6] = DFT_ModuleAuCarre(&(dma_buf[0]), 21); if (coeff[6] < seuil_activation) for (int i = 0; i < 4; i++) { if (attendre[i] == 0 && coeff[i] > seuil_activation) { StartSon(); score[i] = (score[i] + 1) % 100; Prepare_Afficheur(i+1, score[i]); attendre[i] = 1; } else if (attendre[i] == 1 && coeff[i] < seuil_activation) attendre[i] = 0; } } void update_cibles(int oups) { if (oups == 13) { for (int i = 0; i < 4; i++) { if (i == curr_cible) { Choix_Capteur(curr_cible + 1); Prepare_Set_LED(curr_cible); } else Prepare_Clear_LED(i); } curr_cible = (curr_cible + 1) & 3; } Mise_A_Jour_Afficheurs_LED(); } int main(void) { // =========================================================================== // ============= INIT PERIPH (faites qu'une seule fois) ===================== // =========================================================================== // Après exécution : le coeur CPU est clocké à 72MHz ainsi que tous les timers CLOCK_Configure(); //init systeme ADC/DMA 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); //systick pour les mesures Systick_Period_ff(72000000 * 5 / 1000); Systick_Prio_IT(0, mesure); SysTick_On; SysTick_Enable_IT; //timer pour le son GPIO_Configure(GPIOB, 0, OUTPUT, ALT_PPULL); PWM_Init_ff(TIM3, 3, 720); // f_PWM = 72MHz/720 = 100kHz Timer_1234_Init_ff(TIM4, 6552); // periode_son/f_CPU = (91*10^-6)*(72*10^6) = 6552 Active_IT_Debordement_Timer(TIM4, 2, CallbackSon); //init affichage malette Init_Affichage(); //init tableau score for (int i = 0; i < 6; i++) { score[i] = 0; attendre[i] = 0; } //============================================================================ int oups = 0; while (1) { oups = (oups + 1) % 2500; update_cibles(oups); } }