Ken Van Hoeylandt 9a11e6f47b
Implement UI scaling and more (#501)
**New Features**
 * Runtime font accessors and new symbol fonts for text, launcher, statusbar, and shared icons.
 * Added font height base setting to device.properties
 * Text fonts now have 3 sizes: small, default, large

**Improvements**
 * Renamed `UiScale` to `UiDensity`
 * Statusbar, toolbar and many UI components now compute heights and spacing from fonts/density.
 * SSD1306 initialization sequence refined for more stable startup.
 * Multiple image assets replaced by symbol-font rendering.
 * Many layout improvements related to density, font scaling and icon scaling
 * Updated folder name capitalization for newer style
2026-02-15 01:41:47 +01:00

77 lines
1.8 KiB
C++

// SPDX-License-Identifier: Apache-2.0
#ifndef ESP_PLATFORM
#include <tactility/log.h>
#include <mutex>
#include <inttypes.h>
#include <stdio.h>
#include <stdint.h>
#include <stdarg.h>
#include <sys/time.h>
static const char* get_log_color(LogLevel level) {
using enum LogLevel;
switch (level) {
case LOG_LEVEL_ERROR:
return "\033[1;31m";
case LOG_LEVEL_WARNING:
return "\033[1;33m";
case LOG_LEVEL_INFO:
return "\033[32m";
case LOG_LEVEL_DEBUG:
return "\033[36m";
case LOG_LEVEL_VERBOSE:
return "\033[37m";
default:
return "";
}
}
static inline char get_log_prefix(LogLevel level) {
using enum LogLevel;
switch (level) {
case LOG_LEVEL_ERROR:
return 'E';
case LOG_LEVEL_WARNING:
return 'W';
case LOG_LEVEL_INFO:
return 'I';
case LOG_LEVEL_DEBUG:
return 'D';
case LOG_LEVEL_VERBOSE:
return 'V';
default:
return '?';
}
}
static uint64_t get_log_timestamp() {
static uint64_t base = 0U;
static std::once_flag init_flag;
std::call_once(init_flag, []() {
timeval time {};
gettimeofday(&time, nullptr);
base = ((uint64_t)time.tv_sec * 1000U) + (time.tv_usec / 1000U);
});
timeval time {};
gettimeofday(&time, nullptr);
uint64_t now = ((uint64_t)time.tv_sec * 1000U) + (time.tv_usec / 1000U);
return now - base;
}
extern "C" {
void log_generic(enum LogLevel level, const char* tag, const char* format, ...) {
va_list args;
va_start(args, format);
printf("%s %c (%" PRIu64 ") %s ", get_log_color(level), get_log_prefix(level), get_log_timestamp(), tag);
vprintf(format, args);
printf("\033[0m\n");
va_end(args);
}
}
#endif