main/task_sdcard.c

changeset 54
7b134c27fadb
parent 33
dd52aecfc19d
child 61
c7b8a9931b59
equal deleted inserted replaced
53:cf91a3a20d0d 54:7b134c27fadb
14 14
15 #include "vfs_fat_internal.h" 15 #include "vfs_fat_internal.h"
16 #include "driver/sdmmc_host.h" 16 #include "driver/sdmmc_host.h"
17 #include "driver/sdspi_host.h" 17 #include "driver/sdspi_host.h"
18 #include "sdmmc_cmd.h" 18 #include "sdmmc_cmd.h"
19 #include "diskio.h" 19 #include "diskio_impl.h"
20 #include "diskio_sdmmc.h"
20 21
21 #include "config.h" 22 #include "config.h"
22 23
23 24
24 25
89 90
90 91
91 92
92 void log_json(void) 93 void log_json(void)
93 { 94 {
94 char filename[32], strftime_buf[64]; 95 char filename[64], strftime_buf[64];
95 FILE *f; 96 FILE *f;
96 bool addcomma = true; 97 bool addcomma = true;
97 98
98 if (strlen(sdcard_state->logfile)) { 99 if (strlen(sdcard_state->logfile)) {
99 sprintf(filename, "/spiffs/log/%s.json", sdcard_state->logfile); 100 sprintf(filename, "/spiffs/log/%s.json", sdcard_state->logfile);
137 138
138 139
139 140
140 void log_annotation(int annotation_type, char *label) 141 void log_annotation(int annotation_type, char *label)
141 { 142 {
142 char filename[32]; 143 char filename[64];
143 char bordercolor[9], color[9], pos[8]; 144 char bordercolor[9], color[9], pos[8];
144 FILE *f; 145 FILE *f;
145 bool addcomma = true; 146 bool addcomma = true;
146 int Hour = (TimeBrewing / 3600); 147 int Hour = (TimeBrewing / 3600);
147 int Minute = ((TimeBrewing % 3600) / 60); 148 int Minute = ((TimeBrewing % 3600) / 60);
172 addcomma = false; 173 addcomma = false;
173 } else { 174 } else {
174 fclose(f); 175 fclose(f);
175 } 176 }
176 177
177 snprintf(json_log->time, 8, "%02d:%02d", Hour, Minute); 178 snprintf(json_log->time, 11, "%02d:%02d", Hour, Minute);
178 f = fopen(filename, "a"); 179 f = fopen(filename, "a");
179 if (f) { 180 if (f) {
180 if (addcomma) { 181 if (addcomma) {
181 fprintf(f, ",\n"); 182 fprintf(f, ",\n");
182 } 183 }
463 char lf[32]; 464 char lf[32];
464 465
465 if (dir != NULL) { 466 if (dir != NULL) {
466 struct dirent *de = readdir(dir); 467 struct dirent *de = readdir(dir);
467 while (de) { 468 while (de) {
468 sprintf(lf, "/spiffs/log/%s", de->d_name); 469 sprintf(lf, "/spiffs/log/");
470 strncat(lf, de->d_name, 31 - strlen(lf));
469 if (unlink(lf) == ESP_OK) { 471 if (unlink(lf) == ESP_OK) {
470 ESP_LOGI(TAG, "Removed old %s", lf); 472 ESP_LOGI(TAG, "Removed old %s", lf);
471 } 473 }
472 de = readdir(dir); 474 de = readdir(dir);
473 vTaskDelay(2 / portTICK_PERIOD_MS); 475 vTaskDelay(2 / portTICK_PERIOD_MS);

mercurial