Instead of storing each command in an array of size MaxCommands, they could be called from a single callback which then selects which command to call.
Saves SRAM on devices by moving the selection logic into program space.
Allows for all user EmbMessenger logic to be in one place, decluttering user code, although the EmbMessenger logic could still be kept in individual commands or adaptors.
Allows for arbitrary command IDs instead of 0-indexed.
Example usage:
void commandCallback(uint8_t command_id)
{
switch (command_id)
{
case 0: {
ping();
} break;
case 1: {
bool state;
messenger.read(state); // Can read data in callback instead of command
setLed(state);
} break;
case 2: {
bool rv;
rv = toggleLed();
messenger.write(rv); // Can write data in callback instead of command
} break;
case 77: { // Note Arbitrary CommandID
int16_t a = 0, b = 0, rv = 0;
messenger.read_and_validate(a, [](int16_t val){ return val > -16 && val < 128; });
messenger.read_and_validate(b, [](int16_t val){ return val > -16 && val < 128; });
add(a, b, rv);
messenger.write(rv);
} break;
}
}
void setup()
{
messenger.registerCommandCallback(commandCallback);
}
Instead of storing each command in an array of size
MaxCommands
, they could be called from a single callback which then selects which command to call.Example usage:
This feature is on hold until EmbGen is finished.