micro mode: fix padding

This commit is contained in:
Lightos1
2026-04-03 13:15:01 +02:00
parent fc203c723c
commit 59ba05332f
2 changed files with 311 additions and 308 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -36,7 +36,7 @@ private:
size_t fontsize = 0;
bool showFPS = false;
uint64_t systemtickfrequency_impl = systemtickfrequency;
// Pre-compiled render data structures
struct RenderItem {
uint8_t type;
@@ -45,7 +45,7 @@ private:
const char* volt_ptr;
bool has_voltage;
};
// Resolution tracking
resolutionCalls m_resolutionRenderCalls[8] = {0};
resolutionCalls m_resolutionViewportCalls[8] = {0};
@@ -62,7 +62,7 @@ private:
bool skipOnce = true;
bool runOnce = true;
// Fixed spacing system - calculate actual widths at render time
struct LayoutMetrics {
uint32_t label_data_gap = 8; // Fixed gap between label and data
@@ -72,20 +72,20 @@ private:
uint32_t side_margin = 3; // Margins on left and right
bool calculated = false;
} layout;
// Lookup table for difference symbols
static constexpr const char* diffSymbols[4] = {"", "@", "", ""};
inline const char* getDifferenceSymbol(int32_t delta) {
if (delta > 20000) return diffSymbols[0]; // △
if (delta > -20000) return diffSymbols[1]; // @
if (delta < -50000) return diffSymbols[3]; // ≠
return diffSymbols[2]; // ▽
}
void calculateLayoutMetrics(tsl::gfx::Renderer *renderer) {
if (layout.calculated) return;
// Use font size to determine appropriate spacing
if (fontsize <= 16) {
layout.label_data_gap = 6;
@@ -103,12 +103,12 @@ private:
layout.volt_data_gap = 0;
layout.item_spacing = 20;
}
layout.calculated = true;
}
public:
MicroOverlay() {
MicroOverlay() {
tsl::hlp::requestForeground(false);
disableJumpTo = true;
//tsl::initializeUltrahandSettings();
@@ -135,7 +135,7 @@ public:
//alphabackground = 0x0;
deactivateOriginalFooter = true;
StartThreads();
// Pre-allocate render items vector
//renderItems.reserve(8);
realVoltsPolling = settings.realVolts;
@@ -144,15 +144,15 @@ public:
if (R_SUCCEEDED(psmCheck) && R_SUCCEEDED(i2cCheck)) {
uint16_t data = 0;
float tempA = 0.0;
// Get initial power consumption
Max17050ReadReg(MAX17050_AvgCurrent, &data);
tempA = (1.5625 / (max17050SenseResistor * max17050CGain)) * (s16)data;
PowerConsumption = tempA * batVoltageAvg / 1000000.0; // Rough initial estimate
// Get initial battery info
psmGetBatteryChargeInfoFields(psmService, &_batteryChargeInfoFields);
// Get initial time estimate
if (tempA >= 0) {
batTimeEstimate = -1;
@@ -171,18 +171,18 @@ public:
batTimeEstimate = -1;
_batteryChargeInfoFields = {0};
}
// Now format the initial Battery_c string
char remainingBatteryLife[8];
const float drawW = (fabsf(PowerConsumption) < 0.01f) ? 0.0f : PowerConsumption;
if (batTimeEstimate >= 0 && !(drawW <= 0.01f && drawW >= -0.01f)) {
snprintf(remainingBatteryLife, sizeof(remainingBatteryLife),
"%d:%02d", batTimeEstimate / 60, batTimeEstimate % 60);
} else {
strcpy(remainingBatteryLife, "--:--");
}
if (!settings.invertBatteryDisplay) {
snprintf(Battery_c, sizeof(Battery_c),
"%.2f W%.1f%% [%s]",
@@ -197,39 +197,39 @@ public:
drawW);
}
}
~MicroOverlay() {
CloseThreads();
fixForeground = true;
FullMode = true;
}
// Fast parsing and render item preparation
void prepareRenderItems() {
if (!renderDataDirty) return;
renderItems.clear();
// Fast manual parsing of settings.show
const std::string& show = settings.show;
size_t start = 0, end = 0;
uint8_t seen_flags = 0;
static size_t len;
static uint32_t key3;
while (start < show.length()) {
end = show.find('+', start);
if (end == std::string::npos) end = show.length();
len = end - start;
if (len >= 3) {
const char* key = &show[start];
// Use first 3 chars for fast comparison
key3 = (key[0] << 16) | (key[1] << 8) | key[2];
switch (key3) {
case 0x435055: // "CPU"
if (!(seen_flags & 1)) {
@@ -286,7 +286,7 @@ public:
seen_flags |= 512;
}
break;
case 0x445443: // "DTC"
case 0x445443: // "DTC"
if (!(seen_flags & 256) && settings.showDTC) {
renderItems.push_back({8, settings.useDTCSymbol ? "\uE007" : "DTC", DTC_c, nullptr, false});
seen_flags |= 256;
@@ -296,38 +296,38 @@ public:
}
start = end + 1;
}
renderDataDirty = false;
}
virtual tsl::elm::Element* createUI() override {
auto* Status = new tsl::elm::CustomDrawer([this](tsl::gfx::Renderer *renderer, u16 x, u16 y, u16 w, u16 h) {
cachedMargin = renderer->getTextDimensions("CPUGPURAMSOCBAT[]", false, fontsize).second;
if (!Initialized) {
//cachedMargin = renderer->drawString(" ", false, 0, 0, fontsize, renderer->a(0x0000)).first;
catColorA = settings.catColor;
textColorA = settings.textColor;
base_y = settings.setPosBottom ?
base_y = settings.setPosBottom ?
tsl::cfg::FramebufferHeight - (fontsize + (fontsize / 4)) +1: 0;
Initialized = true;
renderDataDirty = true;
layout.calculated = false; // Force recalculation
tsl::hlp::requestForeground(false);
}
//renderer->drawRect(0, 0, tsl::cfg::FramebufferWidth, cachedMargin + 4, a(settings.backgroundColor));
renderer->drawRect(0, settings.setPosBottom ? base_y-1 : 0, tsl::cfg::FramebufferWidth, cachedMargin + 4, a(settings.backgroundColor));
// Prepare render items if settings changed
prepareRenderItems();
calculateLayoutMetrics(renderer);
// Separate battery from other items
std::vector<RenderItem> main_items;
//RenderItem* battery_item = nullptr;
for (auto& item : renderItems) {
//if (item.type == 6) { // BAT
// battery_item = &item;
@@ -347,7 +347,7 @@ public:
main_items.push_back(item);
}
}
// Calculate actual widths for all main items
struct ItemLayout {
uint32_t label_width;
@@ -355,7 +355,7 @@ public:
uint32_t volt_width;
uint32_t total_width;
};
std::vector<ItemLayout> item_layouts;
uint32_t total_main_width = 0;
@@ -364,81 +364,81 @@ public:
static ItemLayout item_layout;
for (const auto& item : main_items) {
item_layout = {};
// Calculate actual label width
//auto label_dim = renderer->drawString(item.label, false, 0, 0, fontsize, renderer->a(0x0000));
//auto label_dim = renderer->getTextDimensions(item.label, fontsize);
item_layout.label_width = renderer->getTextDimensions(item.label, false, fontsize).first;
// Calculate actual data width
//auto data_dim = renderer->drawString(item.data_ptr, false, 0, 0, fontsize, renderer->a(0x0000));
//auto data_dim = renderer->getTextDimensions(item.data_ptr, fontsize);
item_layout.data_width = renderer->getTextDimensions(item.data_ptr, false, fontsize).first;
// Calculate voltage width if present
if (item.has_voltage && item.volt_ptr) {
//uto volt_dim = renderer->drawString(item.volt_ptr, false, 0, 0, fontsize, renderer->a(0x0000));
//auto volt_dim = renderer->getTextDimensions(item.volt_ptr, fontsize);
item_layout.volt_width = renderer->getTextDimensions(item.volt_ptr, false, fontsize).first;
// Total: label + gap + data + gap + "|" + gap + voltage
//auto sep_width = renderer->drawString("", false, 0, 0, fontsize, renderer->a(0x0000));
item_layout.total_width = item_layout.label_width + layout.label_data_gap +
item_layout.data_width + layout.volt_separator_gap +
item_layout.total_width = item_layout.label_width + layout.label_data_gap +
item_layout.data_width + layout.volt_separator_gap +
sep_width + layout.volt_data_gap + item_layout.volt_width;
} else {
// Total: label + gap + data
item_layout.total_width = item_layout.label_width + layout.label_data_gap + item_layout.data_width;
}
item_layouts.push_back(item_layout);
total_main_width += item_layout.total_width;
}
// Determine if we have battery and handle it as the rightmost item
std::vector<RenderItem> all_items_ordered;
std::vector<ItemLayout> all_layouts_ordered;
// Add main items first
for (size_t i = 0; i < main_items.size(); i++) {
all_items_ordered.push_back(main_items[i]);
all_layouts_ordered.push_back(item_layouts[i]);
}
// Add battery as the last item if present
//if (battery_item) {
// //auto bat_label_dim = renderer->drawString("BAT", false, 0, 0, fontsize, renderer->a(0x0000));
// //auto bat_label_dim = renderer->getTextDimensions("BAT", fontsize);
// //auto bat_data_dim = renderer->drawString(battery_item->data_ptr, false, 0, 0, fontsize, renderer->a(0x0000));
// //auto bat_data_dim = renderer->getTextDimensions(battery_item->data_ptr, fontsize);
//
//
// ItemLayout battery_layout = {};
// battery_layout.label_width = renderer->getTextDimensions("BAT", false, fontsize).first;
// battery_layout.data_width = renderer->getTextDimensions(battery_item->data_ptr, false, fontsize).first;
// battery_layout.volt_width = 0;
// battery_layout.total_width = battery_layout.label_width + layout.label_data_gap + battery_layout.data_width;
//
//
// all_items_ordered.push_back(*battery_item);
// all_layouts_ordered.push_back(battery_layout);
//}
// Calculate total width of all items
uint32_t total_all_width = 0;
for (const auto& item_layout : all_layouts_ordered) {
total_all_width += item_layout.total_width;
}
// Calculate available space for distribution
//uint32_t available_width = tsl::cfg::FramebufferWidth - (2 * layout.side_margin);
//uint32_t remaining_space = available_width - total_all_width;
// Calculate positions based on alignment mode
std::vector<uint32_t> item_positions;
const size_t N = all_items_ordered.size();
if (N == 0) return;
if (N == 1) {
// Single item positioning based on alignment
if (settings.alignTo == 2) { // RIGHT
@@ -452,43 +452,43 @@ public:
for (const auto& layout : all_layouts_ordered) {
total_widths += layout.total_width;
}
if (settings.alignTo == 0) { // LEFT alignment
// All items except last positioned from left with small gaps
// Last item (battery if present) positioned at far right
const uint32_t small_gap = layout.item_spacing;
// Position items from left
uint32_t current_x = layout.side_margin;
for (size_t i = 0; i < N - 1; ++i) {
item_positions.push_back(current_x);
current_x += all_layouts_ordered[i].total_width + small_gap;
}
// Position last item at far right
const uint32_t last_width = all_layouts_ordered[N-1].total_width;
item_positions.push_back(tsl::cfg::FramebufferWidth - layout.side_margin - last_width);
} else if (settings.alignTo == 2) { // RIGHT alignment
// First item at far left, remaining items packed at right
const uint32_t small_gap = layout.item_spacing;
// Resize vector to hold all positions
item_positions.resize(N);
// Position first item at far left
item_positions[0] = layout.side_margin;
// Calculate total width of items 1 to N-1 plus gaps between them
uint32_t right_group_width = 0;
for (size_t i = 1; i < N; ++i) {
right_group_width += all_layouts_ordered[i].total_width;
if (i < N - 1) right_group_width += small_gap; // Gap after each item except the last
}
// Start positioning from right margin minus total width of right group
uint32_t current_x = tsl::cfg::FramebufferWidth - layout.side_margin - right_group_width;
// Position items 1 to N-1 sequentially from left to right within the right group
for (size_t i = 1; i < N; ++i) {
item_positions[i] = current_x;
@@ -497,10 +497,10 @@ public:
} else { // CENTER alignment (default behavior)
// Total available width for spacing = framebuffer width minus total item widths minus margins
const int32_t total_spacing = (int32_t)tsl::cfg::FramebufferWidth - (2 * (int32_t)layout.side_margin) - (int32_t)total_widths;
// Number of gaps between items is N-1
const uint32_t gap = total_spacing > 0 ? (uint32_t)(total_spacing / (N - 1)) : 0;
// Position first item flush left
item_positions.push_back(layout.side_margin);
static uint32_t prev_pos, prev_width;
@@ -510,11 +510,11 @@ public:
prev_width = all_layouts_ordered[i - 1].total_width;
item_positions.push_back(prev_pos + prev_width + gap);
}
// Fix any rounding error for center alignment
const int32_t last_item_end = item_positions.back() + all_layouts_ordered.back().total_width;
const int32_t overflow = (int32_t)tsl::cfg::FramebufferWidth - layout.side_margin - last_item_end;
if (overflow != 0) {
for (size_t i = 1; i < item_positions.size(); ++i) {
item_positions[i] += overflow;
@@ -532,11 +532,11 @@ public:
const auto& item = all_items_ordered[i];
const auto& item_layout = all_layouts_ordered[i];
current_x = item_positions[i];
// Draw label
renderer->drawString(item.label, false, current_x, base_y + cachedMargin, fontsize, catColorA);
current_x += item_layout.label_width + layout.label_data_gap;
// Draw data
//renderer->drawString(item.data_ptr, false, current_x, base_y + fontsize, fontsize, textColorA);
@@ -552,22 +552,22 @@ public:
const size_t cPos = dataStr.find("C", degreesPos);
if (cPos != std::string::npos) {
const size_t tempEnd = cPos + 1;
const std::string preTempPart = dataStr.substr(0, tempStart);
const std::string tempPart = dataStr.substr(tempStart, tempEnd - tempStart);
const std::string postTempPart = dataStr.substr(tempEnd);
const float temp = realCPU_Temp / 1000.0f;
const tsl::Color tempColor = tsl::GradientColor(temp);
uint32_t renderX = current_x;
if (!preTempPart.empty()) {
renderer->drawStringWithColoredSections(preTempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
renderX += renderer->getTextDimensions(preTempPart, false, fontsize).first;
}
renderer->drawStringWithColoredSections(tempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, tempColor, a(settings.separatorColor));
if (!postTempPart.empty()) {
renderX += renderer->getTextDimensions(tempPart, false, fontsize).first;
renderer->drawStringWithColoredSections(postTempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
@@ -581,7 +581,7 @@ public:
} else {
renderer->drawStringWithColoredSections(item.data_ptr, false, specialChars, current_x, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
}
} else if (item.type == 1) { // GPU
std::string dataStr(item.data_ptr);
const size_t degreesPos = dataStr.find("°");
@@ -592,22 +592,22 @@ public:
const size_t cPos = dataStr.find("C", degreesPos);
if (cPos != std::string::npos) {
const size_t tempEnd = cPos + 1;
const std::string preTempPart = dataStr.substr(0, tempStart);
const std::string tempPart = dataStr.substr(tempStart, tempEnd - tempStart);
const std::string postTempPart = dataStr.substr(tempEnd);
const float temp = realGPU_Temp / 1000.0f;
const tsl::Color tempColor = tsl::GradientColor(temp);
uint32_t renderX = current_x;
if (!preTempPart.empty()) {
renderer->drawStringWithColoredSections(preTempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
renderX += renderer->getTextDimensions(preTempPart, false, fontsize).first;
}
renderer->drawStringWithColoredSections(tempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, tempColor, a(settings.separatorColor));
if (!postTempPart.empty()) {
renderX += renderer->getTextDimensions(tempPart, false, fontsize).first;
renderer->drawStringWithColoredSections(postTempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
@@ -621,7 +621,7 @@ public:
} else {
renderer->drawStringWithColoredSections(item.data_ptr, false, specialChars, current_x, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
}
} else if (item.type == 2) { // RAM
std::string dataStr(item.data_ptr);
const size_t degreesPos = dataStr.find("°");
@@ -632,22 +632,22 @@ public:
const size_t cPos = dataStr.find("C", degreesPos);
if (cPos != std::string::npos) {
const size_t tempEnd = cPos + 1;
const std::string preTempPart = dataStr.substr(0, tempStart);
const std::string tempPart = dataStr.substr(tempStart, tempEnd - tempStart);
const std::string postTempPart = dataStr.substr(tempEnd);
const float temp = realRAM_Temp / 1000.0f;
const tsl::Color tempColor = tsl::GradientColor(temp);
uint32_t renderX = current_x;
if (!preTempPart.empty()) {
renderer->drawStringWithColoredSections(preTempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
renderX += renderer->getTextDimensions(preTempPart, false, fontsize).first;
}
renderer->drawStringWithColoredSections(tempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, tempColor, a(settings.separatorColor));
if (!postTempPart.empty()) {
renderX += renderer->getTextDimensions(tempPart, false, fontsize).first;
renderer->drawStringWithColoredSections(postTempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
@@ -661,7 +661,7 @@ public:
} else {
renderer->drawStringWithColoredSections(item.data_ptr, false, specialChars, current_x, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
}
} else if (item.type == 3) { // SOC temperature
// Parse SOC temperature: "XX°C (XX%)"
std::string dataStr(item.data_ptr);
@@ -670,18 +670,18 @@ public:
const size_t cPos = dataStr.find("C", degreesPos);
if (cPos != std::string::npos) {
const size_t tempEnd = cPos + 1; // Include the 'C'
// Extract temperature value and apply gradient
const int temp = atoi(item.data_ptr);
const tsl::Color tempColor = tsl::GradientColor((float)temp);
// Split into temperature part and remaining part
const std::string tempPart = dataStr.substr(0, tempEnd);
const std::string restPart = dataStr.substr(tempEnd);
// Render temperature with gradient color
renderer->drawString(tempPart, false, current_x, base_y + cachedMargin, fontsize, tempColor);
// Render remaining text with normal color
if (!restPart.empty()) {
const uint32_t tempPartWidth = renderer->getTextDimensions(tempPart, false, fontsize).first;
@@ -695,14 +695,14 @@ public:
// Fallback: render normally
renderer->drawStringWithColoredSections(item.data_ptr, false, specialChars, current_x, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
}
} else if (item.type == 4) { // TMP multiple temperatures
// Parse TMP temperatures: "XX°C XX°C XX°C (XX%)"
std::string dataStr(item.data_ptr);
uint32_t renderX = current_x;
size_t pos = 0;
bool parseSuccess = true;
// Parse up to 3 temperatures
for (int tempCount = 0; tempCount < 3 && parseSuccess && pos < dataStr.length(); tempCount++) {
// Skip any leading spaces
@@ -711,47 +711,47 @@ public:
renderX += renderer->getTextDimensions(" ", false, fontsize).first;
pos++;
}
if (pos >= dataStr.length()) break;
// Find degrees symbol
const size_t degreesPos = dataStr.find("°", pos);
if (degreesPos == std::string::npos) {
parseSuccess = false;
break;
}
// Find 'C' after degrees symbol
const size_t cPos = dataStr.find("C", degreesPos);
if (cPos == std::string::npos) {
parseSuccess = false;
break;
}
const size_t tempEnd = cPos + 1; // Include the 'C'
// Extract and render temperature with gradient
const std::string tempPart = dataStr.substr(pos, tempEnd - pos);
const int temp = atoi(tempPart.c_str());
const tsl::Color tempColor = tsl::GradientColor((float)temp);
renderer->drawStringWithColoredSections(tempPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, tempColor, a(settings.separatorColor));
renderX += renderer->getTextDimensions(tempPart, false, fontsize).first;
pos = tempEnd;
}
// Render any remaining text (like " (50%)")
if (pos < dataStr.length()) {
const std::string restPart = dataStr.substr(pos);
renderer->drawStringWithColoredSections(restPart, false, specialChars, renderX, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
}
// If parsing failed, fall back to normal rendering
if (!parseSuccess) {
renderer->drawStringWithColoredSections(item.data_ptr, false, specialChars, current_x, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
}
} else {
// Normal rendering for all other item types
renderer->drawStringWithColoredSections(item.data_ptr, false, specialChars, current_x, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
@@ -761,7 +761,7 @@ public:
renderer->drawStringWithColoredSections(item.data_ptr, false, specialChars, current_x, base_y + cachedMargin, fontsize, textColorA, a(settings.separatorColor));
}
current_x += item_layout.data_width;
// Draw voltage if present
if (item.has_voltage && item.volt_ptr) {
current_x += layout.volt_separator_gap;
@@ -773,7 +773,7 @@ public:
}
}
});
tsl::elm::HeaderOverlayFrame* rootFrame = new tsl::elm::HeaderOverlayFrame("", "");
rootFrame->setContent(Status);
return rootFrame;
@@ -827,7 +827,7 @@ public:
// CPU usage calculations - optimized with fewer conditionals
const double inv_freq = 1.0 / systemtickfrequency_impl;
// Capture systemtickfrequency_impl and inv_freq safely
const auto formatUsage = [this](char* buf, size_t size, uint64_t idletick, double inv_freq) {
if (idletick > systemtickfrequency_impl) {
@@ -836,60 +836,60 @@ public:
snprintf(buf, size, "%.0f%%", (1.0 - (idletick * inv_freq)) * 100.0);
}
};
// Atomically load idle ticks before using them
const uint64_t idle0 = idletick0.load(std::memory_order_acquire);
const uint64_t idle1 = idletick1.load(std::memory_order_acquire);
const uint64_t idle2 = idletick2.load(std::memory_order_acquire);
const uint64_t idle3 = idletick3.load(std::memory_order_acquire);
formatUsage(CPU_Usage0, sizeof(CPU_Usage0), idle0, inv_freq);
formatUsage(CPU_Usage1, sizeof(CPU_Usage1), idle1, inv_freq);
formatUsage(CPU_Usage2, sizeof(CPU_Usage2), idle2, inv_freq);
formatUsage(CPU_Usage3, sizeof(CPU_Usage3), idle3, inv_freq);
mutexLock(&mutex_Misc);
// CPU frequency and voltage
const char* cpuDiff = "@";
if (realCPU_Hz) {
const int32_t deltaCPU = (int32_t)(realCPU_Hz / 1000) - (CPU_Hz / 1000);
cpuDiff = getDifferenceSymbol(deltaCPU);
}
const uint32_t cpuFreq = settings.realFrequencies && realCPU_Hz ? realCPU_Hz : CPU_Hz;
if (settings.showFullCPU) {
snprintf(CPU_compressed_c, sizeof(CPU_compressed_c),
"[%s,%s,%s,%s]%s%u.%u",
CPU_Usage0, CPU_Usage1, CPU_Usage2, CPU_Usage3,
snprintf(CPU_compressed_c, sizeof(CPU_compressed_c),
"[%s,%s,%s,%s]%s%u.%u",
CPU_Usage0, CPU_Usage1, CPU_Usage2, CPU_Usage3,
cpuDiff, cpuFreq / 1000000, (cpuFreq / 100000) % 10);
} else {
// Find max CPU usage across all cores
const auto extractUsage = [](const char* usage_str) -> double {
return strtod(usage_str, nullptr);
};
const double usage0 = extractUsage(CPU_Usage0);
const double usage1 = extractUsage(CPU_Usage1);
const double usage2 = extractUsage(CPU_Usage2);
const double usage3 = extractUsage(CPU_Usage3);
const double maxUsage = std::max({usage0, usage1, usage2, usage3});
snprintf(CPU_compressed_c, sizeof(CPU_compressed_c),
"%.0f%%%s%u.%u",
snprintf(CPU_compressed_c, sizeof(CPU_compressed_c),
"%.0f%%%s%u.%u",
maxUsage, cpuDiff, cpuFreq / 1000000, (cpuFreq / 100000) % 10);
}
if (settings.realTemps && realCPU_Temp != 0) {
char temp_buffer[48];
snprintf(temp_buffer, sizeof(temp_buffer), " %s", CPU_temp_c);
snprintf(temp_buffer, sizeof(temp_buffer), "%s", CPU_temp_c);
strncat(CPU_compressed_c, temp_buffer, sizeof(CPU_compressed_c) - strlen(CPU_compressed_c) - 1);
}
//if (settings.realVolts) {
// snprintf(CPU_volt_c, sizeof(CPU_volt_c), "%u.%u mV",
// snprintf(CPU_volt_c, sizeof(CPU_volt_c), "%u.%u mV",
// realCPU_mV/1000, (isMariko ? (realCPU_mV/100)%10 : (realCPU_mV/10)%100));
//}
@@ -898,28 +898,28 @@ public:
const uint32_t mv = realCPU_mV / 1000; // µV → mV
snprintf(CPU_volt_c, sizeof(CPU_volt_c), "%u mV", mv);
}
// GPU frequency and voltage
const char* gpuDiff = "@";
if (realGPU_Hz) {
const int32_t deltaGPU = (int32_t)(realGPU_Hz / 1000) - (GPU_Hz / 1000);
gpuDiff = getDifferenceSymbol(deltaGPU);
}
const uint32_t gpuFreq = settings.realFrequencies && realGPU_Hz ? realGPU_Hz : GPU_Hz;
snprintf(GPU_Load_c, sizeof(GPU_Load_c),
"%u%%%s%u.%u",
GPU_Load_u / 10,
gpuDiff, gpuFreq / 1000000, (gpuFreq / 100000) % 10);
if (settings.realTemps && realGPU_Temp != 0) {
char temp_buffer[48];
snprintf(temp_buffer, sizeof(temp_buffer), " %s", GPU_temp_c);
snprintf(temp_buffer, sizeof(temp_buffer), "%s", GPU_temp_c);
strncat(GPU_Load_c, temp_buffer, sizeof(GPU_Load_c) - strlen(GPU_Load_c) - 1);
}
//if (settings.realVolts) {
// snprintf(GPU_volt_c, sizeof(GPU_volt_c), "%u.%u mV",
// snprintf(GPU_volt_c, sizeof(GPU_volt_c), "%u.%u mV",
// realGPU_mV/1000, (isMariko ? (realGPU_mV/100)%10 : (realGPU_mV/10)%100));
//}
@@ -930,20 +930,20 @@ public:
if (GPU_Hz_int == 0 && lastGPU_Hz_int != 0) {
isRendering = false;
leventSignal(&renderingStopEvent);
triggerExitNow = true;
return;
}
lastGPU_Hz_int = GPU_Hz_int;
}
/* ── GPU voltage ───────────────────────────── */
if (settings.realVolts) {
const uint32_t mv = realGPU_mV / 1000;
snprintf(GPU_volt_c, sizeof(GPU_volt_c), "%u mV", mv);
}
// RAM usage and frequency
char MICRO_RAM_all_c[16];
if (!settings.showpartLoad) {
@@ -971,23 +971,23 @@ public:
const int32_t deltaRAM = (int32_t)(realRAM_Hz / 1000) - (RAM_Hz / 1000);
ramDiff = getDifferenceSymbol(deltaRAM);
}
const uint32_t ramFreq = settings.realFrequencies && realRAM_Hz ? realRAM_Hz : RAM_Hz;
snprintf(RAM_var_compressed_c, sizeof(RAM_var_compressed_c),
"%s%s%u.%u", MICRO_RAM_all_c, ramDiff,
snprintf(RAM_var_compressed_c, sizeof(RAM_var_compressed_c),
"%s%s%u.%u", MICRO_RAM_all_c, ramDiff,
ramFreq / 1000000, (ramFreq / 100000) % 10);
if (settings.realTemps && realRAM_Temp != 0) {
char temp_buffer[48];
snprintf(temp_buffer, sizeof(temp_buffer), " %s", RAM_temp_c);
snprintf(temp_buffer, sizeof(temp_buffer), "%s", RAM_temp_c);
strncat(RAM_var_compressed_c, temp_buffer, sizeof(RAM_var_compressed_c) - strlen(RAM_var_compressed_c) - 1);
}
//if (settings.realVolts) {
// uint32_t vdd2 = realRAM_mV / 10000;
// uint32_t vddq = realRAM_mV % 10000;
// if (isMariko) {
// snprintf(RAM_volt_c, sizeof(RAM_volt_c), "%u.%u%u.%u mV",
// snprintf(RAM_volt_c, sizeof(RAM_volt_c), "%u.%u%u.%u mV",
// vdd2/10, vdd2%10, vddq/10, vddq%10);
// } else {
// snprintf(RAM_volt_c, sizeof(RAM_volt_c), "%u.%u mV", vdd2/10, vdd2%10);
@@ -997,15 +997,15 @@ public:
/* ── RAM voltage ───────────────────────────── */
if (settings.realVolts && (settings.showVDD2 || settings.showVDDQ)) {
/* realRAM_mV packs VDD2 | VDDQ in 10-µV units *
* → split, convert to mV
* → split, convert to mV
*/
const float mv_vdd2 = (realRAM_mV % 100000) / 10.0f; // VDD2
const uint32_t mv_vddq = (realRAM_mV / 10000) / 10; // VDDQ
// Build voltage string based on settings
RAM_volt_c[0] = '\0'; // Start with empty string
char temp_buffer[16];
if (settings.showVDD2) {
if (settings.decimalVDD2) {
snprintf(temp_buffer, sizeof(temp_buffer), "%.1f mV", mv_vdd2);
@@ -1014,7 +1014,7 @@ public:
}
strcat(RAM_volt_c, temp_buffer);
}
if (settings.showVDDQ && isMariko) {
if (RAM_volt_c[0] != '\0') {
strcat(RAM_volt_c, "");
@@ -1025,7 +1025,7 @@ public:
} else {
RAM_volt_c[0] = '\0'; // Empty if voltages disabled
}
/* ── Battery / power draw ───────────────────────────── */
char remainingBatteryLife[8];
@@ -1075,7 +1075,7 @@ public:
"%d°C %d%%",
(int)SOC_temperatureF, // SoC °C, no decimals
duty); // fan %
/* Integer SOC, PCB and skin temperatures + duty *
* skin_temperaturemiliC is in milli-degrees C → divide by 1000 */
snprintf(skin_temperature_c, sizeof skin_temperature_c,
@@ -1084,9 +1084,9 @@ public:
(int)PCB_temperatureF, // PCB
(uint16_t)(skin_temperaturemiliC / 1000), // skin
duty);
//if (settings.realVolts) {
// snprintf(SOC_volt_c, sizeof(SOC_volt_c), "%u.%u mV",
// snprintf(SOC_volt_c, sizeof(SOC_volt_c), "%u.%u mV",
// realSOC_mV/1000, (realSOC_mV/100)%10);
//}
@@ -1097,16 +1097,16 @@ public:
} else {
SOC_volt_c[0] = '\0'; // Clear the buffer when disabled
}
if (settings.realTemps) {
if (realCPU_Temp != 0) {
snprintf(CPU_temp_c, sizeof(CPU_temp_c), " %.1f°C", realCPU_Temp / 1000.0f);
snprintf(CPU_temp_c, sizeof(CPU_temp_c), "%.1f°C", realCPU_Temp / 1000.0f);
}
if (realGPU_Temp != 0) {
snprintf(GPU_temp_c, sizeof(GPU_temp_c), " %.1f°C", realGPU_Temp / 1000.0f);
snprintf(GPU_temp_c, sizeof(GPU_temp_c), "%.1f°C", realGPU_Temp / 1000.0f);
}
if (realRAM_Temp != 0) {
snprintf(RAM_temp_c, sizeof(RAM_temp_c), " %.1f°C", realRAM_Temp / 1000.0f);
snprintf(RAM_temp_c, sizeof(RAM_temp_c), "%.1f°C", realRAM_Temp / 1000.0f);
}
}
@@ -1176,20 +1176,20 @@ public:
m_resolutionOutput[out_iter].width = m_resolutionViewportCalls[x].width;
m_resolutionOutput[out_iter].height = m_resolutionViewportCalls[x].height;
m_resolutionOutput[out_iter].calls = m_resolutionViewportCalls[x].calls;
out_iter++;
out_iter++;
}
found = false;
if (out_iter == 8) break;
}
}
qsort(m_resolutionOutput, 8, sizeof(resolutionCalls), compare);
// Anti-flicker swap logic
static std::pair<uint16_t, uint16_t> old_res[2];
// Only swap if BOTH resolutions exist (prevent swapping with empty slot)
if (m_resolutionOutput[0].width && m_resolutionOutput[1].width) {
if ((m_resolutionOutput[0].width == old_res[1].first && m_resolutionOutput[0].height == old_res[1].second) ||
if ((m_resolutionOutput[0].width == old_res[1].first && m_resolutionOutput[0].height == old_res[1].second) ||
(m_resolutionOutput[1].width == old_res[0].first && m_resolutionOutput[1].height == old_res[0].second)) {
const uint16_t swap_width = m_resolutionOutput[0].width;
const uint16_t swap_height = m_resolutionOutput[0].height;
@@ -1199,31 +1199,31 @@ public:
m_resolutionOutput[1].height = swap_height;
}
}
// Format resolution string
if (m_resolutionOutput[0].width) {
if (settings.showFullResolution) {
if (!m_resolutionOutput[1].width) {
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dx%d",
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dx%d",
m_resolutionOutput[0].width, m_resolutionOutput[0].height);
}
else {
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dx%d%dx%d",
m_resolutionOutput[0].width, m_resolutionOutput[0].height,
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dx%d%dx%d",
m_resolutionOutput[0].width, m_resolutionOutput[0].height,
m_resolutionOutput[1].width, m_resolutionOutput[1].height);
}
} else {
if (!m_resolutionOutput[1].width) {
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dp",
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dp",
m_resolutionOutput[0].height);
}
else {
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dp%dp",
snprintf(RES_var_compressed_c, sizeof(RES_var_compressed_c), "%dp%dp",
m_resolutionOutput[0].height, m_resolutionOutput[1].height);
}
}
}
// Always store current resolutions for next frame comparison
old_res[0] = std::make_pair(m_resolutionOutput[0].width, m_resolutionOutput[0].height);
old_res[1] = std::make_pair(m_resolutionOutput[1].width, m_resolutionOutput[1].height);
@@ -1253,7 +1253,7 @@ public:
mutexUnlock(&mutex_Misc);
//static bool skipOnce = true;
if (!skipOnce) {
//static bool runOnce = true;
if (runOnce) {
@@ -1265,7 +1265,7 @@ public:
skipOnce = false;
}
}
virtual bool handleInput(u64 keysDown, u64 keysHeld, const HidTouchState &touchPos, HidAnalogStickState joyStickPosLeft, HidAnalogStickState joyStickPosRight) override {
if (isKeyComboPressed(keysHeld, keysDown)) {
isRendering = false;