summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Buesch <m@bues.ch>2014-12-08 19:51:38 +0100
committerMichael Buesch <m@bues.ch>2014-12-08 19:51:38 +0100
commite4f51c11ee86cf3c33af8843d03bec390fe20a12 (patch)
tree144adebb24ce368e88580e20bc6236a5a79c084b
parentd18dbde523cf556ecb080bae498419379bab8796 (diff)
downloadmoistcontrol-e4f51c11ee86cf3c33af8843d03bec390fe20a12.zip
moistcontrol-e4f51c11ee86cf3c33af8843d03bec390fe20a12.tar.xz
Simplify logging
Signed-off-by: Michael Buesch <m@bues.ch>
-rw-r--r--firmware/controller.c14
-rw-r--r--firmware/log.c22
-rw-r--r--firmware/log.h11
-rw-r--r--firmware/main.c11
4 files changed, 30 insertions, 28 deletions
diff --git a/firmware/controller.c b/firmware/controller.c
index 2baf6e7..65debe9 100644
--- a/firmware/controller.c
+++ b/firmware/controller.c
@@ -208,12 +208,7 @@ static void pot_info(struct flowerpot *pot,
return;
}
- /* Construct the log data structure. */
- log_init(&log, log_class);
- log.code = log_code;
- log.data = log_data;
- /* Append the log message to the log queue. */
- log_append(&log);
+ log_event(log_class, log_code, log_data);
}
/* Emit a log message, if verbose logging is enabled.
@@ -857,14 +852,9 @@ void controller_work(enum onoff_state hw_switch)
/* No freeze timeout. */
return;
} else {
- struct log_item log;
-
/* Timeout. Disable freeze. */
cont.frozen = 0;
-
- log_init(&log, LOG_ERROR);
- log.code = LOG_ERR_FREEZE;
- log_append(&log);
+ log_error(LOG_ERR_FREEZE, 0);
}
}
diff --git a/firmware/log.c b/firmware/log.c
index cdfbed2..e3b3a73 100644
--- a/firmware/log.c
+++ b/firmware/log.c
@@ -25,7 +25,7 @@
/* Size of the log ringbuffer, in number of elements. */
-#define LOG_BUFFER_SIZE 32
+#define LOG_BUFFER_SIZE 24
/* Log buffer */
@@ -132,3 +132,23 @@ bool log_pop(struct log_item *item)
return 1;
}
+
+void log_event(uint8_t type, uint8_t code, uint8_t data)
+{
+ struct log_item log;
+
+ log_init(&log, type);
+ log.code = code;
+ log.data = data;
+ log_append(&log);
+}
+
+void log_info(uint8_t code, uint8_t data)
+{
+ log_event(LOG_INFO, code, data);
+}
+
+void log_error(uint8_t code, uint8_t data)
+{
+ log_event(LOG_ERROR, code, data);
+}
diff --git a/firmware/log.h b/firmware/log.h
index d212753..073ad4e 100644
--- a/firmware/log.h
+++ b/firmware/log.h
@@ -67,14 +67,13 @@ void log_init(struct log_item *item, uint8_t type);
void log_append(const struct log_item *item);
bool log_pop(struct log_item *item);
+void log_event(uint8_t type, uint8_t code, uint8_t data);
+
+void log_info(uint8_t code, uint8_t data);
+void log_error(uint8_t code, uint8_t data);
static inline void log_debug(uint8_t data)
{
- struct log_item item;
-
- log_init(&item, LOG_INFO);
- item.code = LOG_INFO_DEBUG;
- item.data = data;
- log_append(&item);
+ log_info(LOG_INFO_DEBUG, data);
}
#endif /* LOG_H_ */
diff --git a/firmware/main.c b/firmware/main.c
index a5c48f7..44f1fbd 100644
--- a/firmware/main.c
+++ b/firmware/main.c
@@ -377,17 +377,10 @@ static enum onoff_state handle_onoffswitch(void)
if (hw_switch == ONOFF_SWITCHED_OFF) {
/* Log the 'off'-event. */
- log_init(&log, LOG_INFO);
- log.code = LOG_INFO_HWONOFF;
- log.data = 0;
- log_append(&log);
-
+ log_info(LOG_INFO_HWONOFF, 0);
} else if (hw_switch == ONOFF_SWITCHED_ON) {
/* Log the 'on'-event. */
- log_init(&log, LOG_INFO);
- log.code = LOG_INFO_HWONOFF;
- log.data = 1;
- log_append(&log);
+ log_info(LOG_INFO_HWONOFF, 1);
/* Disable notification LED.
* This will also clear notification messages from other
bues.ch cgit interface