preparing for better output of configuration data

This commit is contained in:
iceman1001 committed 2024-01-18 13:44:03 +01:00
1 parent 6170eea81e
commit 0e937e8cc6
2 files changed
+67

No files matched your search

+58
View File
@@ -558,6 +558,64 @@ char *sprint_ascii(const uint8_t *data, const size_t len) {
return sprint_ascii_ex(data, len, 0);
}
char *sprint_breakdown_bin(color_t color, const char* bs, int width, int padn, int bits, const char* msg) {
if (bs == NULL || width > 32) {
return NULL;
}
const char *prepad = " ";
const char *postmarker = "................................";
static char buf[32 + 120] = {0};
memset(buf, 0, sizeof(buf));
int8_t end = (width - padn - 1 - bits);
if (end < 0) {
end = 0;
}
switch (color) {
case C_GREEN: {
snprintf(buf, sizeof(buf), "%.*s" _GREEN_("%.*s") " %.*s - " _GREEN_("%s")
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
case C_RED: {
snprintf(buf, sizeof(buf), "%.*s" _RED_("%.*s") " %.*s - " _RED_("%s")
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
case C_YELLOW: {
snprintf(buf, sizeof(buf), "%.*s" _YELLOW_("%.*s") " %.*s - " _YELLOW_("%s")
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
case C_NONE:
default: {
snprintf(buf, sizeof(buf), "%.*s%.*s %.*s - %s"
, padn, prepad
, bits, bs + padn
, end, postmarker
, msg
);
break;
}
}
return buf;
}
int hex_to_bytes(const char *hexValue, uint8_t *bytesValue, size_t maxBytesValueLen) {
char buf[4] = {0};
int indx = 0;