gestione accelerometro e scrittura su sd. Da aggiungere la scrittura su file dei dati

Dependencies:   SDFileSystem3 mbed

Fork of f4_def_v2 by Unina_corse

lettoreSD.h

Committer:
NdA994
Date:
2017-11-22
Revision:
3:3b2b8b0955f9
Parent:
2:f59bd5312559
Child:
4:58e4283f9a59

File content as of revision 3:3b2b8b0955f9:

#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;
    }
    else{
        nCounter++;
        strcat(buffer, stringa);
    }
    
}

#endif