final

Dependencies:   mbed FATFileSystem

Fork of KL46Z-USBHostMSD_HelloWorld by Norimasa Okamoto

Committer:
homzovam
Date:
Sat Apr 04 20:16:39 2015 +0000
Revision:
4:77d6450f34d7
Parent:
3:4238ec88ddcf
prijimac-funkcni final

Who changed what in which revision?

UserRevisionLine numberNew contents of line
va009039 0:7012d3c02e58 1 #include "USBHostMSD.h"
homzovam 4:77d6450f34d7 2 #include "RF22.h"
va009039 0:7012d3c02e58 3
homzovam 4:77d6450f34d7 4 DigitalOut led1(LED2);
homzovam 4:77d6450f34d7 5
homzovam 4:77d6450f34d7 6 RF22 r(PTD4 , PTD6, PTD7, PTD5, PTD2);
homzovam 4:77d6450f34d7 7 //_slaveSelectPin(slaveSelectPin), _spi(mosi, miso, sclk), _interrupt(interrupt)
va009039 0:7012d3c02e58 8
homzovam 4:77d6450f34d7 9 Serial pc(USBTX, USBRX);
homzovam 4:77d6450f34d7 10
homzovam 4:77d6450f34d7 11 int main()
homzovam 4:77d6450f34d7 12 {
va009039 0:7012d3c02e58 13 USBHostMSD msd("usb");
homzovam 4:77d6450f34d7 14 if (!msd.connect())
homzovam 4:77d6450f34d7 15 {
va009039 2:982b2bbbeda4 16 error("USB Flash drive not found.\n");
va009039 2:982b2bbbeda4 17 }
homzovam 4:77d6450f34d7 18
va009039 0:7012d3c02e58 19 FILE* fp = fopen("/usb/test1.txt", "a");
homzovam 4:77d6450f34d7 20 if (fp)
homzovam 4:77d6450f34d7 21 {
homzovam 4:77d6450f34d7 22 fprintf(fp,"\n\r---------------------------------prijimac---------------------");
homzovam 4:77d6450f34d7 23 fprintf(fp,"\n\r tlak \t\tteplota \tzrycheni \t\tcislo pak");
homzovam 4:77d6450f34d7 24 fclose(fp);
homzovam 4:77d6450f34d7 25 }
homzovam 4:77d6450f34d7 26
homzovam 4:77d6450f34d7 27 uint8_t data[8];//dolni bity, horni bity, teplota, zrychleni
homzovam 4:77d6450f34d7 28 uint8_t delka = 8;
homzovam 4:77d6450f34d7 29 uint8_t *ptrdelka=&delka;
homzovam 4:77d6450f34d7 30
homzovam 4:77d6450f34d7 31 r.init();
homzovam 4:77d6450f34d7 32 pc.printf("Mod zarizeni je: %d\n", r.mode());
homzovam 4:77d6450f34d7 33
homzovam 4:77d6450f34d7 34 r.setModeRx();
homzovam 4:77d6450f34d7 35 pc.printf("Mod zarizeni je: %d\n", r.mode());
homzovam 4:77d6450f34d7 36 r.setPromiscuous(true);
homzovam 4:77d6450f34d7 37
homzovam 4:77d6450f34d7 38 while(1)
homzovam 4:77d6450f34d7 39 {
homzovam 4:77d6450f34d7 40
homzovam 4:77d6450f34d7 41 //r.obsluhapreruseni();
homzovam 4:77d6450f34d7 42 bool provedeno = r.recv(data, ptrdelka);
homzovam 4:77d6450f34d7 43 r.obsluhapreruseni();
homzovam 4:77d6450f34d7 44
homzovam 4:77d6450f34d7 45 //pc.printf("Prijato:");
homzovam 4:77d6450f34d7 46 //pc.printf(provedeno ? "true\n" : "false\n");
homzovam 4:77d6450f34d7 47
homzovam 4:77d6450f34d7 48 if(provedeno == true)
homzovam 4:77d6450f34d7 49 {
homzovam 4:77d6450f34d7 50
homzovam 4:77d6450f34d7 51 short tlak = data[1]<<8;
homzovam 4:77d6450f34d7 52 tlak = tlak + data[0];
homzovam 4:77d6450f34d7 53 float press= tlak * 1.25;
homzovam 4:77d6450f34d7 54 pc.printf("\n\r Tlak je %f", press);
homzovam 4:77d6450f34d7 55
homzovam 4:77d6450f34d7 56 short temp=data[2]-50;
homzovam 4:77d6450f34d7 57 pc.printf("\n\r Teplota je %i", temp);
homzovam 4:77d6450f34d7 58
homzovam 4:77d6450f34d7 59 float acc = (data[3]*0.5)-12; //udavany v g
homzovam 4:77d6450f34d7 60 pc.printf("\n\r Zrychleni je %f", acc);
homzovam 4:77d6450f34d7 61 pc.printf("\n\r Cislo paketu je:%i\n", data[4]);
homzovam 4:77d6450f34d7 62 pc.printf("\n\r---------------------------------prijimac---------------------");
homzovam 4:77d6450f34d7 63
homzovam 4:77d6450f34d7 64 FILE* fp = fopen("/usb/test1.txt", "a");
homzovam 4:77d6450f34d7 65 if (fp)
homzovam 4:77d6450f34d7 66 {
homzovam 4:77d6450f34d7 67 fprintf(fp,"\n\r %0.4f \t %i \t %0.2f \t %i", press, temp, acc, data[4]);
homzovam 4:77d6450f34d7 68 fprintf(fp, "\n");
homzovam 4:77d6450f34d7 69 fclose(fp);
homzovam 4:77d6450f34d7 70 }
va009039 1:88de0ef4739f 71 }
homzovam 4:77d6450f34d7 72
homzovam 4:77d6450f34d7 73 //pc.printf("\r\n Obsah dat je: ");
homzovam 4:77d6450f34d7 74 //for (int a =0; a<5; a++)pc.printf(" %i", data[a]);
homzovam 4:77d6450f34d7 75 for(int a=0; a<8; a++) data[a]=0;
homzovam 4:77d6450f34d7 76 wait_ms(500);
homzovam 4:77d6450f34d7 77 //wait(2);
homzovam 4:77d6450f34d7 78
va009039 0:7012d3c02e58 79 }
homzovam 4:77d6450f34d7 80 }
va009039 3:4238ec88ddcf 81