bruno LARNAUDIE
/
UsbTest
main.cpp@0:4359b47b3d7c, 2011-08-26 (annotated)
- Committer:
- slowness
- Date:
- Fri Aug 26 12:19:16 2011 +0000
- Revision:
- 0:4359b47b3d7c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
slowness | 0:4359b47b3d7c | 1 | #include "mbed.h" |
slowness | 0:4359b47b3d7c | 2 | #include "MSCFileSystem.h" |
slowness | 0:4359b47b3d7c | 3 | |
slowness | 0:4359b47b3d7c | 4 | #define FSNAME "msc" |
slowness | 0:4359b47b3d7c | 5 | #define LOCAL "local" |
slowness | 0:4359b47b3d7c | 6 | |
slowness | 0:4359b47b3d7c | 7 | #define START 1 |
slowness | 0:4359b47b3d7c | 8 | #define STOP 0 |
slowness | 0:4359b47b3d7c | 9 | #define DEBOUNCING_INTERVAL 40 // Debouncing interval (in mili-seconds) |
slowness | 0:4359b47b3d7c | 10 | |
slowness | 0:4359b47b3d7c | 11 | Serial pc(USBTX,USBRX); |
slowness | 0:4359b47b3d7c | 12 | |
slowness | 0:4359b47b3d7c | 13 | MSCFileSystem msc(FSNAME); |
slowness | 0:4359b47b3d7c | 14 | LocalFileSystem local(LOCAL); |
slowness | 0:4359b47b3d7c | 15 | |
slowness | 0:4359b47b3d7c | 16 | DigitalOut led1(LED1); |
slowness | 0:4359b47b3d7c | 17 | |
slowness | 0:4359b47b3d7c | 18 | AnalogIn input(p16); |
slowness | 0:4359b47b3d7c | 19 | InterruptIn bouton(p18); |
slowness | 0:4359b47b3d7c | 20 | Timeout timeout; |
slowness | 0:4359b47b3d7c | 21 | Timer t; |
slowness | 0:4359b47b3d7c | 22 | Timer timerAcquisition; |
slowness | 0:4359b47b3d7c | 23 | Timer tempsBoucle; |
slowness | 0:4359b47b3d7c | 24 | |
slowness | 0:4359b47b3d7c | 25 | struct TRAME |
slowness | 0:4359b47b3d7c | 26 | { |
slowness | 0:4359b47b3d7c | 27 | unsigned long int tempsA; /* 4 octets nb de tops de 250�s */ |
slowness | 0:4359b47b3d7c | 28 | unsigned char topAv, topAr; |
slowness | 0:4359b47b3d7c | 29 | unsigned short guidon, refx, refy, refz, ax, ay, az, rx, ry, rz, gaz; |
slowness | 0:4359b47b3d7c | 30 | unsigned long int tempsB; /* 4 octets tempsA + 1 */ |
slowness | 0:4359b47b3d7c | 31 | }; |
slowness | 0:4359b47b3d7c | 32 | |
slowness | 0:4359b47b3d7c | 33 | TRAME trame; |
slowness | 0:4359b47b3d7c | 34 | int etatBouton = STOP; |
slowness | 0:4359b47b3d7c | 35 | int compteurfclose = 0; |
slowness | 0:4359b47b3d7c | 36 | int compteurfopen = 0; |
slowness | 0:4359b47b3d7c | 37 | int veriffclose = 1; |
slowness | 0:4359b47b3d7c | 38 | int compteurBoucle= 0; |
slowness | 0:4359b47b3d7c | 39 | DIR *d; |
slowness | 0:4359b47b3d7c | 40 | FILE *fichier; |
slowness | 0:4359b47b3d7c | 41 | |
slowness | 0:4359b47b3d7c | 42 | void isr_interrupteurRisingStart(void) { |
slowness | 0:4359b47b3d7c | 43 | if ( t.read_ms() > DEBOUNCING_INTERVAL ) { |
slowness | 0:4359b47b3d7c | 44 | etatBouton = START; |
slowness | 0:4359b47b3d7c | 45 | printf("Isr Rising\n\r"); |
slowness | 0:4359b47b3d7c | 46 | compteurfopen = 1; |
slowness | 0:4359b47b3d7c | 47 | wait_ms(100); |
slowness | 0:4359b47b3d7c | 48 | } |
slowness | 0:4359b47b3d7c | 49 | |
slowness | 0:4359b47b3d7c | 50 | t.reset(); // timer reset |
slowness | 0:4359b47b3d7c | 51 | } |
slowness | 0:4359b47b3d7c | 52 | void isr_interrupteurFallingStop(void) { |
slowness | 0:4359b47b3d7c | 53 | if ( t.read_ms() > DEBOUNCING_INTERVAL ) { |
slowness | 0:4359b47b3d7c | 54 | etatBouton = STOP; |
slowness | 0:4359b47b3d7c | 55 | printf("Isr Falling\n\r"); |
slowness | 0:4359b47b3d7c | 56 | compteurfclose = 1; |
slowness | 0:4359b47b3d7c | 57 | wait_ms(100); |
slowness | 0:4359b47b3d7c | 58 | } |
slowness | 0:4359b47b3d7c | 59 | |
slowness | 0:4359b47b3d7c | 60 | t.reset(); // timer reset |
slowness | 0:4359b47b3d7c | 61 | } |
slowness | 0:4359b47b3d7c | 62 | int main() { |
slowness | 0:4359b47b3d7c | 63 | t.start(); |
slowness | 0:4359b47b3d7c | 64 | int acquisition = 0; |
slowness | 0:4359b47b3d7c | 65 | float temps; |
slowness | 0:4359b47b3d7c | 66 | char i; |
slowness | 0:4359b47b3d7c | 67 | |
slowness | 0:4359b47b3d7c | 68 | trame.refx = 0x7ff; /* 2047 */ |
slowness | 0:4359b47b3d7c | 69 | trame.refy = 0x7ff; |
slowness | 0:4359b47b3d7c | 70 | trame.refz = 0x7ff; |
slowness | 0:4359b47b3d7c | 71 | trame.ax = 0x5555; |
slowness | 0:4359b47b3d7c | 72 | |
slowness | 0:4359b47b3d7c | 73 | unsigned short int buf[16]; |
slowness | 0:4359b47b3d7c | 74 | for(i=0;i<16;i++){ |
slowness | 0:4359b47b3d7c | 75 | buf[i] = 0; |
slowness | 0:4359b47b3d7c | 76 | } |
slowness | 0:4359b47b3d7c | 77 | buf[4] = 0x7FF; |
slowness | 0:4359b47b3d7c | 78 | buf[5] = 0x7FF; |
slowness | 0:4359b47b3d7c | 79 | buf[6] = 0x7FF; |
slowness | 0:4359b47b3d7c | 80 | buf[7] = 0x5555; |
slowness | 0:4359b47b3d7c | 81 | //d = opendir("/" FSNAME); |
slowness | 0:4359b47b3d7c | 82 | //fichier = fopen( "/" FSNAME "/Datatest.txt", "ab"); |
slowness | 0:4359b47b3d7c | 83 | |
slowness | 0:4359b47b3d7c | 84 | //d = opendir("/" LOCAL); |
slowness | 0:4359b47b3d7c | 85 | //fichier = fopen( "/" LOCAL "/Datatest.txt", "ab"); |
slowness | 0:4359b47b3d7c | 86 | |
slowness | 0:4359b47b3d7c | 87 | bouton.rise(&isr_interrupteurRisingStart); |
slowness | 0:4359b47b3d7c | 88 | bouton.fall(&isr_interrupteurFallingStop); |
slowness | 0:4359b47b3d7c | 89 | |
slowness | 0:4359b47b3d7c | 90 | while (1){ |
slowness | 0:4359b47b3d7c | 91 | |
slowness | 0:4359b47b3d7c | 92 | if(compteurfopen){ |
slowness | 0:4359b47b3d7c | 93 | if(veriffclose){ |
slowness | 0:4359b47b3d7c | 94 | do{ |
slowness | 0:4359b47b3d7c | 95 | printf("do\n\r"); |
slowness | 0:4359b47b3d7c | 96 | fichier = fopen( "/" FSNAME "/Data.IEF", "ab"); |
slowness | 0:4359b47b3d7c | 97 | timerAcquisition.start(); |
slowness | 0:4359b47b3d7c | 98 | }while (fichier == NULL); |
slowness | 0:4359b47b3d7c | 99 | printf("Open file\n\rAcquisition : %d\n\r",acquisition); |
slowness | 0:4359b47b3d7c | 100 | veriffclose = 0; |
slowness | 0:4359b47b3d7c | 101 | compteurfopen = 0; |
slowness | 0:4359b47b3d7c | 102 | acquisition++; |
slowness | 0:4359b47b3d7c | 103 | }else{ |
slowness | 0:4359b47b3d7c | 104 | printf("Defaultclose file\n\r"); |
slowness | 0:4359b47b3d7c | 105 | compteurfclose = 1; |
slowness | 0:4359b47b3d7c | 106 | } |
slowness | 0:4359b47b3d7c | 107 | } |
slowness | 0:4359b47b3d7c | 108 | tempsBoucle.start(); |
slowness | 0:4359b47b3d7c | 109 | while (etatBouton && !compteurfopen){ |
slowness | 0:4359b47b3d7c | 110 | buf[1] = ((timerAcquisition.read_us()) & 0xFFFF0000)>>16; |
slowness | 0:4359b47b3d7c | 111 | buf[0] = timerAcquisition.read_us(); |
slowness | 0:4359b47b3d7c | 112 | buf[15] = ((timerAcquisition.read_us()/2)& 0xFFFF0000)>>16; |
slowness | 0:4359b47b3d7c | 113 | buf[14] = timerAcquisition.read_us()/2; |
slowness | 0:4359b47b3d7c | 114 | buf[7] = input.read_u16(); |
slowness | 0:4359b47b3d7c | 115 | fwrite(buf,2,16,fichier); |
slowness | 0:4359b47b3d7c | 116 | led1 = 1; |
slowness | 0:4359b47b3d7c | 117 | compteurBoucle++; |
slowness | 0:4359b47b3d7c | 118 | } |
slowness | 0:4359b47b3d7c | 119 | |
slowness | 0:4359b47b3d7c | 120 | if(compteurfclose){ |
slowness | 0:4359b47b3d7c | 121 | temps = tempsBoucle.read(); |
slowness | 0:4359b47b3d7c | 122 | printf("%d %f\n\r", compteurBoucle, temps); |
slowness | 0:4359b47b3d7c | 123 | fclose(fichier); |
slowness | 0:4359b47b3d7c | 124 | timerAcquisition.reset(); |
slowness | 0:4359b47b3d7c | 125 | led1 = 0; |
slowness | 0:4359b47b3d7c | 126 | printf("Close file Compteur\n\r"); |
slowness | 0:4359b47b3d7c | 127 | compteurfclose = 0; |
slowness | 0:4359b47b3d7c | 128 | veriffclose = 1; |
slowness | 0:4359b47b3d7c | 129 | compteurBoucle = 0; |
slowness | 0:4359b47b3d7c | 130 | } |
slowness | 0:4359b47b3d7c | 131 | } |
slowness | 0:4359b47b3d7c | 132 | } |