SD card reader native mode added
This commit is contained in:
parent
2b46a69dbe
commit
6e487983b5
@ -207,7 +207,10 @@ There in the sensor configuration select "TheThingsNetwork" and set Decoding Pro
|
|||||||
# SD-card
|
# SD-card
|
||||||
Data can be stored on an SD-card if one is availabe. Simply choose the file in src/hal and add the following lines to your hal-file:
|
Data can be stored on an SD-card if one is availabe. Simply choose the file in src/hal and add the following lines to your hal-file:
|
||||||
|
|
||||||
#define HAS_SDCARD 1 // this board has an SD-card-reader/writer
|
#define HAS_SDCARD 1 // this board has an SD-card-reader/writer, with SPI interface
|
||||||
|
OR
|
||||||
|
#define HAS_SDCARD 2 // this board has an SD-card-reader/writer, using native SD interface
|
||||||
|
|
||||||
// Pins for SD-card
|
// Pins for SD-card
|
||||||
#define SDCARD_CS (13) // fill in the correct numbers for your board
|
#define SDCARD_CS (13) // fill in the correct numbers for your board
|
||||||
#define SDCARD_MOSI (15)
|
#define SDCARD_MOSI (15)
|
||||||
|
@ -4,14 +4,37 @@
|
|||||||
#include <globals.h>
|
#include <globals.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
|
|
||||||
|
#if HAS_SDCARD == 1
|
||||||
#include <mySD.h>
|
#include <mySD.h>
|
||||||
|
#elif HAS_SDCARD == 2
|
||||||
|
#include <SD_MMC.h>
|
||||||
|
#else
|
||||||
|
#error HAS_SDCARD unknown card reader value, must be either 1 or 2
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "sds011read.h"
|
#include "sds011read.h"
|
||||||
|
|
||||||
#define SDCARD_FILE_NAME "paxcount.%02d"
|
#ifndef SDCARD_CS
|
||||||
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"
|
#define SDCARD_CS SS
|
||||||
|
#endif
|
||||||
|
|
||||||
bool sdcard_init( void );
|
#ifndef SDCARD_MOSI
|
||||||
void sdcardWriteData( uint16_t, uint16_t);
|
#define SDCARD_MOSI MOSI
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SDCARD_MISO
|
||||||
|
#define SDCARD_MISO MISO
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef SDCARD_SCLK
|
||||||
|
#define SDCARD_SCLK SCK
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SDCARD_FILE_NAME "/paxcount.%02d"
|
||||||
|
#define SDCARD_FILE_HEADER "date, time, wifi, bluet"
|
||||||
|
|
||||||
|
bool sdcard_init(void);
|
||||||
|
void sdcardWriteData(uint16_t, uint16_t);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -14,12 +14,19 @@ static void createFile(void);
|
|||||||
File fileSDCard;
|
File fileSDCard;
|
||||||
|
|
||||||
bool sdcard_init() {
|
bool sdcard_init() {
|
||||||
ESP_LOGD(TAG, "looking for SD-card...");
|
ESP_LOGI(TAG, "looking for SD-card...");
|
||||||
|
#if HAS_SDCARD == 1
|
||||||
|
pinMode(SS, OUTPUT);
|
||||||
useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK);
|
useSDCard = SD.begin(SDCARD_CS, SDCARD_MOSI, SDCARD_MISO, SDCARD_SCLK);
|
||||||
if (useSDCard)
|
#elif HAS_SDCARD == 2
|
||||||
|
useSDCard = SD_MMC.begin();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (useSDCard) {
|
||||||
|
ESP_LOGI(TAG, "SD-card found");
|
||||||
createFile();
|
createFile();
|
||||||
else
|
} else
|
||||||
ESP_LOGD(TAG, "SD-card not found");
|
ESP_LOGI(TAG, "SD-card not found");
|
||||||
return useSDCard;
|
return useSDCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,10 +71,22 @@ void createFile(void) {
|
|||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
sprintf(bufferFilename, SDCARD_FILE_NAME, i);
|
sprintf(bufferFilename, SDCARD_FILE_NAME, i);
|
||||||
ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename);
|
ESP_LOGD(TAG, "SD: looking for file <%s>", bufferFilename);
|
||||||
|
|
||||||
|
#if HAS_SDCARD == 1
|
||||||
bool fileExists = SD.exists(bufferFilename);
|
bool fileExists = SD.exists(bufferFilename);
|
||||||
|
#elif HAS_SDCARD == 2
|
||||||
|
bool fileExists = SD_MMC.exists(bufferFilename);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (!fileExists) {
|
if (!fileExists) {
|
||||||
ESP_LOGD(TAG, "SD: file does not exist: opening");
|
ESP_LOGD(TAG, "SD: file does not exist: opening");
|
||||||
|
|
||||||
|
#if HAS_SDCARD == 1
|
||||||
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
|
fileSDCard = SD.open(bufferFilename, FILE_WRITE);
|
||||||
|
#elif HAS_SDCARD == 2
|
||||||
|
fileSDCard = SD_MMC.open(bufferFilename, FILE_WRITE);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (fileSDCard) {
|
if (fileSDCard) {
|
||||||
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
|
ESP_LOGD(TAG, "SD: name opened: <%s>", bufferFilename);
|
||||||
fileSDCard.print(SDCARD_FILE_HEADER);
|
fileSDCard.print(SDCARD_FILE_HEADER);
|
||||||
|
Loading…
Reference in New Issue
Block a user