mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 08:19:52 +03:00
prefix 0x to printing hex values (optional)
This commit is contained in:
@@ -23,8 +23,13 @@ namespace emsesp {
|
|||||||
uint8_t Helpers::bool_format_ = BOOL_FORMAT_ONOFF; // on/off
|
uint8_t Helpers::bool_format_ = BOOL_FORMAT_ONOFF; // on/off
|
||||||
|
|
||||||
// like itoa but for hex, and quicker
|
// like itoa but for hex, and quicker
|
||||||
char * Helpers::hextoa(char * result, const uint8_t value) {
|
// only for single byte hex values
|
||||||
char * p = result;
|
char * Helpers::hextoa(char * result, const uint8_t value, bool prefix) {
|
||||||
|
char * p = result;
|
||||||
|
if (prefix) {
|
||||||
|
*p++ = '0';
|
||||||
|
*p++ = 'x';
|
||||||
|
}
|
||||||
uint8_t nib1 = (value >> 4) & 0x0F;
|
uint8_t nib1 = (value >> 4) & 0x0F;
|
||||||
uint8_t nib2 = (value >> 0) & 0x0F;
|
uint8_t nib2 = (value >> 0) & 0x0F;
|
||||||
*p++ = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
|
*p++ = nib1 < 0xA ? '0' + nib1 : 'A' + nib1 - 0xA;
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ namespace emsesp {
|
|||||||
|
|
||||||
class Helpers {
|
class Helpers {
|
||||||
public:
|
public:
|
||||||
static char * hextoa(char * result, const uint8_t value);
|
static char * hextoa(char * result, const uint8_t value, bool prefix = false);
|
||||||
static std::string data_to_hex(const uint8_t * data, const uint8_t length);
|
static std::string data_to_hex(const uint8_t * data, const uint8_t length);
|
||||||
|
|
||||||
static char * render_value(char * result, const float value, const uint8_t format); // format is the precision
|
static char * render_value(char * result, const float value, const uint8_t format); // format is the precision
|
||||||
|
|||||||
Reference in New Issue
Block a user