final
Dependencies: mbed FATFileSystem
Fork of KL46Z-USBHostMSD_HelloWorld by
Diff: main.cpp
- Revision:
- 4:77d6450f34d7
- Parent:
- 3:4238ec88ddcf
--- a/main.cpp Fri Jun 13 01:57:39 2014 +0000 +++ b/main.cpp Sat Apr 04 20:16:39 2015 +0000 @@ -1,40 +1,81 @@ #include "USBHostMSD.h" +#include "RF22.h" -DigitalOut led1(LED1); +DigitalOut led1(LED2); + +RF22 r(PTD4 , PTD6, PTD7, PTD5, PTD2); +//_slaveSelectPin(slaveSelectPin), _spi(mosi, miso, sclk), _interrupt(interrupt) -int main() { +Serial pc(USBTX, USBRX); + +int main() +{ USBHostMSD msd("usb"); - if (!msd.connect()) { + if (!msd.connect()) + { error("USB Flash drive not found.\n"); } + FILE* fp = fopen("/usb/test1.txt", "a"); - if (fp) { - fprintf(fp, "Hello from mbed.\n"); - for(int i = 0; i < 21; i++) { - fprintf(fp, " %d", i); - led1 = !led1; + if (fp) + { + fprintf(fp,"\n\r---------------------------------prijimac---------------------"); + fprintf(fp,"\n\r tlak \t\tteplota \tzrycheni \t\tcislo pak"); + fclose(fp); + } + + uint8_t data[8];//dolni bity, horni bity, teplota, zrychleni + uint8_t delka = 8; + uint8_t *ptrdelka=&delka; + + r.init(); + pc.printf("Mod zarizeni je: %d\n", r.mode()); + + r.setModeRx(); + pc.printf("Mod zarizeni je: %d\n", r.mode()); + r.setPromiscuous(true); + + while(1) + { + + //r.obsluhapreruseni(); + bool provedeno = r.recv(data, ptrdelka); + r.obsluhapreruseni(); + + //pc.printf("Prijato:"); + //pc.printf(provedeno ? "true\n" : "false\n"); + + if(provedeno == true) + { + + short tlak = data[1]<<8; + tlak = tlak + data[0]; + float press= tlak * 1.25; + pc.printf("\n\r Tlak je %f", press); + + short temp=data[2]-50; + pc.printf("\n\r Teplota je %i", temp); + + float acc = (data[3]*0.5)-12; //udavany v g + pc.printf("\n\r Zrychleni je %f", acc); + pc.printf("\n\r Cislo paketu je:%i\n", data[4]); + pc.printf("\n\r---------------------------------prijimac---------------------"); + + FILE* fp = fopen("/usb/test1.txt", "a"); + if (fp) + { + fprintf(fp,"\n\r %0.4f \t %i \t %0.2f \t %i", press, temp, acc, data[4]); + fprintf(fp, "\n"); + fclose(fp); + } } - fprintf(fp, "\n"); - fclose(fp); - } - fp = fopen("/usb/test1.txt", "r"); - if (fp) { - int n = 0; - while(1) { - int c = fgetc(fp); - if (c == EOF) { - break; - } - printf("%c", c); - n++; - led1 = !led1; + + //pc.printf("\r\n Obsah dat je: "); + //for (int a =0; a<5; a++)pc.printf(" %i", data[a]); + for(int a=0; a<8; a++) data[a]=0; + wait_ms(500); + //wait(2); + } - fclose(fp); - printf("%d bytes\n", n); - } +} - while(1) { - led1 = !led1; - wait_ms(200); - } -}