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

Slowly getting there

parent 634af243
...@@ -118,7 +118,7 @@ namespace csv_writer { ...@@ -118,7 +118,7 @@ namespace csv_writer {
Serial.println(); Serial.println();
sensor_commands::defineIntCallback("csv", setCSVinterval, " 60 (Sets CSV writing interval, in s)"); sensor_commands::defineIntCallback("csv", setCSVinterval, " 60 (Sets CSV writing interval, in s)");
sensor_commands::defineCallback("format_filesystem", formatFilesystem, "(Deletes the whole filesystem.)"); sensor_commands::defineCallback("format_filesystem", formatFilesystem, " (Deletes the whole filesystem.)");
} }
File openOrCreate() { File openOrCreate() {
......
...@@ -5,24 +5,35 @@ namespace sensor_commands { ...@@ -5,24 +5,35 @@ namespace sensor_commands {
const uint8_t MAX_COMMAND_SIZE = 30; const uint8_t MAX_COMMAND_SIZE = 30;
uint8_t callbacks_count = 0; uint8_t callbacks_count = 0;
struct Callback { struct Callback {
Callback(const char *s = 0, void (*f)(int32_t) = 0, const char *d = 0) :
name(s), function(f), doc(d) {
}
const char *name; const char *name;
void (*function)(int32_t); union {
void (*intFunction)(int32_t);
void (*voidFunction)(void);
};
const char *doc; const char *doc;
}; };
Callback callbacks[MAX_CALLBACKS]; Callback callbacks[MAX_CALLBACKS];
//NOTE: Probably possible to DRY
void defineCallback(const char *name, void (*function)(void), const char *doc) { void defineCallback(const char *name, void (*function)(void), const char *doc) {
if (callbacks_count < MAX_CALLBACKS) {
callbacks[callbacks_count].name = name;
callbacks[callbacks_count].voidFunction = function;
callbacks[callbacks_count].doc = doc;
callbacks_count++;
} else {
Serial.println(F("Too many callbacks have been defined."));
}
} }
void defineIntCallback(const char *name, void (*function)(int32_t), const char *doc) { void defineIntCallback(const char *name, void (*function)(int32_t), const char *doc) {
if (callbacks_count < MAX_CALLBACKS) { if (callbacks_count < MAX_CALLBACKS) {
callbacks[callbacks_count] = Callback(name, function, doc); callbacks[callbacks_count].name = name;
callbacks[callbacks_count].intFunction = function;
callbacks[callbacks_count].doc = doc;
callbacks_count++; callbacks_count++;
} else { } else {
Serial.println(F("Too many callbacks have been defined.")); Serial.println(F("Too many callbacks have been defined."));
...@@ -81,7 +92,7 @@ namespace sensor_commands { ...@@ -81,7 +92,7 @@ namespace sensor_commands {
Serial.print("("); Serial.print("(");
Serial.print(parameter); Serial.print(parameter);
Serial.println(")"); Serial.println(")");
callbacks[i].function(parameter); callbacks[i].intFunction(parameter);
return; return;
} }
} }
......
Supports Markdown
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