Gestione accelerometro e scrittura su SD da F4
Dependencies: SDFileSystem1 mbed
Fork of SDFileSystem_HelloWorld by
Diff: lettoreSD.h
- Revision:
- 2:f59bd5312559
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lettoreSD.h Mon Nov 20 22:18:10 2017 +0000 @@ -0,0 +1,52 @@ +#ifndef __LETTORESD__ +#define __LETTORESD__ + +#include "SDFileSystem.h" + +int nFile = 1; + +SDFileSystem sd(SPI_MOSI, SPI_MISO, SPI_SCK, A2, "sd"); +FILE *fp; +char buffer[4100]; +int nCounter = 0; + +void initFile(){ + mkdir("/sd/mydir", 0777); +} + + +FILE * aperturaFile(){ + char destinazione[14]; + char path[21]="/sd/mydir/"; + sprintf(destinazione, "%d", nFile); + strcat(destinazione, ".txt"); + strcat(path, destinazione); + fp = fopen(path, "w"); + if(fp == NULL){ + error("Could not open file for write\n"); + } + return fp; +} + +void chiusuraFile(){ + fclose(fp); + nFile++; + buffer[0] = 0; + nCounter = 0; +} + +void stampaFile(char* stringa){ + if(nCounter == 99){ + fprintf(fp, "%s", buffer); + nCounter = 0; + buffer[0] = 0; + printf("sono qua <---------\n\r"); + } + else{ + printf("sono qua\n\r"); + nCounter++; + strcat(buffer, stringa); + } +} + +#endif \ No newline at end of file