Fabien Lepoutre
/
ProjetMbed
main.cpp@0:5fccc8628275, 2012-01-23 (annotated)
- Committer:
- fabienlepoutre
- Date:
- Mon Jan 23 12:55:16 2012 +0000
- Revision:
- 0:5fccc8628275
- Child:
- 1:e184fce6da0d
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabienlepoutre | 0:5fccc8628275 | 1 | #include "mbed.h" |
fabienlepoutre | 0:5fccc8628275 | 2 | |
fabienlepoutre | 0:5fccc8628275 | 3 | DigitalOut myled(LED1); |
fabienlepoutre | 0:5fccc8628275 | 4 | Timeout timeout; |
fabienlepoutre | 0:5fccc8628275 | 5 | AnalogIn voltage(p20); |
fabienlepoutre | 0:5fccc8628275 | 6 | |
fabienlepoutre | 0:5fccc8628275 | 7 | |
fabienlepoutre | 0:5fccc8628275 | 8 | typedef struct CHAINECH{ |
fabienlepoutre | 0:5fccc8628275 | 9 | float fValEch; |
fabienlepoutre | 0:5fccc8628275 | 10 | struct CHAINECH* suivant; |
fabienlepoutre | 0:5fccc8628275 | 11 | }ChainEch; |
fabienlepoutre | 0:5fccc8628275 | 12 | |
fabienlepoutre | 0:5fccc8628275 | 13 | |
fabienlepoutre | 0:5fccc8628275 | 14 | typedef struct HEADECH{ |
fabienlepoutre | 0:5fccc8628275 | 15 | ChainEch *FirstEch; |
fabienlepoutre | 0:5fccc8628275 | 16 | int NbEch; |
fabienlepoutre | 0:5fccc8628275 | 17 | }HeadEch; |
fabienlepoutre | 0:5fccc8628275 | 18 | |
fabienlepoutre | 0:5fccc8628275 | 19 | |
fabienlepoutre | 0:5fccc8628275 | 20 | HeadEch Head; |
fabienlepoutre | 0:5fccc8628275 | 21 | |
fabienlepoutre | 0:5fccc8628275 | 22 | |
fabienlepoutre | 0:5fccc8628275 | 23 | int main() { |
fabienlepoutre | 0:5fccc8628275 | 24 | } |
fabienlepoutre | 0:5fccc8628275 | 25 | |
fabienlepoutre | 0:5fccc8628275 | 26 | |
fabienlepoutre | 0:5fccc8628275 | 27 | void vTimeoutEch(){ |
fabienlepoutre | 0:5fccc8628275 | 28 | ChainEch* ValEch = (ChainEch*)malloc(sizeof(ChainEch)); //Cr�ation maillon valeur CAN |
fabienlepoutre | 0:5fccc8628275 | 29 | ValEch->fValEch = voltage; // R�cup�ration valeur -> ?!: valeur entre 0 et 1 -->> CONVERTIR |
fabienlepoutre | 0:5fccc8628275 | 30 | ValEch->suivant = NULL; |
fabienlepoutre | 0:5fccc8628275 | 31 | if(Head->NbEch == 0){ // Test si Premier maillon |
fabienlepoutre | 0:5fccc8628275 | 32 | Head->FirstEch = ValEch; // Atribu. premier maillon |
fabienlepoutre | 0:5fccc8628275 | 33 | Head->NbEch++; |
fabienlepoutre | 0:5fccc8628275 | 34 | } |
fabienlepoutre | 0:5fccc8628275 | 35 | else{ |
fabienlepoutre | 0:5fccc8628275 | 36 | ChainEch* maillon = Head->FirstEch; // On va au bou de la chaine |
fabienlepoutre | 0:5fccc8628275 | 37 | while(maillon->suivant !=NULL){ |
fabienlepoutre | 0:5fccc8628275 | 38 | maillon = maillon->suivant; |
fabienlepoutre | 0:5fccc8628275 | 39 | } |
fabienlepoutre | 0:5fccc8628275 | 40 | maillon->suivant = ValEch; // Ajout a la chaine |
fabienlepoutre | 0:5fccc8628275 | 41 | Head->NbEch++; |
fabienlepoutre | 0:5fccc8628275 | 42 | } |
fabienlepoutre | 0:5fccc8628275 | 43 | } |
fabienlepoutre | 0:5fccc8628275 | 44 | |
fabienlepoutre | 0:5fccc8628275 | 45 | |
fabienlepoutre | 0:5fccc8628275 | 46 | |
fabienlepoutre | 0:5fccc8628275 | 47 | HeadEch* Echantillonnage(int freq){ |
fabienlepoutre | 0:5fccc8628275 | 48 | float time = 1/freq; // periode echantillonnage |
fabienlepoutre | 0:5fccc8628275 | 49 | HeadEch* Echanti = (HeadEch*)malloc(sizeof(HeadEch)); // Cr�ation t�te maillon |
fabienlepoutre | 0:5fccc8628275 | 50 | Echanti->NbEch =0; // Initialisation |
fabienlepoutre | 0:5fccc8628275 | 51 | Echanti->FirstEch = NULL; |
fabienlepoutre | 0:5fccc8628275 | 52 | |
fabienlepoutre | 0:5fccc8628275 | 53 | |
fabienlepoutre | 0:5fccc8628275 | 54 | timeout.attach(&vTimeoutEch, time); // Init Timeout |
fabienlepoutre | 0:5fccc8628275 | 55 | } |
fabienlepoutre | 0:5fccc8628275 | 56 | |
fabienlepoutre | 0:5fccc8628275 | 57 | |
fabienlepoutre | 0:5fccc8628275 | 58 | |
fabienlepoutre | 0:5fccc8628275 | 59 | |
fabienlepoutre | 0:5fccc8628275 | 60 |