diff --git a/src/helpers/utils.cpp b/src/helpers/utils.cpp index 56c793d..0ea5e0d 100644 --- a/src/helpers/utils.cpp +++ b/src/helpers/utils.cpp @@ -216,4 +216,12 @@ namespace utils { return true; } + bool parseUInt16(std::string val, uint16_t &uint16) { + if (val.length() == 1) val = "0" + val; + if (val.length() == 2) val = "0" + val; + if (val.length() == 3) val = "0" + val; + if (val.length() != 4) return false; + uint16 = std::stoul("0x" + val, nullptr, 16); + return true; + } } diff --git a/src/helpers/utils.h b/src/helpers/utils.h index 5b7a52c..92de26b 100644 --- a/src/helpers/utils.h +++ b/src/helpers/utils.h @@ -16,6 +16,7 @@ namespace utils { bool parseColor(std::string val, LedKeyboard::Color &color); bool parseSpeed(std::string val, uint8_t &speed); bool parseUInt8(std::string val, uint8_t &uint8); + bool parseUInt16(std::string val, uint16_t &uint16); }