main/task_sdcard.h

Sat, 06 Jun 2020 13:28:46 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 06 Jun 2020 13:28:46 +0200
changeset 77
66c77497d86d
parent 62
2e90ada37476
permissions
-rw-r--r--

Changed the recipe database so that it is expandable, version 2. More mash fields and allow 16 steps. Allow 20 Additions. Removed separate mash steps from the state machine, the steps are moved to the runtime data. There is no fixed step number for mashout anymore. There is no fixed step for mash-in anymore, just use the first step and heat to the infusion temperature. After malt add, switch to the normal step temperature. Implemented decoction steps.

#ifndef	_TASK_SDCARD_H
#define	_TASK_SDCARD_H

/**
 * @file task_sdcard.h
 * @brief SD/MMC driver. This driver is for a slot for the user on
 *        the front panel. It will detect an inserted card and then
 *        mount it. It also detects the removal of the card and then
 *        unmounts it. Be carefull, only do this in the main menu.
 *        Also, brew logging is handled here and finished brewlogs
 *        are copied to the SD card if it is mounted.
 *        Recipes to import must go into the /sdcard/recipe folder
 *        and have extension .xml and the contents be a beerxml file.
 *        Backup and restore is also done to this card.
 */


/**
 * @brief Annotation types for the log graph.
 */
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[12];		///< 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 Write application messages to a logfile on the sdcard. The
 *        logfile is /sdcard/log/sysyyymmdd.log and is only used
 *        when the time is set from NTP and a card is mounted.
 *        Log messages are always copied to ESP_LOGI() too.
 * @param tag is the log tag just as in ESP_LOGx().
 * @param * is the formatted string.
 */
void log_msg(const char *tag, const char *, ...);

/**
 * @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 Copy one file.
 * @param ff The from filename
 * @param tf The to filename
 * @return 0 if success.
 */
int FileCopy(char *ff, char *tf);

/**
 * @brief FreeRTOS sd card task. 
 */
void task_sdcard(void *);

#endif

mercurial