Ce programme correspond a la cellule de depart du systeme "Laser Gate Timer" developpe par Tanguy KESSELY et Dorian VOYDIE. Il utilise une carte Nucleo F411, un shield BLE IDB05A1 et un PCB fait maison
Dependencies: mbed X_NUCLEO_IDB0XA1 BLE_API
Revision 15:040b2ce981f0, committed 2021-02-04
- Comitter:
- dorianvoydie
- Date:
- Thu Feb 04 16:04:14 2021 +0000
- Parent:
- 14:ac6cbe6ffaab
- Commit message:
- Ce programme correspond a la cellule de depart du systeme "Laser Gate Timer" developpe par Tanguy KESSELY et Dorian VOYDIE. Il utilise une carte Nucleo F411, un shield BLE IDB05A1 et un PCB fait maison
Changed in this revision
X_NUCLEO_IDB0XA1.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r ac6cbe6ffaab -r 040b2ce981f0 X_NUCLEO_IDB0XA1.lib --- a/X_NUCLEO_IDB0XA1.lib Tue Nov 17 17:18:52 2020 +0000 +++ b/X_NUCLEO_IDB0XA1.lib Thu Feb 04 16:04:14 2021 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/teams/ENSMM/code/X_NUCLEO_IDB0XA1/#8886c0252544 +https://os.mbed.com/teams/ENSMM/code/X_NUCLEO_IDB0XA1/#b173b83b9e64
diff -r ac6cbe6ffaab -r 040b2ce981f0 main.cpp --- a/main.cpp Tue Nov 17 17:18:52 2020 +0000 +++ b/main.cpp Thu Feb 04 16:04:14 2021 +0000 @@ -7,66 +7,115 @@ #define UART_BUFFER (UARTService::BLE_UART_SERVICE_MAX_DATA_LEN) -const static char DEVICE_NAME[] = "OBCP"; +const static char DEVICE_NAME[] = "ObCP"; UARTService *uartServicePtr; -//PWM output -PwmOut Green(PC_8); //PWM Red LED -PwmOut Red(PC_6); //PWM Red LED -PwmOut Blue(PC_9); //PWM Red LED +///////////Périphériques///////////////// +InterruptIn myButton(USER_BUTTON); +InterruptIn photodiode(A2); +DigitalOut myled(LED1); +DigitalOut laser(A3); +DigitalIn photodiode1(A2); +DigitalOut compteur(A4); +float photodiode2 = 0; -// Def Peripheriques -InterruptIn myButton(PC_13); // USER BUTTON +///////////Init devices////////////////// +Serial device(D8, D2); +Serial pc(USBTX, USBRX); -///////////Init HC05///////////////// -Serial HC05(D8, D2); -//Bluetooth -//Maitre (Arrivee) : ADDR = 98d3,b1,fd5c5d -//Esclave (Départ) : ADDR = 0019,10,08FCB5 -///////////////////////////////////// -//Ticker t; -////////////TIMER//////////////////// -Timer timer; -int begin; -int end; -float chrono=0; -void Timer_triggered() -{ - timer.start(); - begin = timer.read_ms(); - Blue=1; - wait(0.5); - Blue=0; -} +//////////Initialisations//////////////// +Timer timer_player_1; +Timer timer_player_2; +int begin1; +int begin2; +int end1; +int end2; +float chrono1; +float chrono2; +char temp=0; +char temp2=0; +char temp3=0; +char gamemode = 'M'; + void Timer_Reset() { - timer.stop(); - begin=0; - end=0; - chrono=0; + timer_player_1.stop(); + timer_player_2.stop(); + timer_player_1.reset(); + timer_player_2.reset(); + begin1=0; + begin2=0; + end1=0; + end2=0; + chrono1=0; + chrono2=0; +} + +void photodiode_triggered() +{ + if (gamemode == 'S') { + compteur = 1; + wait(0.001); + compteur = 0; + Timer_Reset(); + timer_player_1.start(); + begin1 = timer_player_1.read_ms(); + myled=1; + wait(0.5); + myled=0; + + } + if (gamemode == 'D') { + wait(0.001); + compteur = 0; + end2 = timer_player_2.read_ms(); + timer_player_2.stop(); + chrono2 = end2-begin2; + } + if (gamemode == 'L') { + wait(0.001); + compteur = 0; + timer_player_1.start(); + chrono1 = timer_player_1.read_ms(); + myled=1; + wait(0.5); + myled=0; + } } ///////////////////////////////////// /////////COMMUNICATION/////////////// -void HC05_receive() +void device_receive() { - char IncomingValue = HC05.getc(); - if(IncomingValue == 'u') { - end = timer.read_ms(); - timer.stop(); - chrono = end-begin; + temp=device.getc(); + //Ignore Sync pattern and do not pass on to PC + if (temp!=0xAA) { + //Mode solo, la cellule arrivée envoie u à la cellule départ + if(temp == 0xBB and temp2!=0xBB) { + temp2=0xBB; + } + if(temp == 0xBC and temp2==0xBB) { + temp3 = 0xBC; + } + if(temp == 0xBD and temp3==0xBC) { + end1 = timer_player_1.read_ms(); + timer_player_1.stop(); + chrono1 = end1-begin1-0.02; + photodiode2 = 0; + pc.printf("C'est bon"); + } + if(temp == 0xCC) { + photodiode2 = 1; + } + pc.putc(temp); + } - } + } ///////////////////////////////////// - - - - - // Tableau et index de communication avec UART static char uartBuff[UART_BUFFER]; // Routine de traitement des erreurs @@ -75,20 +124,46 @@ /****************************************************/ /* Ticker actif lorsque la connexion BLE est présente */ /****************************************************/ +void ConnectedBLE(void) +{ + // Signal de vie: allumer et éteindre la LED + +} void update(void) { - char train[5]; - float chrono_value = float(chrono)* 0.001F; + + if (gamemode != 'A') { + char train1[5]; + char train2[5]; + float chrono_value_J1 = float(chrono1)* 0.001F; + float chrono_value_J2 = float(chrono2)* 0.001F; - //Transformation des valeurs numeriques en chaine de caracteres - sprintf(train,"%5.2f",chrono_value); - //Integre les trois chaines de caractere contenant les ts dans la chaine uartBuff - sprintf(uartBuff, "%s", train) ; - //Envoie la chaine uartBuff sur le sevice TX UART BLE - uartServicePtr->write(uartBuff, UARTService::BLE_UART_SERVICE_MAX_DATA_LEN); - // Réinitialiser la chaîne uartBuff en entrant 0 dans les premiers caractères UART_BUFFER - memset(uartBuff, 0, UART_BUFFER); + //Transformation des valeurs numeriques en chaine de caracteres + sprintf(train1,"%5.2f",chrono_value_J1); + sprintf(train2,"%5.2f",chrono_value_J2); + //Integre les trois chaines de caractere contenant les ts dans la chaine uartBuff + sprintf(uartBuff, "%s %s", train1, train2) ; + //Envoie la chaine uartBuff sur le sevice TX UART BLE + uartServicePtr->write(uartBuff, UARTService::BLE_UART_SERVICE_MAX_DATA_LEN); + // Réinitialiser la chaîne uartBuff en entrant 0 dans les premiers caractères UART_BUFFER + memset(uartBuff, 0, UART_BUFFER); + } else { + char laser1[1]; + char laser2[1]; + + //Transformation des valeurs numeriques en chaine de caracteres + float meas = photodiode1.read(); + sprintf(laser1,"%1.0f",meas); + sprintf(laser2,"%1.0f",photodiode2); + //Integre les trois chaines de caractere contenant les ts dans la chaine uartBuff + sprintf(uartBuff, "%s %s", laser1, laser2) ; + //Envoie la chaine uartBuff sur le sevice TX UART BLE + uartServicePtr->write(uartBuff, UARTService::BLE_UART_SERVICE_MAX_DATA_LEN); + // Réinitialiser la chaîne uartBuff en entrant 0 dans les premiers caractères UART_BUFFER + memset(uartBuff, 0, UART_BUFFER); + } + } @@ -97,8 +172,8 @@ /*************************/ void BleConnectionCallback(const Gap::ConnectionCallbackParams_t *params) { - Timer_Reset(); - update(); + // Signal de connexion BLE: allume / éteint la LED avec une période de 1 seconde + ConnectedBLE(); } /*****************************/ @@ -109,46 +184,72 @@ (void)params; // Redémarrer la publicité Timer_Reset(); - update(); - BLE::Instance().gap().startAdvertising(); - - Blue.write(0.0f); - Green.write(0.0f); - Red.write(0.0f); + + } /***************************/ /* Rx de BLE et Rx vers USB*/ /***************************/ - void BleOnDataWrittenCallback(const GattWriteCallbackParams *params) { char reception[UART_BUFFER]; char commande[3]; - - // Reçoit une chaîne de BLE if (params->handle == uartServicePtr->getTXCharacteristicHandle()) { // Copie de la chaine reçue dans reception sprintf(reception,"%s", params->data); // Copie dans la chaine commande des deux premier caracteres de la chaine reception sprintf(commande,"%c%c%c", reception[0], reception[1], reception[2]); - if( strcmp(commande, "RST" )==0 or strcmp(commande, "rst" )==0 ) { + + if( strcmp(commande, "RST" )==0 ) { Timer_Reset(); update(); } + if( strcmp(commande, "SOL" )==0 ) { + gamemode = 'S'; + laser=1; + update(); + } + if( strcmp(commande, "DUO" )==0 ) { + gamemode = 'D'; + laser=1; + update(); + } + if( strcmp(commande, "LAP" )==0 ) { + gamemode = 'L'; + laser=1; + update(); + } + if( strcmp(commande, "MEN" )==0 ) { + gamemode = 'M'; + laser=0; + update(); + } + if( strcmp(commande, "LAS" )==0 ) { + gamemode = 'A'; + laser=1; + update(); + } + if( strcmp(commande, "BIP" )==0 ) { + Timer_Reset(); + timer_player_1.start(); + timer_player_2.start(); + begin1 = timer_player_1.read_ms(); + begin1 = timer_player_2.read_ms(); + myled=1; + wait(0.5); + myled=0; + } } } - /***************************/ /* Erreur sur le canal BLE */ /***************************/ void onBleError(ble_error_t error) { - Red.period(0.8f); // période = 0.8 seconde - Red.write(0.10f); // élaire 10% de la période /* Entrer le traitement des erreurs */ } @@ -191,11 +292,11 @@ // Attend les événements sur BLE while (true) { + ble.waitForEvent(); update(); - while(HC05.readable()) { - HC05_receive(); - } + //RF Receive Code + device_receive(); wait(0.01); } } @@ -205,13 +306,10 @@ /********/ int main(void) { - HC05.baud(38400); - myButton.fall(&Timer_triggered); - - // Initialiser LED - Green.write(0.0f); - Red.write(0.0f); - Blue.write(0.0f); + device.baud(2400); + myButton.fall(&photodiode_triggered); + photodiode.fall(&photodiode_triggered); + /****** START Initialiser BLE **********/ BLE &ble = BLE::Instance();