From 21811b7ad62211fb3a03574f71bb72c46ec55b08 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Thu, 16 Jun 2022 22:40:21 +1000 Subject: [PATCH] DrawHex dynamicLength --- source/Core/Drivers/OLED.cpp | 4 ++-- source/Core/Drivers/OLED.hpp | 2 +- source/Core/Threads/GUIThread.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/Core/Drivers/OLED.cpp b/source/Core/Drivers/OLED.cpp index ab436e0e..7c252c28 100644 --- a/source/Core/Drivers/OLED.cpp +++ b/source/Core/Drivers/OLED.cpp @@ -423,9 +423,9 @@ inline void stripLeaderZeros(char *buffer, uint8_t places) { } } } -void OLED::drawHex(uint32_t x, FontStyle fontStyle) { +void OLED::drawHex(uint32_t x, FontStyle fontStyle, uint8_t digits) { // print number to hex - for (uint_fast8_t i = 0; i < 8; i++) { + for (uint_fast8_t i = 0; i < digits; i++) { uint16_t value = (x >> (4 * (7 - i))) & 0b1111; drawChar(value + 2, fontStyle); } diff --git a/source/Core/Drivers/OLED.hpp b/source/Core/Drivers/OLED.hpp index 0d6f790c..f088f91a 100644 --- a/source/Core/Drivers/OLED.hpp +++ b/source/Core/Drivers/OLED.hpp @@ -89,7 +89,7 @@ public: // Draws a checkbox static void drawCheckbox(bool state) { drawSymbol((state) ? 16 : 17); } static void debugNumber(int32_t val, FontStyle fontStyle); - static void drawHex(uint32_t x, FontStyle fontStyle); + static void drawHex(uint32_t x, FontStyle fontStyle, uint8_t digits); static void drawSymbol(uint8_t symbolID); // Used for drawing symbols of a predictable width static void drawArea(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t *ptr); // Draw an area, but y must be aligned on 0/8 offset static void drawAreaSwapped(int16_t x, int8_t y, uint8_t wide, uint8_t height, const uint8_t *ptr); // Draw an area, but y must be aligned on 0/8 offset diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 3e5df310..d9268588 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -758,8 +758,10 @@ void showDebugMenu(void) { // Print device ID Numbers { uint64_t id = getDeviceID(); - OLED::drawHex((uint32_t)(id >> 32), FontStyle::SMALL); - OLED::drawHex((uint32_t)(id & 0xFFFFFFFF), FontStyle::SMALL); + OLED::drawHex((uint32_t)(id >> 32), FontStyle::SMALL, 2); + + OLED::drawHex((uint32_t)(id >> 32), FontStyle::SMALL, 8); + OLED::drawHex((uint32_t)(id & 0xFFFFFFFF), FontStyle::SMALL, 8); } break; case 10: