Tactility/TactilityCore/Source/LogSimulator.cpp
Ken Van Hoeylandt 08029a84dd
Various fixes and improvements (#269)
- Bump version for next release
- Fix default gamma for CYD 2432S032C
- Remember gamma curve setting from Display settings app
- Add UART to Core2 (still has no voltage on Grove port, though)
- LVGL performance improvements: pin to second core and set task priority to "critical"
- Fix build warnings, including deprecations
- Removed deprecated `Thread` constructor
- Fix WaveShare S3 display: Some displays would show a white screen at 12MHz, so I'm putting it back to the
official config values.
2025-04-01 23:42:56 +02:00

92 lines
2.1 KiB
C++

#ifndef ESP_PLATFORM
#include "Tactility/Log.h"
#include <cstdint>
#include <iomanip>
#include <sstream>
#include <sys/time.h>
namespace tt {
void storeLog(LogLevel level, const char* format, va_list args);
static char toPrefix(LogLevel level) {
using enum LogLevel;
switch (level) {
case Error:
return 'E';
case Warning:
return 'W';
case Info:
return 'I';
case Debug:
return 'D';
case Verbose:
return 'V';
default:
return ' ';
}
}
static const char* toTagColour(LogLevel level) {
using enum LogLevel;
switch (level) {
case Error:
return "\033[1;31m";
case Warning:
return "\033[1;33m";
case Info:
return "\033[32m";
case Debug:
return "\033[36m";
case Verbose:
return "\033[37m";
default:
return "";
}
}
static const char* toMessageColour(LogLevel level) {
using enum LogLevel;
switch (level) {
case Error:
return "\033[1;31m";
case Warning:
return "\033[1;33m";
case Info:
case Debug:
case Verbose:
return "\033[0m";
default:
return "";
}
}
static uint64_t getLogTimestamp() {
static uint64_t base = 0U;
struct timeval time {};
gettimeofday(&time, nullptr);
uint64_t now = ((uint64_t)time.tv_sec * 1000U) + (time.tv_usec / 1000U);
if (base == 0U) {
base = now;
}
return now - base;
}
void log(LogLevel level, const char* tag, const char* format, ...) {
std::stringstream buffer;
buffer << getLogTimestamp() << " [" << toTagColour(level) << toPrefix(level) << "\033[0m" << "] [" << tag << "] " << toMessageColour(level) << format << "\033[0m\n";
va_list args;
va_start(args, format);
vprintf(buffer.str().c_str(), args);
va_end(args);
va_start(args, format);
tt::storeLog(level, buffer.str().c_str(), args);
va_end(args);
}
} // namespace tt
#endif