Moved the logger into its own project
This commit is contained in:
+5
-1
@@ -24,4 +24,8 @@ build_unflags = -std=gnu++11
|
|||||||
# -Ilib/u8g2/cppsrc
|
# -Ilib/u8g2/cppsrc
|
||||||
board_build.arduino.memory_type = qio_opi
|
board_build.arduino.memory_type = qio_opi
|
||||||
|
|
||||||
lib_deps = ../eslabsCurses/
|
lib_deps =
|
||||||
|
../lib/logger/
|
||||||
|
../lib/eslabsCurses/
|
||||||
|
|
||||||
|
lib_extra_dirs = ../lib
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include "walkieTalkie.h"
|
#include "walkieTalkie.h"
|
||||||
#include "HardwareSerial.h"
|
#include "HardwareSerial.h"
|
||||||
#include "logger/logger.h"
|
#include "logger.h"
|
||||||
#include "communication/commands.h"
|
#include "communication/commands.h"
|
||||||
#include "communication/communication.h"
|
#include "communication/communication.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|||||||
@@ -1,48 +0,0 @@
|
|||||||
#include "logger.h"
|
|
||||||
#include "HardwareSerial.h"
|
|
||||||
|
|
||||||
namespace Logger {
|
|
||||||
inline HardwareSerial& out() {
|
|
||||||
return Serial2;
|
|
||||||
}
|
|
||||||
|
|
||||||
void WritePrefix(LogLevel lvl) {
|
|
||||||
switch (lvl) {
|
|
||||||
case Error: out().print(F("\r[ERR] ")); break;
|
|
||||||
case Warn: out().print(F("\r[WRN] ")); break;
|
|
||||||
case Info: out().print(F("\r[INF] ")); break;
|
|
||||||
case Debug: out().print(F("\r[DBG] ")); break;
|
|
||||||
case Trace: out().print(F("\r[TRC] ")); break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VPrintf(const char* fmt, va_list args) {
|
|
||||||
char buffer[128];
|
|
||||||
vsnprintf(buffer, sizeof(buffer), fmt, args);
|
|
||||||
out().print(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Printf(const char* fmt, ...) {
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
VPrintf(fmt, args);
|
|
||||||
va_end(args);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Printf(const __FlashStringHelper* fmt, ...) {
|
|
||||||
char buffer[128];
|
|
||||||
|
|
||||||
va_list args;
|
|
||||||
va_start(args, fmt);
|
|
||||||
vsnprintf_P(buffer, sizeof(buffer),
|
|
||||||
reinterpret_cast<const char*>(fmt), args);
|
|
||||||
va_end(args);
|
|
||||||
|
|
||||||
out().print(buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Initialize(int8_t rx, int8_t tx) {
|
|
||||||
Serial2.begin(115200, SERIAL_8N1, rx, tx);
|
|
||||||
Serial2.flush();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
@@ -1,82 +0,0 @@
|
|||||||
#ifndef __LOGGER__
|
|
||||||
#define __LOGGER__
|
|
||||||
|
|
||||||
#include <Arduino.h>
|
|
||||||
#include <cstdint>
|
|
||||||
|
|
||||||
#define LOG_LEVEL_ERROR 0
|
|
||||||
#define LOG_LEVEL_WARN 1
|
|
||||||
#define LOG_LEVEL_INFO 2
|
|
||||||
#define LOG_LEVEL_DEBUG 3
|
|
||||||
#define LOG_LEVEL_TRACE 4
|
|
||||||
|
|
||||||
#define LOG_ENABLED(lvl) ((lvl) <= LOG_LEVEL)
|
|
||||||
|
|
||||||
#if LOG_ENABLED(LOG_LEVEL_ERROR)
|
|
||||||
#define LOG_ERROR(fmt, ...) \
|
|
||||||
do { \
|
|
||||||
Logger::WritePrefix(Logger::Error); \
|
|
||||||
Logger::Printf(fmt, ##__VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define LOG_ERROR(...) do {} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LOG_ENABLED(LOG_LEVEL_WARN)
|
|
||||||
#define LOG_WARN(fmt, ...) \
|
|
||||||
do { \
|
|
||||||
Logger::WritePrefix(Logger::Warn); \
|
|
||||||
Logger::Printf(fmt, ##__VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define LOG_WARN(...) do {} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LOG_ENABLED(LOG_LEVEL_INFO)
|
|
||||||
#define LOG_INFO(fmt, ...) \
|
|
||||||
do { \
|
|
||||||
Logger::WritePrefix(Logger::Info); \
|
|
||||||
Logger::Printf(fmt, ##__VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define LOG_INFO(...) do {} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LOG_ENABLED(LOG_LEVEL_DEBUG)
|
|
||||||
#define LOG_DEBUG(fmt, ...) \
|
|
||||||
do { \
|
|
||||||
Logger::WritePrefix(Logger::Debug); \
|
|
||||||
Logger::Printf(fmt, ##__VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define LOG_DEBUG(...) do {} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if LOG_ENABLED(LOG_LEVEL_TRACE)
|
|
||||||
#define LOG_TRACE(fmt, ...) \
|
|
||||||
do { \
|
|
||||||
Logger::WritePrefix(Logger::Trace); \
|
|
||||||
Logger::Printf(fmt, ##__VA_ARGS__); \
|
|
||||||
} while (0)
|
|
||||||
#else
|
|
||||||
#define LOG_TRACE(...) do {} while (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Logger {
|
|
||||||
enum LogLevel : uint8_t {
|
|
||||||
Error = LOG_LEVEL_ERROR,
|
|
||||||
Warn = LOG_LEVEL_WARN,
|
|
||||||
Info = LOG_LEVEL_INFO,
|
|
||||||
Debug = LOG_LEVEL_DEBUG,
|
|
||||||
Trace = LOG_LEVEL_TRACE
|
|
||||||
};
|
|
||||||
|
|
||||||
void Initialize(int8_t rx, int8_t tx);
|
|
||||||
|
|
||||||
void WritePrefix(LogLevel lvl);
|
|
||||||
void VPrintf(const char* fmt, va_list args);
|
|
||||||
void Printf(const char* fmt, ...);
|
|
||||||
void Printf(const __FlashStringHelper* fmt, ...);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
+1
-18
@@ -16,7 +16,7 @@ to have more ways to run analytics
|
|||||||
#include "communication/commands.h"
|
#include "communication/commands.h"
|
||||||
#include "communication/packets.h"
|
#include "communication/packets.h"
|
||||||
#include "communication/walkieTalkie.h"
|
#include "communication/walkieTalkie.h"
|
||||||
#include "logger/logger.h"
|
#include "logger.h"
|
||||||
#include "values.h"
|
#include "values.h"
|
||||||
#include "windowPool.h"
|
#include "windowPool.h"
|
||||||
// #include "UIDrawing.h"
|
// #include "UIDrawing.h"
|
||||||
@@ -156,23 +156,6 @@ uint64_t lastDataRead = 0;
|
|||||||
|
|
||||||
bool gotAck = false;
|
bool gotAck = false;
|
||||||
|
|
||||||
// struct header {
|
|
||||||
// uint8_t StartMarker;
|
|
||||||
// Command Cmd;
|
|
||||||
// uint8_t EndMarker;
|
|
||||||
// };
|
|
||||||
|
|
||||||
// void PrintHeader(header *h) {
|
|
||||||
// Serial2.println("HEADER:");
|
|
||||||
// Serial2.print(" StartMarker: ");
|
|
||||||
// Serial2.println(h->StartMarker);
|
|
||||||
// Serial2.print(" Command : ");
|
|
||||||
// Serial2.println(CommandToStr(h->Cmd));
|
|
||||||
// Serial2.print(" EndMarker : ");
|
|
||||||
// Serial2.println(h->EndMarker);
|
|
||||||
// Serial2.println();
|
|
||||||
// }
|
|
||||||
|
|
||||||
struct UIWindowPacket {
|
struct UIWindowPacket {
|
||||||
uint8_t StartMarker;
|
uint8_t StartMarker;
|
||||||
uint16_t x0;
|
uint16_t x0;
|
||||||
|
|||||||
Reference in New Issue
Block a user