From 0609cdb2d32ef5aacd26f8733545b8e7dc174ad0 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 15 May 2020 15:54:51 +0200 Subject: [PATCH] Alternative to display INT_MIN correctly (#7557) INT_MIN/INT_MAX --- radio/src/gui/128x64/lcd.cpp | 13 +++++++++++++ radio/src/gui/212x64/lcd.cpp | 13 +++++++++++++ radio/src/gui/480x272/lcd.cpp | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/radio/src/gui/128x64/lcd.cpp b/radio/src/gui/128x64/lcd.cpp index c2c12fead..f3adae2ca 100644 --- a/radio/src/gui/128x64/lcd.cpp +++ b/radio/src/gui/128x64/lcd.cpp @@ -18,6 +18,7 @@ * GNU General Public License for more details. */ +#include #include "opentx.h" display_t displayBuf[DISPLAY_BUFFER_SIZE] __DMA; @@ -465,7 +466,19 @@ void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t le int idx = 0; int mode = MODE(flags); bool neg = false; + + if (val == INT_MAX) { + flags &= ~(LEADING0 | PREC1 | PREC2); + lcdDrawText(x, y, "INT_MAX", flags); + return; + } + if (val < 0) { + if (val == INT_MIN) { + flags &= ~(LEADING0 | PREC1 | PREC2); + lcdDrawText(x, y, "INT_MIN", flags); + return; + } val = -val; neg = true; } diff --git a/radio/src/gui/212x64/lcd.cpp b/radio/src/gui/212x64/lcd.cpp index c523643bb..a838003b3 100644 --- a/radio/src/gui/212x64/lcd.cpp +++ b/radio/src/gui/212x64/lcd.cpp @@ -18,6 +18,7 @@ * GNU General Public License for more details. */ +#include #include "opentx.h" #include "timers.h" @@ -402,7 +403,19 @@ void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t le int idx = 0; int mode = MODE(flags); bool neg = false; + + if (val == INT_MAX) { + flags &= ~(LEADING0 | PREC1 | PREC2); + lcdDrawText(x, y, "INT_MAX", flags); + return; + } + if (val < 0) { + if (val == INT_MIN) { + flags &= ~(LEADING0 | PREC1 | PREC2); + lcdDrawText(x, y, "INT_MIN", flags); + return; + } val = -val; neg = true; } diff --git a/radio/src/gui/480x272/lcd.cpp b/radio/src/gui/480x272/lcd.cpp index 34e8831d8..e2c660f73 100644 --- a/radio/src/gui/480x272/lcd.cpp +++ b/radio/src/gui/480x272/lcd.cpp @@ -20,6 +20,7 @@ #include #include +#include #include "opentx.h" #include "strhelpers.h" @@ -165,7 +166,19 @@ void lcdDrawNumber(coord_t x, coord_t y, int32_t val, LcdFlags flags, uint8_t le int idx = 0; int mode = MODE(flags); bool neg = false; + + if (val == INT_MAX) { + flags &= ~(LEADING0 | PREC1 | PREC2); + lcdDrawText(x, y, "INT_MAX", flags); + return; + } + if (val < 0) { + if (val == INT_MIN) { + flags &= ~(LEADING0 | PREC1 | PREC2); + lcdDrawText(x, y, "INT_MIN", flags); + return; + } val = -val; neg = true; }