mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/sta-core.git
synced 2025-06-13 01:55:59 +00:00
Renamed some variables because Arduino.h is terrible as always
This commit is contained in:
parent
99a097b012
commit
645cbe09f0
@ -1,4 +1,5 @@
|
||||
#include <sta/devices/arduino/mcu/common.hpp>
|
||||
|
||||
#define STA_PRINTF_USE_STDLIB
|
||||
#define STA_STDLIB_DISABLE
|
||||
#define STA_STDLIB_DISABLE
|
||||
#define STA_DEBUGGING_ENABLED
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
extern Printable * Debug;
|
||||
extern BasePrintable * Debug;
|
||||
} // namespace sta
|
||||
|
||||
|
||||
|
@ -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.
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace sta
|
||||
{
|
||||
class PrintablePrintf : public Printable
|
||||
class PrintablePrintf : public BasePrintable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -25,7 +25,7 @@ namespace sta
|
||||
*
|
||||
* @ingroup sta_core
|
||||
*/
|
||||
class PrintableUART : public Printable
|
||||
class PrintableUART : public BasePrintable
|
||||
{
|
||||
public:
|
||||
/**
|
||||
|
@ -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<uint32_t>(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];
|
||||
|
Loading…
x
Reference in New Issue
Block a user