Commit c6e6f831 authored by Eric Duminil's avatar Eric Duminil
Browse files

Command starts with

parent 06f4a1d9
......@@ -2,7 +2,7 @@
namespace sensor_commands {
const uint8_t MAX_CALLBACKS = 20;
const uint8_t MAX_COMMAND_SIZE = 20;
uint8_t callbacks_count = 0;
// A callback contains both a function and a pointer to arbitrary data
// that will be passed as argument to the function.
......@@ -17,21 +17,30 @@ namespace sensor_commands {
Callback callbacks[MAX_CALLBACKS];
void defineCallback(const char *command, void (*f)(void*), void *d) {
void defineCallback(const char *n, void (*f)(void*), void *d) {
if (callbacks_count < MAX_CALLBACKS) {
callbacks[callbacks_count] = Callback(command, f, d);
callbacks[callbacks_count] = Callback(n, f, d);
callbacks_count++;
} else {
Serial.println(F("Too many callbacks have been defined."));
}
}
bool startsWith(const char *a, const char *b) {
if (strncmp(a, b, strlen(b)) == 0)
return 1;
return 0;
}
void run(const char *command) {
Serial.print(F("Received command : '"));
Serial.print(command);
Serial.println("'");
// Test all the callbacks.
for (uint8_t i = 0; i < callbacks_count; i++) {
if (startsWith(command, callbacks[i].name)) {
Serial.print("OHHHH YES!!!");
}
Serial.print("Trying '");
Serial.print(callbacks[i].name);
Serial.println("'");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment