Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: bluetoothV2bibli.cpp
- Revision:
- 0:9e8a54e32f30
- Child:
- 1:13af94a28e0d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bluetoothV2bibli.cpp Thu Feb 06 07:46:51 2020 +0000 @@ -0,0 +1,103 @@ +#include "mbed.h" +#include "math.h" +#include "bluetoothV2bibli.h" + +Serial pc(USBTX, USBRX,460800); +Serial blueth(p9, p10,115200); // tx,rx,baudrate + + +static int blueRxBuffer[6]; // Buffer de réception de la liaison série bluetooth +static int blueTxBuffer[6]={240,0,0,0,0,15}; // Buffer de transmission de la liaison série bluetooth +static int RxBuffer[4][6]; +static int paramRx[4][2]; //0 KP 1 KI 2 KD 3 SPEED +static short flagR=0; + + +/********************************** Initialisation *************************************/ + +void init_blueth(void) +{ + blueth.attach(&receptionBlu, Serial::RxIrq); //Creation interruption de reception + blueth.printf("Hello world"); //message de test +} + + +/******************************* Fonctions de transmission *****************************/ + +void transmitBlu(void) +{ + static short i = 0; + if(blueth.writable()) //fonctionne si la liaison est libre + { + blueth.putc(blueTxBuffer[i]); //transmission de la trame de 6 octets + i++; + } + if(i>5) + { + i=0; + blueth.attach(NULL, Serial::TxIrq); + } +} + +void formatTrameT(short reg, int val) +{ + blueTxBuffer[1]=reg; + blueTxBuffer[2]=((val&0xFF0000)>>16); //Conversion sur trois octets independants + blueTxBuffer[3]=((val&0x00FF00)>>8); + blueTxBuffer[4]=((val&0x0000FF)); + + blueth.attach(&transmitBlu, Serial::TxIrq); +} + + +/****************************** Fonctions de reception ******************************/ + +void receptionBlu(void) +{ + static short j = 0, compteur=0; + + if(blueth.readable()) + { + blueRxBuffer[j]=blueth.getc(); //reception + blueth.putc(blueRxBuffer[j]); //renvoie de la reception pour tester + j++; + if(j>5) + { + j=0; + for(short i=0;i<6;i++)RxBuffer[compteur][i]=blueRxBuffer[i]; + compteur++; + if(compteur>4) + { + compteur=0; + flagR=1; + } + } + } +} + +int get_val_pc(short reg) +{ + short indice; + if(flagR==1) + { + decomp_trame(); + flagR=0; + } + if(reg == 30)indice = 0; + if(reg == 45)indice = 1; + if(reg == 60)indice = 2; + if(reg == 75)indice = 3; + return paramRx[indice][1]; +} + +void decomp_trame(void) +{ + for(short i=0;i<4;i++) + { + if(RxBuffer[i][0]== 240 && RxBuffer[i][5]==15) + { + paramRx[i][0]= RxBuffer[i][1]; + paramRx[i][1] = RxBuffer[i][2]*pow((double)2,(double)16)+RxBuffer[i][3]*pow((double)2,(double)8)+RxBuffer[i][4]; + } + } +} \ No newline at end of file