Fabien Lepoutre
/
ProjetMbed
main.cpp@1:e184fce6da0d, 2012-01-23 (annotated)
- Committer:
- fabienlepoutre
- Date:
- Mon Jan 23 13:08:52 2012 +0000
- Revision:
- 1:e184fce6da0d
- Parent:
- 0:5fccc8628275
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 | 1:e184fce6da0d | 17 | ChainEch *LastEch; |
fabienlepoutre | 0:5fccc8628275 | 18 | }HeadEch; |
fabienlepoutre | 0:5fccc8628275 | 19 | |
fabienlepoutre | 0:5fccc8628275 | 20 | |
fabienlepoutre | 0:5fccc8628275 | 21 | HeadEch Head; |
fabienlepoutre | 0:5fccc8628275 | 22 | |
fabienlepoutre | 0:5fccc8628275 | 23 | |
fabienlepoutre | 0:5fccc8628275 | 24 | int main() { |
fabienlepoutre | 0:5fccc8628275 | 25 | } |
fabienlepoutre | 0:5fccc8628275 | 26 | |
fabienlepoutre | 0:5fccc8628275 | 27 | |
fabienlepoutre | 0:5fccc8628275 | 28 | void vTimeoutEch(){ |
fabienlepoutre | 1:e184fce6da0d | 29 | ChainEch* ValEch = (ChainEch*)malloc(sizeof(ChainEch)); //Cr�ation maillon valeur CAN |
fabienlepoutre | 1:e184fce6da0d | 30 | ValEch->fValEch = voltage; // R�cup�ration valeur -> ?!: valeur entre 0 et 1 -->> CONVERTIR |
fabienlepoutre | 0:5fccc8628275 | 31 | ValEch->suivant = NULL; |
fabienlepoutre | 1:e184fce6da0d | 32 | if(Head.NbEch == 0){ // Test si Premier maillon |
fabienlepoutre | 1:e184fce6da0d | 33 | Head.FirstEch = ValEch; // Atribu. premier maillon |
fabienlepoutre | 1:e184fce6da0d | 34 | Head.NbEch++; |
fabienlepoutre | 1:e184fce6da0d | 35 | Head.LastEch = ValEch; |
fabienlepoutre | 0:5fccc8628275 | 36 | } |
fabienlepoutre | 0:5fccc8628275 | 37 | else{ |
fabienlepoutre | 1:e184fce6da0d | 38 | ChainEch* maillon = Head.FirstEch; // On va au bou de la chaine |
fabienlepoutre | 0:5fccc8628275 | 39 | while(maillon->suivant !=NULL){ |
fabienlepoutre | 0:5fccc8628275 | 40 | maillon = maillon->suivant; |
fabienlepoutre | 0:5fccc8628275 | 41 | } |
fabienlepoutre | 0:5fccc8628275 | 42 | maillon->suivant = ValEch; // Ajout a la chaine |
fabienlepoutre | 1:e184fce6da0d | 43 | Head.NbEch++; |
fabienlepoutre | 1:e184fce6da0d | 44 | Head.LastEch = ValEch; |
fabienlepoutre | 0:5fccc8628275 | 45 | } |
fabienlepoutre | 0:5fccc8628275 | 46 | } |
fabienlepoutre | 0:5fccc8628275 | 47 | |
fabienlepoutre | 0:5fccc8628275 | 48 | |
fabienlepoutre | 0:5fccc8628275 | 49 | |
fabienlepoutre | 0:5fccc8628275 | 50 | HeadEch* Echantillonnage(int freq){ |
fabienlepoutre | 1:e184fce6da0d | 51 | float time = 1/freq; // periode echantillonnage |
fabienlepoutre | 1:e184fce6da0d | 52 | Head.NbEch =0; // Initialisation |
fabienlepoutre | 1:e184fce6da0d | 53 | Head.FirstEch = NULL; |
fabienlepoutre | 0:5fccc8628275 | 54 | |
fabienlepoutre | 0:5fccc8628275 | 55 | |
fabienlepoutre | 0:5fccc8628275 | 56 | timeout.attach(&vTimeoutEch, time); // Init Timeout |
fabienlepoutre | 0:5fccc8628275 | 57 | } |
fabienlepoutre | 0:5fccc8628275 | 58 | |
fabienlepoutre | 0:5fccc8628275 | 59 | |
fabienlepoutre | 0:5fccc8628275 | 60 | |
fabienlepoutre | 0:5fccc8628275 | 61 | |
fabienlepoutre | 0:5fccc8628275 | 62 |