Files
ETcontroller_PRO/lib/utils/utils.cpp
2025-07-25 10:57:17 +02:00

63 lines
1.1 KiB
C++

#include "utils.h"
void printBytes(const char title[], const std::vector<uint8_t> &b)
{
Serial0.flush();
printf("%s: ", title);
for (auto v : b)
{
printf("0x%02x ", v);
}
printf("\n");
Serial0.flush();
}
void printBytes(const char title[], const std::vector<uint16_t> &b)
{
Serial0.flush();
printf("%s: ", title);
for (auto v : b)
{
printf("0x%04x ", v);
}
printf("\n");
Serial0.flush();
}
void printBool(const char title[], const std::vector<bool> &vals)
{
Serial0.flush();
printf("%s: ", title);
for (auto j(0); j < vals.size(); j++)
{
printf("%s ", vals.at(j) ? "True" : "False");
}
printf("\n");
Serial0.flush();
}
const std::string printBoolVec(const std::vector<bool> &vals)
{
std::string buf;
buf.reserve(vals.size() + 1);
buf.append("b");
for (const auto v : vals)
{
buf.append(v ? "1" : "0");
}
return buf;
}
const std::string printHex(const uint8_t val)
{
std::string buf(5, '\0');
sprintf(buf.data(), "0x%02x", val);
return buf;
}
const std::string printHex(const uint16_t val)
{
std::string buf(7, '\0');
sprintf(buf.data(), "0x%04x", val);
return buf;
}