diff -r 000000000000 -r b74b0e4902c3 main/task_sdcard.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main/task_sdcard.h Sat Oct 20 13:23:15 2018 +0200 @@ -0,0 +1,80 @@ +#ifndef _TASK_SDCARD_H +#define _TASK_SDCARD_H + +/** + * @file task_sdcard.h + * @brief The interface to the FreeRTOS SD/MMC card task. + */ + + +typedef enum +{ + ANNOTATION_STAGE = 0, ///< Annotate stage event + ANNOTATION_EVENT, ///< Annotate an event + ANNOTATION_SYSTEM, ///< Annotate a system event. +} ANNOTATION_TYPES; + +/** + * @brief Structure containing the information of the SD cards task. + */ +typedef struct { + bool host_ok; ///< SPI host is Ok. + bool card_present; ///< If card is present in the slot. + char logfile[32]; ///< Current logfile name. +} SDCARD_State; + +/** + * @brief JSON log data + */ +typedef struct { + char time[9]; ///< Time in the brew. + float mlt_sp; ///< MLT setpoint. + float mlt_pv; ///< MLT temperature. + int mlt_power; ///< MLT power in % + int mlt_tempreached; ///< MLT temperature reached (0 or 1). + int pump_run; ///< Pump run (0 or 1). + float hlt_sp; ///< HLT setpoint. + float hlt_pv; ///< HLT temperature. + int hlt_power; ///< HLT power in %. + char event[64]; ///< Event message. +} JSON_log; + +/** + * @brief Begin a new logfile. The logfile is created and written to on + * the spiffs filesystem. + * @param t The time in seconds since the Epoch, to create the filename. + */ +void log_begin(time_t t); + +/** + * @brief Close an open logfile. The logfile is moved to the SD card if + * the card is present and mounted. Then, the temporary logfile + * is removed. + */ +void log_close(void); + +/** + * @brief Clean logfile directory /spiffs/log/ + */ +void log_clean(void); + +/** + * @brief Log to JSON logfile. + */ +void log_json(void); + +/** + * @brief Log annotations for the chart. These are stored in a temporary + * file and later when the logfile is closed they are merged in + * the main json logfile. + * @param annotation_type The type of annotation, stage/event/system. + * @param label The label text that will be seen in the chart. + */ +void log_annotation(int annotation_type, char *label); + +/** + * @brief FreeRTOS sd card task. + */ +void task_sdcard(void *); + +#endif