mirror of
https://github.com/HASwitchPlate/openHASP.git
synced 2025-07-24 03:36:38 +00:00
Switch to ArduinoLog library
This commit is contained in:
parent
3c82013834
commit
27a36d7b62
@ -86,7 +86,7 @@ void Logging::setSuffix(printfunction f)
|
||||
#endif
|
||||
}
|
||||
|
||||
void Logging::print(const __FlashStringHelper * format, va_list args)
|
||||
void Logging::print(Print * logOutput, const __FlashStringHelper * format, va_list args)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
PGM_P p = reinterpret_cast<PGM_P>(format);
|
||||
@ -94,70 +94,71 @@ void Logging::print(const __FlashStringHelper * format, va_list args)
|
||||
for(; c != 0; c = pgm_read_byte(p++)) {
|
||||
if(c == '%') {
|
||||
c = pgm_read_byte(p++);
|
||||
printFormat(c, &args);
|
||||
printFormat(logOutput, c, &args);
|
||||
} else {
|
||||
_logOutput->print(c);
|
||||
logOutput->print(c);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Logging::print(const char * format, va_list args)
|
||||
void Logging::print(Print * logOutput, const char * format, va_list args)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
for(; *format != 0; ++format) {
|
||||
if(*format == '%') {
|
||||
++format;
|
||||
printFormat(*format, &args);
|
||||
printFormat(logOutput, *format, &args);
|
||||
} else {
|
||||
_logOutput->print(*format);
|
||||
//_logOutput->print(*format);
|
||||
logOutput->print(*format);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Logging::printFormat(const char format, va_list * args)
|
||||
void Logging::printFormat(Print * logOutput, const char format, va_list * args)
|
||||
{
|
||||
#ifndef DISABLE_LOGGING
|
||||
if(format == '%') {
|
||||
_logOutput->print(format);
|
||||
logOutput->print(format);
|
||||
} else if(format == 's') {
|
||||
register char * s = (char *)va_arg(*args, int);
|
||||
_logOutput->print(s);
|
||||
logOutput->print(s);
|
||||
} else if(format == 'S') {
|
||||
register __FlashStringHelper * s = (__FlashStringHelper *)va_arg(*args, int);
|
||||
_logOutput->print(s);
|
||||
logOutput->print(s);
|
||||
} else if(format == 'd' || format == 'i') {
|
||||
_logOutput->print(va_arg(*args, int), DEC);
|
||||
logOutput->print(va_arg(*args, int), DEC);
|
||||
} else if(format == 'u') {
|
||||
_logOutput->print(va_arg(*args, unsigned int), DEC);
|
||||
logOutput->print(va_arg(*args, unsigned int), DEC);
|
||||
} else if(format == 'D' || format == 'F') {
|
||||
_logOutput->print(va_arg(*args, double));
|
||||
logOutput->print(va_arg(*args, double));
|
||||
} else if(format == 'x') {
|
||||
_logOutput->print(va_arg(*args, int), HEX);
|
||||
logOutput->print(va_arg(*args, int), HEX);
|
||||
} else if(format == 'X') {
|
||||
_logOutput->print("0x");
|
||||
_logOutput->print(va_arg(*args, int), HEX);
|
||||
logOutput->print("0x");
|
||||
logOutput->print(va_arg(*args, int), HEX);
|
||||
} else if(format == 'b') {
|
||||
_logOutput->print(va_arg(*args, int), BIN);
|
||||
logOutput->print(va_arg(*args, int), BIN);
|
||||
} else if(format == 'B') {
|
||||
_logOutput->print("0b");
|
||||
_logOutput->print(va_arg(*args, int), BIN);
|
||||
logOutput->print("0b");
|
||||
logOutput->print(va_arg(*args, int), BIN);
|
||||
} else if(format == 'l') {
|
||||
_logOutput->print(va_arg(*args, long), DEC);
|
||||
logOutput->print(va_arg(*args, long), DEC);
|
||||
} else if(format == 'c') {
|
||||
_logOutput->print((char)va_arg(*args, int));
|
||||
logOutput->print((char)va_arg(*args, int));
|
||||
} else if(format == 't') {
|
||||
if(va_arg(*args, int) == 1) {
|
||||
_logOutput->print("T");
|
||||
logOutput->print("T");
|
||||
} else {
|
||||
_logOutput->print("F");
|
||||
logOutput->print("F");
|
||||
}
|
||||
} else if(format == 'T') {
|
||||
if(va_arg(*args, int) == 1) {
|
||||
_logOutput->print(F("true"));
|
||||
logOutput->print(F("true"));
|
||||
} else {
|
||||
_logOutput->print(F("false"));
|
||||
logOutput->print(F("false"));
|
||||
}
|
||||
}
|
||||
#endif
|
@ -21,7 +21,8 @@ Licensed under the MIT License <http://opensource.org/licenses/MIT>.
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
typedef void (*printfunction)(int level, Print *);
|
||||
#include "StringStream.h"
|
||||
typedef void (*printfunction)(int level, Print *, String &);
|
||||
|
||||
//#include <stdint.h>
|
||||
//#include <stddef.h>
|
||||
@ -251,11 +252,11 @@ class Logging {
|
||||
}
|
||||
|
||||
private:
|
||||
void print(const char * format, va_list args);
|
||||
void print(Print * logOutput, const char * format, va_list args);
|
||||
|
||||
void print(const __FlashStringHelper * format, va_list args);
|
||||
void print(Print * logOutput, const __FlashStringHelper * format, va_list args);
|
||||
|
||||
void printFormat(const char format, va_list * args);
|
||||
void printFormat(Print * logOutput, const char format, va_list * args);
|
||||
|
||||
template <class T> void printLevel(int level, T msg, ...)
|
||||
{
|
||||
@ -264,23 +265,30 @@ class Logging {
|
||||
return;
|
||||
}
|
||||
|
||||
String debugOutput((char *)0);
|
||||
StringStream debugStream((String &)debugOutput);
|
||||
debugOutput.reserve(5 * 128);
|
||||
|
||||
if(_prefix != NULL) {
|
||||
_prefix(level, _logOutput);
|
||||
_prefix(level, &debugStream, debugOutput);
|
||||
}
|
||||
|
||||
if(_showLevel) {
|
||||
static const char levels[] = "FEWNTV";
|
||||
_logOutput->print(levels[level - 1]);
|
||||
_logOutput->print(": ");
|
||||
debugStream.print(levels[level - 1]);
|
||||
debugStream.print(": ");
|
||||
}
|
||||
|
||||
va_list args;
|
||||
va_start(args, msg);
|
||||
print(msg, args);
|
||||
print(&debugStream, msg, args);
|
||||
|
||||
if(_suffix != NULL) {
|
||||
_suffix(level, _logOutput);
|
||||
_suffix(level, &debugStream, debugOutput);
|
||||
}
|
||||
|
||||
//_logOutput->print(debugOutput);
|
||||
debugOutput.clear();
|
||||
#endif
|
||||
}
|
||||
|
@ -10,7 +10,8 @@
|
||||
|
||||
#include "lvgl.h"
|
||||
#include "lv_zifont.h"
|
||||
#include "../src/hasp_log.h"
|
||||
// #include "../src/hasp_log.h"
|
||||
#include "ArduinoLog.h"
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
@ -101,9 +102,7 @@ bool openFont(File & file, const char * filename)
|
||||
{
|
||||
file = SPIFFS.open(filename, "r");
|
||||
if(!file) {
|
||||
String error = String(F("FONT: %sOpening font: "));
|
||||
error += String(filename);
|
||||
errorPrintln(error);
|
||||
Log.error(F("FONT: %sOpening font: %s"), filename);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -150,14 +149,14 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
|
||||
|
||||
/* Check that we read the correct size */
|
||||
if(readSize != sizeof(zi_font_header_t)) {
|
||||
debugPrintln(PSTR("FONT: Error reading ziFont Header"));
|
||||
Log.error(F("FONT: Error reading ziFont Header"));
|
||||
file.close();
|
||||
return ZIFONT_ERROR_READING_DATA;
|
||||
}
|
||||
|
||||
/* Check ziFile Header Format */
|
||||
if(header.Password != 4 || header.Version != 5) {
|
||||
debugPrintln(PSTR("FONT: Unknown font file format"));
|
||||
Log.error(F("FONT: Unknown font file format"));
|
||||
file.close();
|
||||
return ZIFONT_ERROR_UNKNOWN_HEADER;
|
||||
}
|
||||
@ -186,15 +185,13 @@ int lv_zifont_font_init(lv_font_t ** font, const char * font_path, uint16_t size
|
||||
|
||||
//* Check that we read the correct size
|
||||
if(readSize != sizeof(lv_zifont_char_t) * CHAR_CACHE_SIZE) {
|
||||
debugPrintln(PSTR("FONT: Error reading ziFont character map"));
|
||||
Log.error(F("FONT: Error reading ziFont character map"));
|
||||
file.close();
|
||||
return ZIFONT_ERROR_READING_DATA;
|
||||
}
|
||||
|
||||
char msg[128];
|
||||
sprintf_P(msg, PSTR("FONT: Loaded V%d Font File: %s containing %d characters"), header.Version, font_path,
|
||||
header.Maximumnumchars);
|
||||
debugPrintln(msg);
|
||||
Log.notice(F("FONT: Loaded V%d Font File: %s containing %d characters"), header.Version, font_path,
|
||||
header.Maximumnumchars);
|
||||
|
||||
file.close();
|
||||
|
||||
@ -295,7 +292,7 @@ const uint8_t * lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t u
|
||||
if(readSize != sizeof(lv_zifont_char_t)) {
|
||||
file.close();
|
||||
lv_mem_free(charInfo);
|
||||
debugPrintln(PSTR("FONT: [ERROR] Wrong number of bytes read from flash"));
|
||||
Log.error(F("FONT: Wrong number of bytes read from flash"));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -303,7 +300,7 @@ const uint8_t * lv_font_get_bitmap_fmt_zifont(const lv_font_t * font, uint32_t u
|
||||
if(charInfo->character != unicode_letter) {
|
||||
file.close();
|
||||
lv_mem_free(charInfo);
|
||||
debugPrintln(PSTR("FONT: [ERROR] Incorrect letter read from flash"));
|
||||
Log.error(F("FONT: Incorrect letter read from flash"));
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
/*
|
||||
#include "hasp_conf.h"
|
||||
#include <Arduino.h>
|
||||
#include "ArduinoLog.h"
|
||||
@ -16,6 +17,7 @@
|
||||
#include "hasp_log.h"
|
||||
#include "hasp_debug.h"
|
||||
|
||||
|
||||
void debugPrintln(String & debugText)
|
||||
{
|
||||
serialPrintln(debugText, LOG_LEVEL_NOTICE);
|
||||
@ -62,4 +64,5 @@ void warningPrintln(String debugText)
|
||||
#if HASP_USE_SYSLOG != 0
|
||||
syslogSend(LOG_WARNING, buffer);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
*/
|
@ -1,3 +1,4 @@
|
||||
/*
|
||||
#ifndef HASP_LOG_H
|
||||
#define HASP_LOG_H
|
||||
|
||||
@ -8,4 +9,5 @@ void debugPrintln(const char * debugText);
|
||||
void errorPrintln(String debugText);
|
||||
void warningPrintln(String debugText);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
*/
|
Loading…
x
Reference in New Issue
Block a user