Program for leaving logs of running IM920.
Dependencies: IM920 SDFileSystem mbed
Revision 0:89c1b4e9bfec, committed 2017-05-30
- Comitter:
- aaaaaYukiaaaaa
- Date:
- Tue May 30 05:05:46 2017 +0000
- Commit message:
- Program for leaving logs about running IM920.
Changed in this revision
diff -r 000000000000 -r 89c1b4e9bfec IM920.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/IM920.lib Tue May 30 05:05:46 2017 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/okini3939/code/IM920/#db269462ad1c
diff -r 000000000000 -r 89c1b4e9bfec SDFileSystem.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Tue May 30 05:05:46 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
diff -r 000000000000 -r 89c1b4e9bfec main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue May 30 05:05:46 2017 +0000 @@ -0,0 +1,136 @@ +/*** 受信したデータをSDに保存して確認するプログラム */ + +#include "mbed.h" +#include "IM920.h" +#include "SDFileSystem.h" + +// Pin used by SD card +SDFileSystem sd(p5, p6, p7, p8, "sd"); + +// Pin used by IM920 & UART +Serial pc(USBTX, USBRX); +IM920 im920(p28, p27, p29, p30); + +//Digital I/O Pin +DigitalOut myled1(LED1); +DigitalOut myled2(LED2); +AnalogIn inpt(p20); + +//Prottype define +void SD(int num, double btry); +void callback(void); + +//Define maclo +char BUF[65]; + +int main() { + float btry_lg = 0; + int nmbr_lg = 0; + + FILE *fp_csv = fopen("/sd/mydir/sdtest.csv", "w"); + if(fp_csv == NULL) { + error("Could not open file for write\n"); + } + fprintf(fp_csv, "baterry,number\n"); + fclose(fp_csv); + + +// FILE *fp_txt = fopen("/sd/mydir/sdtest.txt", "a"); +// if(fp_txt == NULL) { +// error("Could not open file for write\n"); +// } +// fclose(fp_txt); + + while(1){ + // test the voltage on the initialized analog pin + // and if greater than 0.3 * VCC set the digital pin + // to a logic 1 otherwise a logic 0 + btry_lg = inpt.read()*3.3; + + //if(ain > 0.3f) { + + //} else { + + //} + + // print the percentage and 16 bit normalized values + //printf("percentage: %3.3f%%\n", ain.read()*100.0f); + //printf("normalized: 0x%04X \n", ain.read_u16()); + //wait(0.2f); + + + + nmbr_lg++; + SD(nmbr_lg, btry_lg); + + //wait(0.1); + } +} + +void SD(int num, double btry){ + myled1 = 1; + + //printf("Hello World!\n"); + + mkdir("/sd/mydir", 0777); + + FILE *fp_csv = fopen("/sd/mydir/sdtest.csv", "a"); + if(fp_csv == NULL) { + error("Could not open file for write\n"); + } + + fprintf(fp_csv, "%d,%f\n",num, btry); + + fclose(fp_csv); + + /*** txtファイルバージョン ***/ + +// FILE *fp_txt = fopen("/sd/mydir/sdtest.txt", "a"); +// if(fp_txt == NULL) { +// error("Could not open file for write\n"); +// } +// fprintf(fp_txt, "Hello fun SD Card World!\n"); +// fprintf(fp_txt, "Hello fun SD Card World!\n"); +// fprintf(fp_txt, "%f,%f\n", btry, (float)num); +// +// fclose(fp_txt); + + + printf("Goodbye World!\n"); + myled1 = 0; +} + +void callback(void){ + int i; + char buf[65]; + + i = im920.recv(buf, 64); + buf[i] = 0; + printf("recv: '%s' (%d)\r\n", buf, i); +} + +void IM920_read(void){ + int i = 0; + + //pc.baud(115200); + pc.band(19200); + pc.printf("*** IM920\r\n"); + im920.init(); + im920.attach(callback); + myled2 = 1; + + im920.poll(); + if (pc.readable()) { + char c = pc.getc(); + + if (c == '\r') { + BUF[i] = 0; + printf("send: %s\r\n", BUF); + im920.send(BUF, i); + } + else{ + for (i = 0; i < 64; i++) { + BUF[i] = c; + } + } +} \ No newline at end of file
diff -r 000000000000 -r 89c1b4e9bfec mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue May 30 05:05:46 2017 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file