flush to sd card before sleep

This commit is contained in:
cyberman54 2022-01-29 13:47:59 +01:00
parent db60afe05d
commit 51c6a41180
4 changed files with 15 additions and 2 deletions

View File

@ -8,6 +8,7 @@
#include "lorawan.h" #include "lorawan.h"
#include "display.h" #include "display.h"
#include "power.h" #include "power.h"
#include "sdcard.h"
void reset_rtc_vars(void); void reset_rtc_vars(void);
void do_reset(bool warmstart); void do_reset(bool warmstart);

View File

@ -61,7 +61,8 @@
#define SDCARD_FILE_HEADER_VOLTAGE ",voltage" #define SDCARD_FILE_HEADER_VOLTAGE ",voltage"
#endif #endif
bool sdcard_init(void); bool sdcard_init(bool create = true);
bool sdcard_close(void);
void sdcardWriteData(uint16_t, uint16_t, uint16_t = 0); void sdcardWriteData(uint16_t, uint16_t, uint16_t = 0);
#endif // _SDCARD_H #endif // _SDCARD_H

View File

@ -126,6 +126,11 @@ void enter_deepsleep(const uint64_t wakeup_sec, gpio_num_t wakeup_gpio) {
sds011_sleep(); sds011_sleep();
#endif #endif
// flush & close sd card, if we have
#if (HAS_SDCARD)
sdcard_close();
#endif
// wait a while (max 100 sec) to clear send queues // wait a while (max 100 sec) to clear send queues
ESP_LOGI(TAG, "Waiting until send queues are empty..."); ESP_LOGI(TAG, "Waiting until send queues are empty...");
for (i = 100; i > 0; i--) { for (i = 100; i > 0; i--) {

View File

@ -13,7 +13,13 @@ static void createFile(void);
File fileSDCard; File fileSDCard;
bool sdcard_init() { bool sdcard_close(void) {
ESP_LOGD(TAG, "unmounting SD-card");
fileSDCard.flush();
fileSDCard.end();
}
bool sdcard_init(bool create) {
ESP_LOGI(TAG, "looking for SD-card..."); 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