diff --git a/include/sta/config.hpp b/include/sta/config.hpp index ee160b7..6864f86 100644 --- a/include/sta/config.hpp +++ b/include/sta/config.hpp @@ -1,4 +1,5 @@ #include #define STA_PRINTF_USE_STDLIB -#define STA_STDLIB_DISABLE \ No newline at end of file +#define STA_STDLIB_DISABLE +#define STA_DEBUGGING_ENABLED \ No newline at end of file diff --git a/include/sta/debug/debug.hpp b/include/sta/debug/debug.hpp index 7a09609..cf7cbd1 100644 --- a/include/sta/debug/debug.hpp +++ b/include/sta/debug/debug.hpp @@ -8,7 +8,7 @@ namespace sta { - extern Printable * Debug; + extern BasePrintable * Debug; } // namespace sta diff --git a/include/sta/debug/printing/printable.hpp b/include/sta/debug/printing/printable.hpp index c1b5bbc..4dc5a26 100644 --- a/include/sta/debug/printing/printable.hpp +++ b/include/sta/debug/printing/printable.hpp @@ -23,12 +23,16 @@ namespace sta */ enum class IntegerBase { - DEC, /**< Decimal */ - BIN, /**< Binary */ - HEX /**< Hexadecimal */ + BASE_DEC, /**< Decimal */ + BASE_BIN, /**< Binary */ + BASE_HEX /**< Hexadecimal */ }; - class Printable + /** + * @brief Base class for printable. Renamed to "BasePrintable" from "Printable" because the Arduino dev are dickheads. + * + */ + class BasePrintable { public: /** @@ -64,7 +68,7 @@ namespace sta * @param num 8-bit unsigned integer * @param base Integer base */ - void print(uint8_t num, IntegerBase base = IntegerBase::DEC); + void print(uint8_t num, IntegerBase base = IntegerBase::BASE_DEC); /** * @brief Print integer in selected base. @@ -72,7 +76,7 @@ namespace sta * @param num 16-bit unsigned integer * @param base Integer base */ - void print(uint16_t num, IntegerBase base = IntegerBase::DEC); + void print(uint16_t num, IntegerBase base = IntegerBase::BASE_DEC); /** * @brief Print integer in selected base. @@ -80,7 +84,7 @@ namespace sta * @param num 32-bit unsigned integer * @param base Integer base */ - void print(uint32_t num, IntegerBase base = IntegerBase::DEC); + void print(uint32_t num, IntegerBase base = IntegerBase::BASE_DEC); /** * @brief Print c-string. @@ -129,7 +133,7 @@ namespace sta * @param num 8-bit unsigned integer * @param base Integer base */ - void println(uint8_t num, IntegerBase base = IntegerBase::DEC); + void println(uint8_t num, IntegerBase base = IntegerBase::BASE_DEC); /** * @brief Print integer in selected base followed by a new-line. @@ -137,7 +141,7 @@ namespace sta * @param num 16-bit unsigned integer * @param base Integer base */ - void println(uint16_t num, IntegerBase base = IntegerBase::DEC); + void println(uint16_t num, IntegerBase base = IntegerBase::BASE_DEC); /** * @brief Print integer in selected base followed by a new-line. @@ -145,7 +149,7 @@ namespace sta * @param num 32-bit unsigned integer * @param base Integer base */ - void println(uint32_t num, IntegerBase base = IntegerBase::DEC); + void println(uint32_t num, IntegerBase base = IntegerBase::BASE_DEC); /** * @brief Print c-string followed by a new-line. diff --git a/include/sta/debug/printing/printable_printf.hpp b/include/sta/debug/printing/printable_printf.hpp index 2ef9ed6..1c26b0a 100644 --- a/include/sta/debug/printing/printable_printf.hpp +++ b/include/sta/debug/printing/printable_printf.hpp @@ -5,7 +5,7 @@ namespace sta { - class PrintablePrintf : public Printable + class PrintablePrintf : public BasePrintable { public: /** diff --git a/include/sta/debug/printing/printable_uart.hpp b/include/sta/debug/printing/printable_uart.hpp index d6ea375..85eac01 100644 --- a/include/sta/debug/printing/printable_uart.hpp +++ b/include/sta/debug/printing/printable_uart.hpp @@ -25,7 +25,7 @@ namespace sta * * @ingroup sta_core */ - class PrintableUART : public Printable + class PrintableUART : public BasePrintable { public: /** diff --git a/src/debug/printing/printable.cpp b/src/debug/printing/printable.cpp index f70582c..ead1af9 100644 --- a/src/debug/printing/printable.cpp +++ b/src/debug/printing/printable.cpp @@ -19,7 +19,7 @@ namespace sta { - void Printable::printf(const char * fmt, ...) + void BasePrintable::printf(const char * fmt, ...) { va_list args; va_start (args, fmt); @@ -28,116 +28,116 @@ namespace sta int n = vsnprintf(temp, 1, fmt, args); va_start (args, fmt); - char str[n]; - vsnprintf(str, n, fmt, args); + char str[n+1]; + vsnprintf(str, n+1, fmt, args); STA_ASSERT(n > 0); println(str); } - void Printable::print(char c) + void BasePrintable::print(char c) { print(&c, 1); } - void Printable::print(bool b) + void BasePrintable::print(bool b) { print(b ? "true" : "false"); } - void Printable::print(double d) + void BasePrintable::print(double d) { char buffer[64]; snprintf(buffer, sizeof(buffer), "%f", d); print(buffer); } - void Printable::print(uint8_t num, IntegerBase base) + void BasePrintable::print(uint8_t num, IntegerBase base) { printBase(num, base, "%" PRIu8, sizeof(num)); } - void Printable::print(uint16_t num, IntegerBase base) + void BasePrintable::print(uint16_t num, IntegerBase base) { printBase(num, base, "%" PRIu16, sizeof(num)); } - void Printable::print(uint32_t num, IntegerBase base) + void BasePrintable::print(uint32_t num, IntegerBase base) { printBase(num, base, "%" PRIu32, sizeof(num)); } - void Printable::print(const char * str) + void BasePrintable::print(const char * str) { print(str, strlen(str)); } - void Printable::println() + void BasePrintable::println() { print("\r\n", 2); } - void Printable::println(char c) + void BasePrintable::println(char c) { print(&c, 1); println(); } - void Printable::println(bool b) + void BasePrintable::println(bool b) { print(b); println(); } - void Printable::println(double d) + void BasePrintable::println(double d) { print(d); println(); } - void Printable::println(uint8_t num, IntegerBase base) + void BasePrintable::println(uint8_t num, IntegerBase base) { print(num, base); println(); } - void Printable::println(uint16_t num, IntegerBase base) + void BasePrintable::println(uint16_t num, IntegerBase base) { print(num, base); println(); } - void Printable::println(uint32_t num, IntegerBase base) + void BasePrintable::println(uint32_t num, IntegerBase base) { print(num, base); println(); } - void Printable::println(const char * str) + void BasePrintable::println(const char * str) { println(str, strlen(str)); } - void Printable::println(const char * str, size_t length) + void BasePrintable::println(const char * str, size_t length) { print(str, length); println(); } - void Printable::printBase(uintmax_t num, IntegerBase base, const char * fmt, size_t size) + void BasePrintable::printBase(uintmax_t num, IntegerBase base, const char * fmt, size_t size) { switch (base) { - case IntegerBase::DEC: + case IntegerBase::BASE_DEC: printDec(num, fmt); break; - case IntegerBase::BIN: + case IntegerBase::BASE_BIN: // Digits in base 2 = size in bytes * 8 printBin(num, size * 8); break; - case IntegerBase::HEX: + case IntegerBase::BASE_HEX: // Digits in base 16 = size in bytes * 2 printHex(num, size * 2); break; @@ -147,14 +147,14 @@ namespace sta } } - void Printable::printDec(uintmax_t num, const char * fmt) + void BasePrintable::printDec(uintmax_t num, const char * fmt) { char buffer[64]; snprintf(buffer, sizeof(buffer), fmt, static_cast(num)); print(buffer); } - void Printable::printBin(uintmax_t value, size_t digits) + void BasePrintable::printBin(uintmax_t value, size_t digits) { // Need 8 digits for every byte char buffer[sizeof(value) * 8]; @@ -179,7 +179,7 @@ namespace sta print(buffer, digits); } - void Printable::printHex(uintmax_t value, size_t digits) + void BasePrintable::printHex(uintmax_t value, size_t digits) { // Need 2 digits for every byte char buffer[sizeof(value) * 2];