![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
201708能代のメインマイコンの保存データ送信用プログラム
Dependencies: MPU6050 mbed MS5607
main.cpp
- Committer:
- mikawataru
- Date:
- 2017-07-18
- Revision:
- 2:1dbaef45ae46
- Parent:
- 0:bdbd3d6fc5d5
- Child:
- 3:660279be8484
File content as of revision 2:1dbaef45ae46:
#include "mbed.h" #include "string.h" #include "SDFileSystem.h" #define BUFFNUM 50 #define CHARNUM 16 SDFileSystem sd(dp2, dp1, dp6, dp14, "sd"); Serial mainCP(dp16, dp15); bool row = false; int8_t col=0, cnt=0; char data[2][BUFFNUM][CHARNUM] = {}; FILE *fp; void _log(); int main() { printf("Hello World!\r\n"); mkdir("/sd/mydir", 0777); fp = fopen("/sd/mydir/log.txt", "w"); if(fp == NULL) error("Could not open file for write\r\n"); fprintf(fp, "Hello fun SD Card World!\n"); fclose(fp); mainCP.attach(&_log, Serial::RxIrq); while(1); } void _log(){//受信割り込み用.\n区切りで保存する. data[row][col][cnt] = mainCP.getc(); cnt++; if(data[row][col][cnt]=='\n'){ col++; cnt = 0; }else if(cnt==CHARNUM){ memset(&data[row][col][0],'\0',CHARNUM); cnt = 0; } if(col==BUFFNUM){ col = 0; row = !row; fp = fopen("/sd/mydir/log.txt", "a"); for (int i = 0; i < BUFFNUM; i++){ fprintf(fp,&data[!row][i][0]); } fclose(fp); memset(&data[row][0][0],'\0',BUFFNUM*CHARNUM); } }