Gestione accelerometro e scrittura su SD da F4

Dependencies:   SDFileSystem1 mbed

Fork of SDFileSystem_HelloWorld by mbed official

lettoreSD.h

Committer:
NdA994
Date:
2017-11-20
Revision:
2:f59bd5312559

File content as of revision 2:f59bd5312559:

#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