commit
960fdfac2c
@ -8,10 +8,8 @@
|
|||||||
#if (HAS_SDCARD)
|
#if (HAS_SDCARD)
|
||||||
#if HAS_SDCARD == 1
|
#if HAS_SDCARD == 1
|
||||||
#include <mySD.h>
|
#include <mySD.h>
|
||||||
#define MYSD SD
|
|
||||||
#elif HAS_SDCARD == 2
|
#elif HAS_SDCARD == 2
|
||||||
#include <SD_MMC.h>
|
#include <SD_MMC.h>
|
||||||
#define MYSD SD_MMC
|
|
||||||
#else
|
#else
|
||||||
#error HAS_SDCARD unknown card reader value, must be either 1 or 2
|
#error HAS_SDCARD unknown card reader value, must be either 1 or 2
|
||||||
#endif
|
#endif
|
||||||
|
@ -16,10 +16,10 @@
|
|||||||
;halfile = ttgov1.h
|
;halfile = ttgov1.h
|
||||||
;halfile = ttgov2.h
|
;halfile = ttgov2.h
|
||||||
;halfile = ttgov21old.h
|
;halfile = ttgov21old.h
|
||||||
;halfile = ttgov21new.h
|
halfile = ttgov21new.h
|
||||||
;halfile = ttgofox.h
|
;halfile = ttgofox.h
|
||||||
;halfile = ttgobeam.h
|
;halfile = ttgobeam.h
|
||||||
halfile = ttgobeam10.h
|
;halfile = ttgobeam10.h
|
||||||
;halfile = ttgotdisplay.h
|
;halfile = ttgotdisplay.h
|
||||||
;halfile = ttgotwristband.h
|
;halfile = ttgotwristband.h
|
||||||
;halfile = fipy.h
|
;halfile = fipy.h
|
||||||
@ -133,4 +133,4 @@ upload_protocol = esptool
|
|||||||
[env:dev]
|
[env:dev]
|
||||||
upload_protocol = esptool
|
upload_protocol = esptool
|
||||||
build_type = debug
|
build_type = debug
|
||||||
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
|
platform = https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
|
|
||||||
// default settings for transmission of sensor data (first list = data on / second line = data off)
|
// default settings for transmission of sensor data (first list = data on / second line = data off)
|
||||||
#define PAYLOADMASK \
|
#define PAYLOADMASK \
|
||||||
((GPS_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA) \
|
((GPS_DATA | MEMS_DATA | COUNT_DATA | SENSOR1_DATA | SENSOR2_DATA | SENSOR3_DATA | BATT_DATA) \
|
||||||
& (~BATT_DATA) & (~RESERVED_DATA))
|
& (~RESERVED_DATA))
|
||||||
|
|
||||||
// MAC sniffing parameters
|
// MAC sniffing parameters
|
||||||
#define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer
|
#define BLECOUNTER 1 // set to 0 if you do not want to install the BLE sniffer
|
||||||
|
@ -10,62 +10,37 @@ static const char TAG[] = __FILE__;
|
|||||||
|
|
||||||
#ifdef HAS_SDCARD
|
#ifdef HAS_SDCARD
|
||||||
|
|
||||||
static bool useSDCard = false;
|
static bool useSDCard;
|
||||||
static void openFile(void);
|
static void openFile(void);
|
||||||
|
|
||||||
File fileSDCard;
|
File fileSDCard;
|
||||||
|
|
||||||
bool sdcard_init(bool create) {
|
bool sdcard_init(bool create) {
|
||||||
|
|
||||||
uint8_t cardType;
|
|
||||||
uint64_t cardSize;
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "looking for SD-card...");
|
|
||||||
|
|
||||||
// for usage of SD drivers on ESP32 platform see
|
// for usage of SD drivers on ESP32 platform see
|
||||||
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdspi_host.html
|
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdspi_host.html
|
||||||
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html
|
// https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/peripherals/sdmmc_host.html
|
||||||
|
|
||||||
|
ESP_LOGI(TAG, "looking for SD-card...");
|
||||||
#if HAS_SDCARD == 1 // use SD SPI host driver
|
#if HAS_SDCARD == 1 // use SD SPI host driver
|
||||||
useSDCard = MYSD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK);
|
useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK);
|
||||||
#elif HAS_SDCARD == 2 // use SD MMC host driver
|
#elif HAS_SDCARD == 2 // use SD MMC host driver
|
||||||
// enable internal pullups of sd-data lines
|
// enable internal pullups of sd-data lines
|
||||||
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA0), GPIO_PULLUP_ONLY);
|
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA0), GPIO_PULLUP_ONLY);
|
||||||
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA1), GPIO_PULLUP_ONLY);
|
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA1), GPIO_PULLUP_ONLY);
|
||||||
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA2), GPIO_PULLUP_ONLY);
|
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA2), GPIO_PULLUP_ONLY);
|
||||||
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA3), GPIO_PULLUP_ONLY);
|
gpio_set_pull_mode(gpio_num_t(SDCARD_DATA3), GPIO_PULLUP_ONLY);
|
||||||
useSDCard = MYSD.begin();
|
useSDCard = SD_MMC.begin();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (useSDCard) {
|
if (useSDCard) {
|
||||||
ESP_LOGI(TAG, "SD-card found");
|
ESP_LOGI(TAG, "SD-card found");
|
||||||
cardType = MYSD.cardType();
|
openFile();
|
||||||
cardSize = MYSD.cardSize() / (1024 * 1024);
|
return true;
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGI(TAG, "SD-card not found");
|
ESP_LOGI(TAG, "SD-card not found");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cardType == CARD_NONE) {
|
|
||||||
ESP_LOGI(TAG, "No SD card attached");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cardType == CARD_MMC) {
|
|
||||||
ESP_LOGI(TAG, "SD Card type: MMC");
|
|
||||||
} else if (cardType == CARD_SD) {
|
|
||||||
ESP_LOGI(TAG, "SD Card type: SDSC");
|
|
||||||
} else if (cardType == CARD_SDHC) {
|
|
||||||
ESP_LOGI(TAG, "SD Card type: SDHC");
|
|
||||||
} else {
|
|
||||||
ESP_LOGI(TAG, "SD Card type: UNKNOWN");
|
|
||||||
}
|
|
||||||
|
|
||||||
ESP_LOGI(TAG, "SD Card Size: %lluMB\n", cardSize);
|
|
||||||
|
|
||||||
openFile();
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void sdcard_close(void) {
|
void sdcard_close(void) {
|
||||||
@ -121,35 +96,50 @@ void openFile(void) {
|
|||||||
snprintf(bufferFilename, sizeof(bufferFilename), "/%s.csv", SDCARD_FILE_NAME);
|
snprintf(bufferFilename, sizeof(bufferFilename), "/%s.csv", SDCARD_FILE_NAME);
|
||||||
ESP_LOGI(TAG, "SD: looking for file <%s>", bufferFilename);
|
ESP_LOGI(TAG, "SD: looking for file <%s>", bufferFilename);
|
||||||
|
|
||||||
/*
|
#if HAS_SDCARD == 1
|
||||||
if (MYSD.exists(bufferFilename)) {
|
bool fileExists = SD.exists(bufferFilename);
|
||||||
if (MYSD.open(bufferFilename, FILE_APPEND))
|
#elif HAS_SDCARD == 2
|
||||||
useSDCard = true;
|
bool fileExists = SD_MMC.exists(bufferFilename);
|
||||||
} else {
|
#endif
|
||||||
ESP_LOGI(TAG, "SD: file does not exist, creating it");
|
|
||||||
if (MYSD.open(bufferFilename, FILE_WRITE))
|
|
||||||
useSDCard = true;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (!MYSD.exists(bufferFilename))
|
// file not exists, create it
|
||||||
ESP_LOGI(TAG, "SD: file does not exist, creating it");
|
if (!fileExists) {
|
||||||
|
ESP_LOGD(TAG, "SD: file not found, creating...");
|
||||||
|
|
||||||
if (MYSD.open(bufferFilename, FILE_WRITE))
|
#if HAS_SDCARD == 1
|
||||||
useSDCard = true;
|
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
|
||||||
|
#elif HAS_SDCARD == 2
|
||||||
|
fileSDCard = SD_MMC.open(bufferFilename, FILE_WRITE);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (useSDCard) {
|
if (fileSDCard) {
|
||||||
ESP_LOGI(TAG, "SD: file opened: <%s>", bufferFilename);
|
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
|
||||||
fileSDCard.print(SDCARD_FILE_HEADER);
|
fileSDCard.print(SDCARD_FILE_HEADER);
|
||||||
#if (defined BAT_MEASURE_ADC || defined HAS_PMU)
|
#if (defined BAT_MEASURE_ADC || defined HAS_PMU)
|
||||||
fileSDCard.print(SDCARD_FILE_HEADER_VOLTAGE); // for battery level data
|
fileSDCard.print(SDCARD_FILE_HEADER_VOLTAGE); // for battery level data
|
||||||
#endif
|
#endif
|
||||||
#if (HAS_SDS011)
|
#if (HAS_SDS011)
|
||||||
fileSDCard.print(SDCARD_FILE_HEADER_SDS011);
|
fileSDCard.print(SDCARD_FILE_HEADER_SDS011);
|
||||||
#endif
|
#endif
|
||||||
fileSDCard.println();
|
fileSDCard.println();
|
||||||
} else {
|
useSDCard = true;
|
||||||
ESP_LOGE(TAG, "SD: file not opened error");
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// file exists, append data
|
||||||
|
else {
|
||||||
|
ESP_LOGD(TAG, "SD: file found, opening...");
|
||||||
|
|
||||||
|
#if HAS_SDCARD == 1
|
||||||
|
fileSDCard = SD.open(bufferFilename, FILE_APPEND);
|
||||||
|
#elif HAS_SDCARD == 2
|
||||||
|
fileSDCard = SD_MMC.open(bufferFilename, FILE_APPEND);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (fileSDCard) {
|
||||||
|
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
|
||||||
|
useSDCard = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user