1
0
mirror of https://github.com/esphome/esphome.git synced 2025-11-19 08:15:49 +00:00

Introduce encode_value/decode_value() template functions (#2662)

This commit is contained in:
Oxan van Leeuwen
2021-11-10 19:44:01 +01:00
committed by GitHub
parent 4d43396835
commit 99c775d8cb
3 changed files with 36 additions and 19 deletions

View File

@@ -350,17 +350,6 @@ std::string str_sprintf(const char *fmt, ...) {
return str;
}
uint16_t encode_uint16(uint8_t msb, uint8_t lsb) { return (uint16_t(msb) << 8) | uint16_t(lsb); }
std::array<uint8_t, 2> decode_uint16(uint16_t value) {
uint8_t msb = (value >> 8) & 0xFF;
uint8_t lsb = (value >> 0) & 0xFF;
return {msb, lsb};
}
uint32_t encode_uint32(uint8_t msb, uint8_t byte2, uint8_t byte3, uint8_t lsb) {
return (uint32_t(msb) << 24) | (uint32_t(byte2) << 16) | (uint32_t(byte3) << 8) | uint32_t(lsb);
}
std::string hexencode(const uint8_t *data, uint32_t len) {
char buf[20];
std::string res;