BLEBeaconScan / my_sd.h /
d0ba48c 5 years ago
1 contributor
51 lines | 1.387kb
#ifndef _MY_SD_H
#define _MY_SD_H

#include "my_constants.h"
#include "my_ble.h"

#include "FS.h"                // SD Card ESP32
#include "SD_MMC.h"            // SD Card ESP32

#define SDPATHPFX "/ble"
uint8_t cardType = CARD_NONE;

void sd_set() {
  if(!SD_MMC.begin()){
    Serial.println("SD Card Mount Failed");
  }
  cardType = SD_MMC.cardType();
  switch(cardType) {
    case CARD_NONE:
      Serial.println("No SD Card attached");break;
    case CARD_MMC:
      Serial.println("MMC Card attached");break;
    case CARD_SD:
      Serial.println("SD Card attached");break;
    case CARD_SDHC:
      Serial.println("SDHC Card attached");break;
    case CARD_UNKNOWN:
      Serial.println("UNKNOWN Card attached");break;
    default:
      Serial.println("This should not happened");break;
  }
}

void sd_write() {
  if( (CARD_NONE != cardType) && (CARD_UNKNOWN != cardType)) {
    char pathFmt[16]="";
    sprintf(pathFmt,"%s-%05d.json",SDPATHPFX,(countMeasures%10000));
    String path = pathFmt;
    fs::FS &fs = SD_MMC;
    Serial.printf("JSON : %s\n", path.c_str());
    File file = fs.open(path.c_str(), FILE_WRITE);
    if(!file){
      Serial.println("Failed to open file in writing mode");
    } else {
      file.write((const uint8_t*)ss.str().c_str(),ss.str().length());
    }
    file.close();
  }
}

#endif //_MY_SD_H