Fixed conversion for bases other than 10
This commit is contained in:
parent
8d07e2d4db
commit
b6c1c3b51b
11
uart.hpp
11
uart.hpp
@ -28,7 +28,7 @@ static constexpr size_t cntDigits()
|
||||
}
|
||||
|
||||
do {
|
||||
num /= 10;
|
||||
num /= Base;
|
||||
++cnt;
|
||||
} while (num > 0);
|
||||
|
||||
@ -107,9 +107,11 @@ class Uart {
|
||||
}
|
||||
|
||||
template <typename T, size_t Base = 10>
|
||||
static inline void txNumber(const T &val)
|
||||
static void txNumber(const T &val)
|
||||
{
|
||||
static_assert(util::is_integral_v<T>, "Only supported on integral types");
|
||||
static_assert(Base >= 2, "Numbers with bases less than 2 make no sense");
|
||||
static_assert(Base <= 16, "Numbers with bases higher than 16 are not supported");
|
||||
|
||||
constexpr size_t numDigits = detail::maxNumDigits<T, Base>();
|
||||
data_t buffer[numDigits];
|
||||
@ -124,7 +126,7 @@ class Uart {
|
||||
|
||||
do {
|
||||
data_t lastDigit = digits % Base;
|
||||
*bufEnd-- = '0' + lastDigit;
|
||||
*bufEnd-- = (lastDigit < 10) ? ('0' + lastDigit) : ('a' + lastDigit - 10);
|
||||
digits /= Base;
|
||||
} while (digits > 0);
|
||||
|
||||
@ -239,7 +241,8 @@ class Uart {
|
||||
|
||||
Uart &operator<<(const void *val)
|
||||
{
|
||||
txNumber(reinterpret_cast<uint16_t>(val));
|
||||
txString(F("0x"));
|
||||
txNumber<uint16_t, 16>(reinterpret_cast<uint16_t>(val));
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user