main/task_sdcard.c

Sun, 21 Oct 2018 13:07:50 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 21 Oct 2018 13:07:50 +0200
changeset 4
6d1f512cd074
parent 1
ad2c8b13eb88
child 6
e84200edc852
permissions
-rw-r--r--

Updated documentation

0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 * @file task_sdcard.c
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 * @brief SD/MMC driver. This driver is for a slot for the user on
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * the front panel. It will detect an inserted card and then
4
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
5 * mount it. It also detects the removal of the card and then
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
6 * unmounts it. Be carefull, only do this in the main menu.
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 * Also, brew logging is handled here and finished brewlogs
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * are copied to the SD card if it is mounted.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * Recipes to import must go into the /sdcard/recipe folder
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * and have extension .xml and the contents be a beerxml file.
4
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
11 * Backup and restore is also done to this card.
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 #include "vfs_fat_internal.h"
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 #include "driver/sdmmc_host.h"
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 #include "driver/sdspi_host.h"
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 #include "sdmmc_cmd.h"
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 #include "diskio.h"
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 #include "config.h"
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
25 SDCARD_State *sdcard_state; ///< SD card status
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
26 JSON_log *json_log; ///< JSON log array
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 EventGroupHandle_t xEventGroupSDcard; ///< SD card events.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 static const char *TAG = "task_sdcard";
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 static sdmmc_card_t* s_card = NULL;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 static uint8_t s_pdrv = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 static char * s_base_path = NULL;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 BYTE pdrv = 0xFF;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 #define SDCARD_HOST_SLOT VSPI_HOST ///< HSPI_HOST is used by the TFT
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
38 #define SDCARD_PIN_NUM_MISO 2 ///< MISO pin
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
39 #define SDCARD_PIN_NUM_MOSI 15 ///< MOSI pin
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
40 #define SDCARD_PIN_NUM_CLK 14 ///< CLOCK
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
41 #define SDCARD_PIN_NUM_CS 13 ///< Chip select pin
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 #define SDCARD_DMA_CHANNEL 2 ///< Channel 1 is used by the TFT
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 const int TASK_SDCARD_LOG_CLEAN = BIT0; ///< Clean spiffs logfile directory
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 const int TASK_SDCARD_LOG_CLOSE = BIT1; ///< Close the logfile.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 extern time_t now;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 extern struct tm timeinfo;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 void log_begin(time_t t)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55 struct tm timeinfo;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 * If there is an open logfile from an crashed brew, open that one.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 if (! strlen(sdcard_state->logfile) && strlen(runtime.Logfile)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 sprintf(sdcard_state->logfile, "%s", runtime.Logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 ESP_LOGI(TAG, "Resumed %s", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 localtime_r(&t, &timeinfo);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 if (timeinfo.tm_year > (2016 - 1900)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 // Valid time, construct the filename.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 strftime(sdcard_state->logfile, sizeof(sdcard_state->logfile), "br%y%m%d%H%M", &timeinfo);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 sprintf(sdcard_state->logfile, "brewlog");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 ESP_LOGI(TAG, "Create %s", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 sprintf(runtime.Logfile, "%s", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 void log_close(void)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 xEventGroupSetBits(xEventGroupSDcard, TASK_SDCARD_LOG_CLOSE);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 void log_clean(void)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 xEventGroupSetBits(xEventGroupSDcard, TASK_SDCARD_LOG_CLEAN);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 void log_json(void)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 char filename[32], strftime_buf[64];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 FILE *f;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 bool addcomma = true;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 if (strlen(sdcard_state->logfile)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99 sprintf(filename, "/spiffs/log/%s.json", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 f = fopen(filename, "r");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 if (f == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 // Create the file and add the header
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 f = fopen(filename, "a");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 if (f) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 strftime(strftime_buf, sizeof(strftime_buf), "%c", &timeinfo);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 fprintf(f, "{\n");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 fprintf(f, " \"brew\": [{\n");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 fprintf(f, " \"Recipe\":\"%s\",\n", recipe.Name);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109 fprintf(f, " \"Date\":\"%s\",\n", strftime_buf);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 fprintf(f, " \"brewdata\":[\n");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 addcomma = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 fclose(f);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 ESP_LOGE(TAG, "Failed to create %s error %d", filename, errno);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 return;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 fclose(f); // Was open for reading.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121 f = fopen(filename, "a");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 if (f) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 if (addcomma) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 fprintf(f, ",\n");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 addcomma = true;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 fprintf(f, " {\"MLT_sp\":\"%.3f\",\"MLT_pv\":\"%.3f\",\"MLT_pwm\":\"%d\",\"MLT_tr\":\"%d\",\"Pump\":\"%d\",",
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 json_log->mlt_sp, json_log->mlt_pv, json_log->mlt_power, json_log->mlt_tempreached, json_log->pump_run);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129 if (json_log->hlt_sp > 0.0) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 fprintf(f, "\"HLT_sp\":\"%.3f\",\"HLT_pv\":\"%.3f\",\"HLT_pwm\":\"%d\",", json_log->hlt_sp, json_log->hlt_pv, json_log->hlt_power);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132 fprintf(f, "\"Label\":\"%s\"}", json_log->time);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 printf("{\"MLT_sp\":\"%.3f\",\"MLT_pv\":\"%.3f\",\"MLT_pwm\":\"%d\",\"MLT_tr\":\"%d\",\"Pump\":\"%d\",",
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134 json_log->mlt_sp, json_log->mlt_pv, json_log->mlt_power, json_log->mlt_tempreached, json_log->pump_run);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 if (json_log->hlt_sp > 0.0) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 printf("\"HLT_sp\":\"%.3f\",\"HLT_pv\":\"%.3f\",\"HLT_pwm\":\"%d\",", json_log->hlt_sp, json_log->hlt_pv, json_log->hlt_power);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 printf("\"Label\":\"%s\"}\n", json_log->time);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 fclose(f);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 void log_annotation(int annotation_type, char *label)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 char filename[32];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 char bordercolor[9], color[9], pos[8];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 FILE *f;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 bool addcomma = true;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 if (strlen(sdcard_state->logfile)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154 sprintf(filename, "/spiffs/log/%s.anno", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 switch (annotation_type) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 case ANNOTATION_STAGE: snprintf(bordercolor, 8, "#8942f4");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 snprintf(color, 8, "#00215b");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 snprintf(pos, 7, "bottom");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160 break;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 case ANNOTATION_EVENT: snprintf(bordercolor, 8, "#42f445");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163 snprintf(color, 8, "#00215b");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 snprintf(pos, 7, "top");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165 break;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 case ANNOTATION_SYSTEM: snprintf(bordercolor, 8, "black");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 snprintf(color, 8, "red");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 snprintf(pos, 7, "center");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 break;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173 // Check if the file exists to see if we need to insert a comma.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 f = fopen(filename, "r");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 if (f == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 addcomma = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 fclose(f);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 f = fopen(filename, "a");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 if (f) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 if (addcomma) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 fprintf(f, ",\n");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 addcomma = true;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 fprintf(f, "{\"type\":\"line\",\"mode\":\"vertical\",\"scaleID\":\"x-axis-0\",\"value\":\"%s\",\"borderColor\":\"%s\",\"borderWidth\":2,\"label\":{\"backgroundColor\":\"%s\",\"content\":\"%s\",\"position\":\"%s\",\"enabled\":true}}", json_log->time, bordercolor, color, label, pos);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 fclose(f);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 printf( "{\"type\":\"line\",\"mode\":\"vertical\",\"scaleID\":\"x-axis-0\",\"value\":\"%s\",\"borderColor\":\"%s\",\"borderWidth\":2,\"label\":{\"backgroundColor\":\"%s\",\"content\":\"%s\",\"position\":\"%s\",\"enabled\":true}}\n", json_log->time, bordercolor, color, label, pos);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
196 /**
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
197 * @brief This is a local modified version of the esp_vfs_fat_sdmmc_mount() function in
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
198 * the FreeRTOS components library. It is here so we can better handle errors
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
199 * for our application.
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
200 * @param base_path The mount path
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
201 * @param host_config SPI host configuration
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
202 * @param slot_config Slot configuration
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
203 * @return Error condition.
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 esp_err_t my_vfs_fat_sdmmc_init(const char* base_path, const sdmmc_host_t* host_config, const void* slot_config)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 if (s_card != NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208 return ESP_ERR_INVALID_STATE;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 // connect SDMMC driver to FATFS
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 pdrv = 0xFF;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 if (ff_diskio_get_drive(&pdrv) != ESP_OK || pdrv == 0xFF) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 ESP_LOGI(TAG, "the maximum count of volumes is already mounted");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 return ESP_ERR_NO_MEM;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 s_base_path = strdup(base_path);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 if (!s_base_path) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 ESP_LOGI(TAG, "could not copy base_path");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 return ESP_ERR_NO_MEM;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 esp_err_t err = ESP_OK;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 s_card = malloc(sizeof(sdmmc_card_t));
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 if (s_card == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 err = ESP_ERR_NO_MEM;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 goto fail;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 err = (*host_config->init)();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 if (err != ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 ESP_LOGI(TAG, "host init returned rc=0x%x", err);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 goto fail;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 // configure SD slot
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 if (host_config->flags == SDMMC_HOST_FLAG_SPI) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238 err = sdspi_host_init_slot(host_config->slot, (const sdspi_slot_config_t*) slot_config);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 err = sdmmc_host_init_slot(host_config->slot, (const sdmmc_slot_config_t*) slot_config);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 if (err != ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 ESP_LOGI(TAG, "slot_config returned rc=0x%x", err);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 goto fail;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 return ESP_OK;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 fail:
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 host_config->deinit();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 free(s_card);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251 s_card = NULL;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 return err;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
257 /**
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
258 * @brief Mount SD card.
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
259 * @param base_path The mountpoint
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
260 * @param host_config SPI host configuration
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
261 * @param slot_config Slot configuration
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
262 * @param mount_config Mount configuration
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
263 * @param[out] out_card Card information
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
264 * @return Error condition
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
265 */
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 esp_err_t my_esp_vfs_fat_sdmmc_mount(const char* base_path,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267 const sdmmc_host_t* host_config,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 const void* slot_config,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 const esp_vfs_fat_mount_config_t* mount_config,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 sdmmc_card_t** out_card)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 FATFS* fs = NULL;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 esp_err_t err = ESP_OK;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275 if (s_card == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 return ESP_ERR_INVALID_STATE;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 // probe and initialize card
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280 err = sdmmc_card_init(host_config, s_card);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 if (err != ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 if (err != ESP_ERR_INVALID_RESPONSE) { // No card present, do not log
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 ESP_LOGI(TAG, "sdmmc_card_init failed 0x(%x)", err);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285 goto fail;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 if (out_card != NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288 *out_card = s_card;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 ff_diskio_register_sdmmc(pdrv, s_card);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292 s_pdrv = pdrv;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 ESP_LOGD(TAG, "using pdrv=%i", pdrv);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 char drv[3] = {(char)('0' + pdrv), ':', 0};
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 // connect FATFS to VFS
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 err = esp_vfs_fat_register(base_path, drv, mount_config->max_files, &fs);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 if (err == ESP_ERR_INVALID_STATE) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 // it's okay, already registered with VFS
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 } else if (err != ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 ESP_LOGI(TAG, "esp_vfs_fat_register failed 0x(%x)", err);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302 goto fail;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 // Try to mount partition
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306 FRESULT res = f_mount(fs, drv, 1);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 if (res != FR_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 err = ESP_FAIL;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 ESP_LOGD(TAG, "f_mount failed (%d)", res);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 goto fail;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 return ESP_OK;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 fail:
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 if (fs) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 f_mount(NULL, drv, 0);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 esp_vfs_fat_unregister_path(base_path);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 ff_diskio_unregister(pdrv);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 return err;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
325 /**
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
326 * @brief Unmount a mounted SD card,
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
327 * @return Error condition
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
328 */
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
329 esp_err_t my_esp_vfs_fat_sdmmc_unmount(void)
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331 if (s_card == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 return ESP_ERR_INVALID_STATE;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 // unmount
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 char drv[3] = {(char)('0' + s_pdrv), ':', 0};
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 f_mount(0, drv, 0);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 return ESP_OK;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 int FileCopy(char *ff, char *tf)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 FILE *f, *t;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 uint8_t buf[512];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346 size_t bytes;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348 f = fopen(ff, "r");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 if (f == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
350 ESP_LOGE(TAG, "FileCopy cannot open %s for read, error %d", ff, errno);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
351 return 1;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
352 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
353
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
354 t = fopen(tf, "w+");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
355 if (t == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
356 ESP_LOGE(TAG, "FileCopy cannot open %s for create/write, error %d", tf, errno);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
357 fclose(f);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
358 return 1;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
359 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
360
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
361 while ((bytes = fread(&buf, 1, 512, f))) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
362 fwrite(&buf, 1, bytes, t);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
363 vTaskDelay(10 / portTICK_PERIOD_MS);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
364 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
365
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
366 fclose(f);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
367 fclose(t);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
368 return 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
369 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
370
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
371
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
372
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
373 /**
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
374 * @brief Sync directories.
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
375 * @param fromdir Source directory
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
376 * @param todir Destination directory
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
377 */
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 void SyncDirs(char *fromdir, char *todir)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
380 char ff[64], tf[64];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
381 struct stat fs, ts;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
382 int rc;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
383
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
384 ESP_LOGI(TAG, "SyncDirs(%s, %s)", fromdir, todir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
385
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
386 DIR *dir = opendir(fromdir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
387 struct dirent* de = readdir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
388 while (de) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 if (de->d_type == DT_REG) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
390 sprintf(ff, "%s/%s", fromdir, de->d_name);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
391 if (stat(ff, &fs) == ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
392
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
393 sprintf(tf, "%s/%s", todir, de->d_name);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
394 if (stat(tf, &ts) != ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
395 ts.st_size = 0;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
396 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
397
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
398 if (fs.st_size && (fs.st_size != ts.st_size)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
399 rc = FileCopy(ff, tf);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
400 ESP_LOGI(TAG, "Copy %s to %s, %ld bytes, rc=%d", ff, todir, fs.st_size, rc);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
401 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
402 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
403 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
404 de = readdir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
405 vTaskDelay(50 / portTICK_PERIOD_MS);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
406 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
407 closedir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
408
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
409 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
410 * Now see if we need to remove files.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
411 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
412 dir = opendir(todir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
413 de = readdir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
414 while (de) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
415 sprintf(tf, "%s/%s", todir, de->d_name);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
416 sprintf(ff, "%s/%s", fromdir, de->d_name);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
417
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
418 if (stat(ff, &fs) != ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
419 if (unlink(tf) == ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
420 ESP_LOGI(TAG, "Removed %s", tf);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
421 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
422 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
423
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
424 de = readdir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
425 vTaskDelay(50 / portTICK_PERIOD_MS);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
426 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
427 closedir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
428 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
429
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
430
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
431
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
432 void task_sdcard(void *pvParameter)
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
433 {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
434 sdmmc_card_t* card;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
435 esp_err_t ret;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
436 EventBits_t uxBits;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
437 char filename[64];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
438
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
439 sdcard_state = malloc(sizeof(SDCARD_State));
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
440 sdcard_state->host_ok = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
441 sdcard_state->card_present = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
442 sdcard_state->logfile[0] = '\0';
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
443
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
444 json_log = malloc(sizeof(JSON_log));
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
445
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
446 ESP_LOGI(TAG, "Starting SD card");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
447 sdmmc_host_t host = SDSPI_HOST_DEFAULT();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
448 host.slot = SDCARD_HOST_SLOT; // HSPI_HOST is in use by the TFT.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
449 sdspi_slot_config_t slot_config = SDSPI_SLOT_CONFIG_DEFAULT();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
450 slot_config.gpio_miso = SDCARD_PIN_NUM_MISO;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
451 slot_config.gpio_mosi = SDCARD_PIN_NUM_MOSI;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
452 slot_config.gpio_sck = SDCARD_PIN_NUM_CLK;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
453 slot_config.gpio_cs = SDCARD_PIN_NUM_CS;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
454 slot_config.dma_channel = SDCARD_DMA_CHANNEL;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
455 // This initializes the slot without card detect (CD) and write protect (WP) signals.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
456 // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
457
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
458 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
459 * No errors from the sdmmc_cmd driver.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
460 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
461 esp_log_level_set("sdmmc_cmd", ESP_LOG_NONE);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
462
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
463 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
464 * Options for mounting the filesystem.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
465 * If format_if_mount_failed is set to true, SD card will be partitioned and
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
466 * formatted in case when mounting fails.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
467 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
468 esp_vfs_fat_sdmmc_mount_config_t mount_config = {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
469 .format_if_mount_failed = false,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
470 .max_files = 5,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
471 .allocation_unit_size = 16 * 1024
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
472 };
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
473
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
474 ret = my_vfs_fat_sdmmc_init("/sdcard", &host, &slot_config);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
475 if (ret == ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
476 ESP_LOGI(TAG, "SPI card interface ready");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
477 sdcard_state->host_ok = true;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
478 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
479 ESP_LOGE(TAG, "SPI card interface failed, abort task");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
480 vTaskDelete(NULL);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
481 return;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
482 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
483
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
484 xEventGroupSDcard = xEventGroupCreate();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
485
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
486 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
487 * Task loop, continues check of the inserted cards.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
488 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
489 while (1) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
490
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
491 if (sdcard_state->card_present == false) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
492 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
493 * If the card is not mounted, try it.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
494 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
495 ret = my_esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
496 if (ret == ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
497 ESP_LOGI(TAG, "SD card mounted on /sdcard");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
498 sdcard_state->card_present = true;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
499
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
500 DIR* dir = opendir("/sdcard/w/log");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
501 if (dir == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
502 ret = mkdir("/sdcard/w/log", 0755);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
503 printf("Dir created ret=%d\n", ret);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
504 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
505 closedir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
506 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
507
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
508
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
509 SyncDirs("/sdcard/w", "/spiffs/w");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
510 SyncDirs("/sdcard/w/js", "/spiffs/w/js");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
511 SyncDirs("/sdcard/w/css", "/spiffs/w/css");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
512 // SyncDirs("/sdcard/w/js/modl" , "/spiffs/w/js/modl"); //
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
513 // SyncDirs("/sdcard/w/js/utils", "/spiffs/w/js/utils");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
514 // SyncDirs("/sdcard/w/js/zlib", "/spiffs/w/js/zlib");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
515 // SyncDirs("/sdcard/w/core", "/spiffs/w/core");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
516 // SyncDirs("/sdcard/w/core/input", "/spiffs/w/core/input");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
517 // SyncDirs("/sdcard/w/core/util", "/spiffs/w/core/util");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
518 // SyncDirs("/sdcard/w/app", "/spiffs/w/app");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
519 // SyncDirs("/sdcard/w/app/images", "/spiffs/w/app/images");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
520 // SyncDirs("/sdcard/w/app/locale", "/spiffs/w/app/locale");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
521 // SyncDirs("/sdcard/w/app/sounds", "/spiffs/w/app/sounds"); //
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
522 SyncDirs("/sdcard/w/app/styles", "/spiffs/w/app/styles");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
523 // SyncDirs("/sdcard/fonts", "/spiffs/fonts"); //
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
524
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
525 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
526 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
527 /*
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
528 * Check if the mounted card is still in the slot.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
529 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
530 DIR* dir = opendir("/sdcard/w/log");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
531 if (dir == NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
532 ESP_LOGI(TAG, "SD card missing, unmount");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
533 my_esp_vfs_fat_sdmmc_unmount();
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
534 sdcard_state->card_present = false;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
535 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
536 closedir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
537 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
538 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
539
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
540 uxBits = xEventGroupWaitBits(xEventGroupSDcard,
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
541 TASK_SDCARD_LOG_CLEAN | TASK_SDCARD_LOG_CLOSE, pdFALSE, pdFALSE, 1000 / portTICK_PERIOD_MS);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
542
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
543 if (uxBits & TASK_SDCARD_LOG_CLEAN) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
544 DIR *dir = opendir("/spiffs/log");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
545 char lf[32];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
546
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
547 if (dir != NULL) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
548 struct dirent *de = readdir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
549 while (de) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
550 sprintf(lf, "/spiffs/log/%s", de->d_name);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
551 if (unlink(lf) == ESP_OK) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
552 ESP_LOGI(TAG, "Removed old %s", lf);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
553 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
554 de = readdir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
555 vTaskDelay(2 / portTICK_PERIOD_MS);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
556 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
557 closedir(dir);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
558 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
559 xEventGroupClearBits(xEventGroupSDcard, TASK_SDCARD_LOG_CLEAN);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
560 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
561
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
562 if (uxBits & TASK_SDCARD_LOG_CLOSE) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
563 // Close the logfile.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
564 if (strlen(sdcard_state->logfile) && (sdcard_state->card_present == true)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
565 ESP_LOGI(TAG, "Closing logfile");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
566 char destname[64];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
567 sprintf(destname, "/sdcard/w/log");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
568 int rc = mkdir(destname, 0755);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
569 if (rc && (errno != EEXIST)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
570 ESP_LOGE(TAG, "Cannot create %s error %d", destname, errno);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
571 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
572 sprintf(filename, "/spiffs/log/%s.json", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
573 // First close the JSON data records
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
574 FILE *f = fopen(filename, "a+");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
575 if (f) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
576 fprintf(f, " ],\n"); // End of brewdata
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
577 fprintf(f, " \"annotations\":[\n");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
578 // Insert annotation records
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
579 sprintf(destname, "/spiffs/log/%s.anno", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
580 FILE *a = fopen(destname, "r");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
581 char buf[256];
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
582 if (a) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
583 while(true) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
584 if (fgets(buf, sizeof(buf), a)) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
585 fprintf(f, "%s", buf);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
586 } else {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
587 break;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
588 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
589 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
590 fclose(a);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
591 unlink(destname);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
592 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
593 fprintf(f, " ]\n"); // End of annotations
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
594 fprintf(f, " }]\n"); // End of brew
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
595 fprintf(f, "}\n");
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
596 fclose(f);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
597 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
598 sprintf(destname, "/sdcard/w/log/%s.json", sdcard_state->logfile);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
599 if (FileCopy(filename, destname) == 0) {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
600 ESP_LOGI(TAG, "JSON file copied to %s", destname);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
601 unlink(filename);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
602 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
603 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
604 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
605 sdcard_state->logfile[0] = '\0'; // Clear logfile name
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
606 runtime.Logfile[0] = '\0';
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
607 xEventGroupClearBits(xEventGroupSDcard, TASK_SDCARD_LOG_CLOSE);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
608 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
609 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
610 }
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
611
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
612

mercurial