From 45cc32b50adad10d5d742e3ed672d87b95c44afd Mon Sep 17 00:00:00 2001 From: jgromes Date: Sat, 19 Jul 2025 19:27:31 +0200 Subject: [PATCH] [Print] Chore: uncrustify formatting --- src/protocols/Print/ITA2String.cpp | 18 ++++++------ src/protocols/Print/ITA2String.h | 18 ++++++------ src/protocols/Print/Print.cpp | 47 ++++++++++++++++++------------ src/protocols/Print/Print.h | 26 +++++++++-------- 4 files changed, 61 insertions(+), 48 deletions(-) diff --git a/src/protocols/Print/ITA2String.cpp b/src/protocols/Print/ITA2String.cpp index 809a1c56..de547f10 100644 --- a/src/protocols/Print/ITA2String.cpp +++ b/src/protocols/Print/ITA2String.cpp @@ -20,7 +20,7 @@ ITA2String::ITA2String(const char* str) { ita2Len = 0; } -ITA2String::ITA2String(const ITA2String& ita2) { +ITA2String::ITA2String(const ITA2String &ita2) { this->asciiLen = ita2.asciiLen; this->ita2Len = ita2.ita2Len; #if !RADIOLIB_STATIC_ONLY @@ -29,7 +29,7 @@ ITA2String::ITA2String(const ITA2String& ita2) { strcpy(this->strAscii, ita2.strAscii); } -ITA2String& ITA2String::operator=(const ITA2String& ita2) { +ITA2String &ITA2String::operator=(const ITA2String &ita2) { if(&ita2 != this) { this->asciiLen = ita2.asciiLen; this->ita2Len = ita2.ita2Len; @@ -43,7 +43,7 @@ ITA2String& ITA2String::operator=(const ITA2String& ita2) { ITA2String::~ITA2String() { #if !RADIOLIB_STATIC_ONLY - delete[] strAscii; + delete[] strAscii; #endif } @@ -62,14 +62,14 @@ size_t ITA2String::length() { uint8_t* ITA2String::byteArr() { // create temporary array 2x the string length (figures may be 3 bytes) #if RADIOLIB_STATIC_ONLY - uint8_t temp[RADIOLIB_STATIC_ARRAY_SIZE*2 + 1]; + uint8_t temp[RADIOLIB_STATIC_ARRAY_SIZE * 2 + 1]; #else - uint8_t* temp = new uint8_t[asciiLen*2 + 1]; + uint8_t* temp = new uint8_t[asciiLen * 2 + 1]; #endif // ensure the minimum possible array size is always initialized temp[0] = 0; - + size_t arrayLen = 0; bool flagFigure = false; for(size_t i = 0; i < asciiLen; i++) { @@ -89,7 +89,7 @@ uint8_t* ITA2String::byteArr() { // check the following character (skip for message end) if(i < (asciiLen - 1)) { - uint16_t nextCode = getBits(strAscii[i+1]); + uint16_t nextCode = getBits(strAscii[i + 1]); uint8_t nextShift = (nextCode >> 5) & 0b11111; if(nextShift == RADIOLIB_ITA2_LTRS) { // next character is a letter, terminate figure shift @@ -112,7 +112,7 @@ uint8_t* ITA2String::byteArr() { uint8_t* arr = new uint8_t[arrayLen]; memcpy(arr, temp, arrayLen); #if !RADIOLIB_STATIC_ONLY - delete[] temp; + delete[] temp; #endif return(arr); @@ -128,7 +128,7 @@ uint16_t ITA2String::getBits(char c) { code = (RADIOLIB_ITA2_LTRS << 5) | i; break; } - + ptr = const_cast(&ITA2Table[i][1]); if(RADIOLIB_NONVOLATILE_READ_BYTE(ptr) == c) { // character is in figures shift diff --git a/src/protocols/Print/ITA2String.h b/src/protocols/Print/ITA2String.h index 70e7b4b0..2da9f48b 100644 --- a/src/protocols/Print/ITA2String.h +++ b/src/protocols/Print/ITA2String.h @@ -8,8 +8,8 @@ #define RADIOLIB_ITA2_LENGTH 32 // ITA2 character table: - position in array corresponds to 5-bit ITA2 code -// - characters to the left are in letters shift, characters to the right in figures shift -// - characters marked 0x7F do not have ASCII equivalent +// - characters to the left are in letters shift, characters to the right in figures shift +// - characters marked 0x7F do not have ASCII equivalent static const char ITA2Table[RADIOLIB_ITA2_LENGTH][2] RADIOLIB_NONVOLATILE = { {'\0', '\0'}, {'E', '3'}, {'\n', '\n'}, {'A', '-'}, {' ', ' '}, {'S', '\''}, {'I', '8'}, {'U', '7'}, {'\r', '\r'}, {'D', 0x05}, {'R', '4'}, {'J', '\a'}, {'N', ','}, {'F', '!'}, {'C', ':'}, {'K', '('}, @@ -39,13 +39,13 @@ class ITA2String { \brief Copy constructor. \param ita2 ITA2String instance to copy. */ - ITA2String(const ITA2String& ita2); - + ITA2String(const ITA2String &ita2); + /*! \brief Overload for assignment operator. \param ita2 rvalue ITA2String. */ - ITA2String& operator=(const ITA2String& ita2); + ITA2String &operator=(const ITA2String &ita2); /*! \brief Default destructor. @@ -65,13 +65,13 @@ class ITA2String { */ uint8_t* byteArr(); -#if !RADIOLIB_GODMODE + #if !RADIOLIB_GODMODE private: -#endif + #endif #if RADIOLIB_STATIC_ONLY - char strAscii[RADIOLIB_STATIC_ARRAY_SIZE]; + char strAscii[RADIOLIB_STATIC_ARRAY_SIZE]; #else - char* strAscii; + char* strAscii; #endif size_t asciiLen; size_t ita2Len; diff --git a/src/protocols/Print/Print.cpp b/src/protocols/Print/Print.cpp index fffa26c4..1362a0f6 100644 --- a/src/protocols/Print/Print.cpp +++ b/src/protocols/Print/Print.cpp @@ -3,7 +3,7 @@ #include #include -size_t RadioLibPrint::print(ITA2String& ita2) { +size_t RadioLibPrint::print(ITA2String &ita2) { uint8_t enc = this->encoding; this->encoding = RADIOLIB_ITA2; uint8_t* arr = ita2.byteArr(); @@ -13,17 +13,20 @@ size_t RadioLibPrint::print(ITA2String& ita2) { return(n); } -size_t RadioLibPrint::println(ITA2String& ita2) { +size_t RadioLibPrint::println(ITA2String &ita2) { size_t n = RadioLibPrint::print(ita2); n += RadioLibPrint::println(); return(n); } -size_t RadioLibPrint::write(const uint8_t *buffer, size_t size) { +size_t RadioLibPrint::write(const uint8_t* buffer, size_t size) { size_t n = 0; - while (size--) { - if (write(*buffer++)) n++; - else break; + while(size--) { + if(write(*buffer++)) { + n++; + } else { + break; + } } return n; } @@ -43,9 +46,9 @@ size_t RadioLibPrint::print(const __FlashStringHelper* fstr) { // dynamically allocate memory #if RADIOLIB_STATIC_ONLY - char str[RADIOLIB_STATIC_ARRAY_SIZE]; + char str[RADIOLIB_STATIC_ARRAY_SIZE]; #else - char* str = new char[len]; + char* str = new char[len]; #endif // copy string from flash @@ -62,12 +65,12 @@ size_t RadioLibPrint::print(const __FlashStringHelper* fstr) { n = write(reinterpret_cast(str), len); } #if !RADIOLIB_STATIC_ONLY - delete[] str; + delete[] str; #endif return(n); } -size_t RadioLibPrint::print(const String& str) { +size_t RadioLibPrint::print(const String &str) { size_t n = 0; if(this->encoding == RADIOLIB_ITA2) { ITA2String ita2 = ITA2String(str.c_str()); @@ -84,7 +87,7 @@ size_t RadioLibPrint::println(const __FlashStringHelper* fstr) { return(n); } -size_t RadioLibPrint::println(const String& str) { +size_t RadioLibPrint::println(const String &str) { size_t n = RadioLibPrint::print(str); n += RadioLibPrint::println(); return(n); @@ -129,7 +132,7 @@ size_t RadioLibPrint::print(long n, int base) { if(base == 0) { return(write(n)); } else if(base == DEC) { - if (n < 0) { + if(n < 0) { int t = RadioLibPrint::print('-'); n = -n; return(RadioLibPrint::printNumber(n, DEC) + t); @@ -213,7 +216,7 @@ size_t RadioLibPrint::println(void) { size_t RadioLibPrint::printNumber(unsigned long n, uint8_t base) { char buf[8 * sizeof(long) + 1]; - char *str = &buf[sizeof(buf) - 1]; + char* str = &buf[sizeof(buf) - 1]; *str = '\0'; @@ -246,11 +249,19 @@ size_t RadioLibPrint::printFloat(double number, uint8_t digits) { size_t n = 0; char code[] = {0x00, 0x00, 0x00, 0x00}; - if (isnan(number)) strcpy(code, "nan"); - if (isinf(number)) strcpy(code, "inf"); - if (number > (double)4294967040.0) strcpy(code, "ovf"); // constant determined empirically - if (number < (double)-4294967040.0) strcpy(code, "ovf"); // constant determined empirically + if(isnan(number)) { + strcpy(code, "nan"); + } + if(isinf(number)) { + strcpy(code, "inf"); + } + if(number > (double)4294967040.0) { + strcpy(code, "ovf"); // constant determined empirically + } + if(number < (double)-4294967040.0) { + strcpy(code, "ovf"); // constant determined empirically + } if(code[0] != 0x00) { if(this->encoding == RADIOLIB_ITA2) { ITA2String ita2 = ITA2String(code); @@ -264,7 +275,7 @@ size_t RadioLibPrint::printFloat(double number, uint8_t digits) { } // Handle negative numbers - if (number < (double)0.0) { + if(number < (double)0.0) { if(this->encoding == RADIOLIB_ITA2) { ITA2String ita2 = ITA2String("-"); uint8_t* arr = ita2.byteArr(); diff --git a/src/protocols/Print/Print.h b/src/protocols/Print/Print.h index 3645416f..2bb3f8b7 100644 --- a/src/protocols/Print/Print.h +++ b/src/protocols/Print/Print.h @@ -17,23 +17,25 @@ class RadioLibPrint { public: virtual size_t write(uint8_t) = 0; - size_t write(const char *str) { - if (str == NULL) return 0; - return write(reinterpret_cast(str), strlen(str)); + size_t write(const char* str) { + if(str == NULL) { + return 0; + } + return write(reinterpret_cast(str), strlen(str)); } - virtual size_t write(const uint8_t *buffer, size_t size); - size_t write(const char *buffer, size_t size) { - return write(reinterpret_cast(buffer), size); + virtual size_t write(const uint8_t* buffer, size_t size); + size_t write(const char* buffer, size_t size) { + return write(reinterpret_cast(buffer), size); } - size_t print(ITA2String& ita2); - size_t println(ITA2String& ita2); + size_t print(ITA2String &ita2); + size_t println(ITA2String &ita2); #if defined(RADIOLIB_BUILD_ARDUINO) - size_t print(const __FlashStringHelper *); + size_t print(const __FlashStringHelper*); size_t print(const String &); - size_t println(const __FlashStringHelper *); + size_t println(const __FlashStringHelper*); size_t println(const String &); #endif @@ -56,9 +58,9 @@ class RadioLibPrint { size_t println(double, int = 2); size_t println(void); -#if !RADIOLIB_GODMODE + #if !RADIOLIB_GODMODE protected: -#endif + #endif uint8_t encoding = RADIOLIB_ASCII_EXTENDED; const char* lineFeed = "\r\n";