diff options
author | Ben V. Brown <[email protected]> | 2019-12-28 11:21:40 +1100 |
---|---|---|
committer | Ben V. Brown <[email protected]> | 2019-12-28 11:21:40 +1100 |
commit | 5974ece9272ff23dce930bdf5b0156fad155ec5f (patch) | |
tree | c694909ad20de15806f23a4ac6ea269028ba37a1 | |
parent | 3ca3b7fccaf59f7e196a256dd56424865e32b583 (diff) | |
download | IronOS-5974ece9272ff23dce930bdf5b0156fad155ec5f.tar.gz IronOS-5974ece9272ff23dce930bdf5b0156fad155ec5f.zip |
Dont blank entire string if all zero
-rw-r--r-- | workspace/TS100/Core/Src/OLED.cpp | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/workspace/TS100/Core/Src/OLED.cpp b/workspace/TS100/Core/Src/OLED.cpp index fab47ed4..646d24c4 100644 --- a/workspace/TS100/Core/Src/OLED.cpp +++ b/workspace/TS100/Core/Src/OLED.cpp @@ -155,7 +155,17 @@ void OLED::setFont(uint8_t fontNumber) { fontWidth = 12; } } - +inline void stripLeaderZeros(char *buffer) { + //Removing the leading zero's by swapping them to SymbolSpace + // Stop 1 short so that we dont blank entire number if its zero + for (int i = 0; i < 6; i++) { + if (buffer[i] == 2) { + buffer[i] = SymbolSpace[0]; + } else { + return; + } + } +} // maximum places is 5 void OLED::printNumber(uint16_t number, uint8_t places) { char buffer[7] = { 0 }; @@ -185,14 +195,7 @@ void OLED::printNumber(uint16_t number, uint8_t places) { } buffer[0] = 2 + number % 10; - //Removing the leading zero's by swapping them to SymbolSpace - for (int i = 0; i < 7; i++) { - if (buffer[i] == 2) { - buffer[i] = SymbolSpace[0]; - } else { - break; - } - } + stripLeaderZeros(buffer); print(buffer); } |