mirror of
https://github.com/MatMoul/g810-led.git
synced 2024-12-23 09:16:11 +00:00
Add utility to convert string to uint16_t
Purpose for this is for command argument parsing of vendor and product IDs Signed-off-by: Kevin Pearson <pearson.kevin.m@gmail.com>
This commit is contained in:
parent
4b2a1002e8
commit
53876ac54e
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user