Update sdcard.cpp
This commit is contained in:
parent
8fe69a9130
commit
14baacc4bf
@ -19,7 +19,7 @@ static void createFile(void);
|
|||||||
|
|
||||||
File fileSDCard;
|
File fileSDCard;
|
||||||
|
|
||||||
bool sdcardInit() {
|
bool sdcard_init() {
|
||||||
ESP_LOGD(TAG, "looking for SD-card...");
|
ESP_LOGD(TAG, "looking for SD-card...");
|
||||||
useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK);
|
useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK);
|
||||||
if (useSDCard)
|
if (useSDCard)
|
||||||
@ -43,7 +43,6 @@ void sdcardWriteData(uint16_t noWifi, uint16_t noBle) {
|
|||||||
sprintf(tempBuffer, "%d,%d", noWifi, noBle);
|
sprintf(tempBuffer, "%d,%d", noWifi, noBle);
|
||||||
fileSDCard.print( tempBuffer);
|
fileSDCard.print( tempBuffer);
|
||||||
#if (HAS_SDS011)
|
#if (HAS_SDS011)
|
||||||
ESP_LOGD(TAG, "fine-dust-values: %5.1f,%4.1f", pm10, pm25);
|
|
||||||
sprintf(tempBuffer, ",%5.1f,%4.1f", pm10, pm25);
|
sprintf(tempBuffer, ",%5.1f,%4.1f", pm10, pm25);
|
||||||
fileSDCard.print( tempBuffer);
|
fileSDCard.print( tempBuffer);
|
||||||
#endif
|
#endif
|
||||||
@ -84,4 +83,41 @@ void createFile(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // (HAS_SDCARD)
|
||||||
|
|
||||||
|
if (++counterWrites > 2) {
|
||||||
|
// force writing to SD-card
|
||||||
|
ESP_LOGD(TAG, "flushing data to card");
|
||||||
|
fileSDCard.flush();
|
||||||
|
counterWrites = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void createFile(void) {
|
||||||
|
char bufferFilename[8 + 1 + 3 + 1];
|
||||||
|
|
||||||
|
useSDCard = false;
|
||||||
|
|
||||||
|
for (int i = 0; i < 100; i++) {
|
||||||
|
sprintf(bufferFilename, SDCARD_FILE_NAME, i);
|
||||||
|
ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename);
|
||||||
|
bool fileExists = SD.exists(bufferFilename);
|
||||||
|
if (!fileExists) {
|
||||||
|
ESP_LOGD(TAG, "SD: file does not exist: opening");
|
||||||
|
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
|
||||||
|
if (fileSDCard) {
|
||||||
|
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
|
||||||
|
fileSDCard.print( SDCARD_FILE_HEADER );
|
||||||
|
#if (HAS_SDS011)
|
||||||
|
fileSDCard.print( SDCARD_FILE_HEADER_SDS011 );
|
||||||
|
#endif
|
||||||
|
fileSDCard.println();
|
||||||
|
useSDCard = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
#endif // (HAS_SDCARD)
|
#endif // (HAS_SDCARD)
|
||||||
|
Loading…
Reference in New Issue
Block a user