For a domotica project I want to emulate a Bluetooth keyboard. The domotica bridge can sent strings of data to a ESP32… The library has a bunch of key’s declared as const. Like:
How can I convert an incoming string like “KEY_UP_ARROW” to the const? Or do I really need to create long if else solution like this:
if (strcmp(incomingString, "KEY_UP_ARROW")==0) {
result = KEY_UP_ARROW;
}
else if (strcmp(incomingString, "KEY_DOWN_ARROW")==0) {
result = KEY_DOWN_ARROW;
}
Surely there must be an more elegant and easier way.
Rather than send a string, you could always just send the key value directly as a single byte and avoid all the compares. Or maybe send the hex value as ascii (e.g. "DA" ) and then convert that to its actual value.