tesseract++ 0.0.1
N-dimensional tensor library for embedded systems
Loading...
Searching...
No Matches
arduino_serial_error_handler.h
Go to the documentation of this file.
1#pragma once
2#include <Arduino.h>
4
6{
7public:
8 static void log(const std::string &msg, ErrorLevel level)
9 {
10 const char *prefix;
11 switch (level)
12 {
14 prefix = "";
15 break;
17 prefix = "[INFO] ";
18 break;
20 prefix = "[WARN] ";
21 break;
23 prefix = "[ERROR] ";
24 break;
26 prefix = "[FATAL] ";
27 break;
28 }
29 Serial.print(prefix);
30 Serial.println(msg.c_str());
31 }
32
33 template <typename... Args>
34 static void log(ErrorLevel level, Args &&...args)
35 {
36 const char *prefix;
37 switch (level)
38 {
40 prefix = "";
41 break;
43 prefix = "[INFO] ";
44 break;
46 prefix = "[WARN] ";
47 break;
49 prefix = "[ERROR] ";
50 break;
52 prefix = "[FATAL] ";
53 break;
54 }
55 Serial.print(prefix);
56 (Serial.print(forward<Args>(args)), ...);
57 Serial.println();
58 }
59
60 template <typename... Args>
61 [[noreturn]] static void error(Args &&...args)
62 {
63 log(ErrorLevel::Fatal, forward<Args>(args)...);
64 while (true)
65 ; // halt forever
66 }
67};
Definition arduino_serial_error_handler.h:6
static void error(Args &&...args)
Definition arduino_serial_error_handler.h:61
static void log(const std::string &msg, ErrorLevel level)
Definition arduino_serial_error_handler.h:8
static void log(ErrorLevel level, Args &&...args)
Definition arduino_serial_error_handler.h:34
ErrorLevel
Definition error_handler.h:5