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.

0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 #ifndef _TASK_SDCARD_H
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2 #define _TASK_SDCARD_H
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * @file task_sdcard.h
4
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
6 * @brief SD/MMC driver. This driver is for a slot for the user on
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
7 * the front panel. It will detect an inserted card and then
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
8 * mount it. It also detects the removal of the card and then
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
9 * unmounts it. Be carefull, only do this in the main menu.
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
10 * Also, brew logging is handled here and finished brewlogs
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
11 * are copied to the SD card if it is mounted.
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
12 * Recipes to import must go into the /sdcard/recipe folder
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
13 * and have extension .xml and the contents be a beerxml file.
6d1f512cd074 Updated documentation
Michiel Broek <mbroek@mbse.eu>
parents: 1
diff changeset
14 * Backup and restore is also done to this card.
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
18 /**
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
19 * @brief Annotation types for the log graph.
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
20 */
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 typedef enum
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 ANNOTATION_STAGE = 0, ///< Annotate stage event
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24 ANNOTATION_EVENT, ///< Annotate an event
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 ANNOTATION_SYSTEM, ///< Annotate a system event.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 } ANNOTATION_TYPES;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27
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 * @brief Structure containing the information of the SD cards task.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 typedef struct {
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32 bool host_ok; ///< SPI host is Ok.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 bool card_present; ///< If card is present in the slot.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 char logfile[32]; ///< Current logfile name.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 } SDCARD_State;
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 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 * @brief JSON log data
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 typedef struct {
54
7b134c27fadb Upgraded esp-ide and compilers. Adjusted the sources for the new compiler warnings.
Michiel Broek <mbroek@mbse.eu>
parents: 4
diff changeset
41 char time[12]; ///< Time in the brew.
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 float mlt_sp; ///< MLT setpoint.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43 float mlt_pv; ///< MLT temperature.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 int mlt_power; ///< MLT power in %
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 int mlt_tempreached; ///< MLT temperature reached (0 or 1).
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 int pump_run; ///< Pump run (0 or 1).
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 float hlt_sp; ///< HLT setpoint.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 float hlt_pv; ///< HLT temperature.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 int hlt_power; ///< HLT power in %.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 char event[64]; ///< Event message.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 } JSON_log;
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52
62
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
53
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
54 /**
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
55 * @brief Write application messages to a logfile on the sdcard. The
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
56 * logfile is /sdcard/log/sysyyymmdd.log and is only used
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
57 * when the time is set from NTP and a card is mounted.
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
58 * Log messages are always copied to ESP_LOGI() too.
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
59 * @param tag is the log tag just as in ESP_LOGx().
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
60 * @param * is the formatted string.
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
61 */
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
62 void log_msg(const char *tag, const char *, ...);
2e90ada37476 Added syslog like logging on the sdcard for the manual and automatic processes.
Michiel Broek <mbroek@mbse.eu>
parents: 54
diff changeset
63
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 * @brief Begin a new logfile. The logfile is created and written to on
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 * the spiffs filesystem.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67 * @param t The time in seconds since the Epoch, to create the filename.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 void log_begin(time_t t);
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 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 * @brief Close an open logfile. The logfile is moved to the SD card if
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 * the card is present and mounted. Then, the temporary logfile
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 * is removed.
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 void log_close(void);
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 /**
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 * @brief Clean logfile directory /spiffs/log/
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 void log_clean(void);
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 * @brief Log to JSON logfile.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 void log_json(void);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87
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 * @brief Log annotations for the chart. These are stored in a temporary
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 * file and later when the logfile is closed they are merged in
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 * the main json logfile.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 * @param annotation_type The type of annotation, stage/event/system.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 * @param label The label text that will be seen in the chart.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 void log_annotation(int annotation_type, char *label);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 /**
1
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
98 * @brief Copy one file.
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
99 * @param ff The from filename
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
100 * @param tf The to filename
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
101 * @return 0 if success.
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
102 */
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
103 int FileCopy(char *ff, char *tf);
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
104
ad2c8b13eb88 Updated lots of doxygen comments
Michiel Broek <mbroek@mbse.eu>
parents: 0
diff changeset
105 /**
0
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 * @brief FreeRTOS sd card task.
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 */
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 void task_sdcard(void *);
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109
b74b0e4902c3 Initial checkin brewboard
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 #endif

mercurial