Commit 32f8968b authored by Eric Duminil's avatar Eric Duminil
Browse files

Set CO2 for debugging

parent 755f8578
...@@ -25,11 +25,10 @@ namespace sensor { ...@@ -25,11 +25,10 @@ namespace sensor {
uint32_t waiting_color = color::blue; uint32_t waiting_color = color::blue;
bool should_calibrate = false; bool should_calibrate = false;
void printCO2(void *data) { void setCO2forDebugging(int32_t fakeCo2) {
int parameter = *(uint16_t*) data; Serial.print(F("DEBUG. Setting CO2 to "));
Serial.print("NICE! HELLO FROM SENSOR."); co2 = fakeCo2;
Serial.print("CO2 : "); Serial.println(co2);
Serial.println(parameter);
} }
void initialize() { void initialize() {
...@@ -76,7 +75,7 @@ namespace sensor { ...@@ -76,7 +75,7 @@ namespace sensor {
Serial.print(F("Auto-calibration is ")); Serial.print(F("Auto-calibration is "));
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF."); Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
sensor_commands::defineCallback("co2", printCO2, &co2); sensor_commands::defineCallback("co2", setCO2forDebugging);
} }
//NOTE: should timer deviation be used to adjust measurement_timestep? //NOTE: should timer deviation be used to adjust measurement_timestep?
......
...@@ -70,7 +70,7 @@ namespace led_effects { ...@@ -70,7 +70,7 @@ namespace led_effects {
onBoardLEDOff(); onBoardLEDOff();
} }
void helloRing(void *c) { void helloRing(int32_t x) {
Serial.print("HELLO FROM LED RINGS!"); Serial.print("HELLO FROM LED RINGS!");
Serial.print("I have "); Serial.print("I have ");
Serial.print(NUMPIXELS); Serial.print(NUMPIXELS);
...@@ -83,7 +83,7 @@ namespace led_effects { ...@@ -83,7 +83,7 @@ namespace led_effects {
pixels.setBrightness(config::max_brightness); pixels.setBrightness(config::max_brightness);
LEDsOff(); LEDsOff();
sensor_commands::defineCallback("led", helloRing, 0); sensor_commands::defineCallback("led", helloRing);
} }
void toggleNightMode() { void toggleNightMode() {
......
...@@ -8,19 +8,18 @@ namespace sensor_commands { ...@@ -8,19 +8,18 @@ namespace sensor_commands {
// A callback contains both a function and a pointer to arbitrary data // A callback contains both a function and a pointer to arbitrary data
// that will be passed as argument to the function. // that will be passed as argument to the function.
struct Callback { struct Callback {
Callback(const char *s = 0, void (*f)(void*) = 0, void *d = 0) : Callback(const char *s = 0, void (*f)(int32_t) = 0) :
name(s), function(f), data(d) { name(s), function(f) {
} }
const char *name; const char *name;
void (*function)(void*); void (*function)(int32_t);
void *data;
}; };
Callback callbacks[MAX_CALLBACKS]; Callback callbacks[MAX_CALLBACKS];
void defineCallback(const char *n, void (*f)(void*), void *d) { void defineCallback(const char *n, void (*f)(int32_t)) {
if (callbacks_count < MAX_CALLBACKS) { if (callbacks_count < MAX_CALLBACKS) {
callbacks[callbacks_count] = Callback(n, f, d); callbacks[callbacks_count] = Callback(n, f);
callbacks_count++; callbacks_count++;
} else { } else {
Serial.println(F("Too many callbacks have been defined.")); Serial.println(F("Too many callbacks have been defined."));
...@@ -31,7 +30,7 @@ namespace sensor_commands { ...@@ -31,7 +30,7 @@ namespace sensor_commands {
return !strncmp(a, b, strlen(b)); return !strncmp(a, b, strlen(b));
} }
bool parseCommand(const char *command, char *function_name, long &parameter) { bool parseCommand(const char *command, char *function_name, int32_t &parameter) {
char split_command[MAX_COMMAND_SIZE]; char split_command[MAX_COMMAND_SIZE];
strlcpy(split_command, command, MAX_COMMAND_SIZE); strlcpy(split_command, command, MAX_COMMAND_SIZE);
Serial.print(F("Received : '")); Serial.print(F("Received : '"));
...@@ -69,7 +68,7 @@ namespace sensor_commands { ...@@ -69,7 +68,7 @@ namespace sensor_commands {
void run(const char *command) { void run(const char *command) {
char function_name[MAX_COMMAND_SIZE]; char function_name[MAX_COMMAND_SIZE];
long parameter; int32_t parameter;
if (parseCommand(command, function_name, parameter)) { if (parseCommand(command, function_name, parameter)) {
listAvailableCallbacks(); listAvailableCallbacks();
return; return;
...@@ -79,14 +78,13 @@ namespace sensor_commands { ...@@ -79,14 +78,13 @@ namespace sensor_commands {
Serial.print("'. Parameter : "); Serial.print("'. Parameter : ");
Serial.println(parameter); Serial.println(parameter);
// Test all the callbacks.
for (uint8_t i = 0; i < callbacks_count; i++) { for (uint8_t i = 0; i < callbacks_count; i++) {
if (!strcmp(function_name, callbacks[i].name)) { if (!strcmp(function_name, callbacks[i].name)) {
Serial.print("Function found!!!"); Serial.print("Function found!!!");
Serial.print("Trying '"); Serial.print("Trying '");
Serial.print(callbacks[i].name); Serial.print(callbacks[i].name);
Serial.println("'"); Serial.println("'");
callbacks[i].function(callbacks[i].data); callbacks[i].function(parameter);
return; return;
} }
} }
......
...@@ -7,5 +7,5 @@ ...@@ -7,5 +7,5 @@
namespace sensor_commands { namespace sensor_commands {
void run(const char *command); void run(const char *command);
void defineCallback(const char *command, void (*f)(void*), void *d); void defineCallback(const char *command, void (*f)(int32_t));
} }
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