Commit 777b0531 authored by Eric Duminil's avatar Eric Duminil
Browse files

Renaming sensor_commands

parent 36230378
Pipeline #2830 passed with stage
in 1 minute and 42 seconds
......@@ -148,7 +148,7 @@ void loop() {
checkFlashButton();
while (Serial.available() > 0) {
sensor_commands::processIncomingByte(Serial.read());
sensor_console::processSerialInput(Serial.read());
}
if (sensor::processData()) {
......
......@@ -71,16 +71,17 @@ namespace sensor {
Serial.print(F("Auto-calibration is "));
Serial.println(config::auto_calibrate_sensor ? "ON." : "OFF.");
sensor_commands::defineIntCallback("co2", setCO2forDebugging, " 1500 (Sets co2 level, for debugging purposes)");
sensor_commands::defineIntCallback("timer", setTimer, " 30 (Sets measurement interval, in s)");
sensor_commands::defineIntCallback("calibrate", calibrateSensorToSpecificPPM,
sensor_console::defineIntCommand("co2", setCO2forDebugging, " 1500 (Sets co2 level, for debugging purposes)");
sensor_console::defineIntCommand("timer", setTimer, " 30 (Sets measurement interval, in s)");
sensor_console::defineCommand("calibrate", startCalibrationProcess, " (Starts calibration process)");
sensor_console::defineIntCommand("calibrate", calibrateSensorToSpecificPPM,
" 600 (Starts calibration process, to given ppm)");
sensor_commands::defineIntCallback("calibrate!", calibrateSensorRightNow,
sensor_console::defineIntCommand("calibrate!", calibrateSensorRightNow,
" 600 (Calibrates right now, to given ppm)");
sensor_commands::defineCallback("reset", []() {
sensor_console::defineCommand("reset", []() {
ESP.restart();
}, " (Restarts the sensor)");
sensor_commands::defineCallback("night_mode", led_effects::toggleNightMode, " (Toggles night mode on/off)");
sensor_console::defineCommand("night_mode", led_effects::toggleNightMode, " (Toggles night mode on/off)");
}
//NOTE: should timer deviation be used to adjust measurement_timestep?
......
......@@ -115,9 +115,9 @@ namespace csv_writer {
showFilesystemContent();
Serial.println();
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("show_csv", showCSVContent, " (Displays the complete CSV file on Serial)");
sensor_console::defineIntCommand("csv", setCSVinterval, " 60 (Sets CSV writing interval, in s)");
sensor_console::defineCommand("format_filesystem", formatFilesystem, " (Deletes the whole filesystem)");
sensor_console::defineCommand("show_csv", showCSVContent, " (Displays the complete CSV file on Serial)");
}
File openOrCreate() {
......
......@@ -47,7 +47,7 @@ namespace lorawan {
LMIC_reset();
// Join, but don't send anything yet.
LMIC_startJoining();
sensor_commands::defineIntCallback("lora", setLoRaInterval, " 300 (Sets LoRaWAN sending interval, in s)");
sensor_console::defineIntCommand("lora", setLoRaInterval, " 300 (Sets LoRaWAN sending interval, in s)");
}
// Checks if OTAA is connected, or if payload should be sent.
......
......@@ -36,8 +36,8 @@ namespace mqtt {
// mqttClient.setSocketTimeout(config::mqtt_timeout); //NOTE: somehow doesn't seem to have any effect on connect()
mqttClient.setServer(config::mqtt_server, config::mqtt_port);
sensor_commands::defineIntCallback("mqtt", setMQTTinterval, " 60 (Sets MQTT sending interval, in s)");
sensor_commands::defineCallback("local_ip", sendInfoAboutLocalNetwork,
sensor_console::defineIntCommand("mqtt", setMQTTinterval, " 60 (Sets MQTT sending interval, in s)");
sensor_console::defineCommand("local_ip", sendInfoAboutLocalNetwork,
" (Sends local IP and SSID via MQTT. Can be useful to find sensor)");
}
......@@ -79,7 +79,7 @@ namespace mqtt {
command[i] = message[i];
}
command[length] = 0;
sensor_commands::run(command);
sensor_console::runCommand(command);
led_effects::onBoardLEDOff();
}
......
#include "sensor_commands.h"
namespace sensor_commands {
namespace sensor_console {
const uint8_t MAX_CALLBACKS = 20;
const uint8_t MAX_COMMAND_SIZE = 30;
......@@ -19,7 +19,7 @@ namespace sensor_commands {
Callback callbacks[MAX_CALLBACKS];
//NOTE: Probably possible to DRY (with templates?)
void defineCallback(const char *name, void (*function)(void), const char *doc) {
void defineCommand(const char *name, void (*function)(void), const char *doc) {
if (callbacks_count < MAX_CALLBACKS) {
callbacks[callbacks_count].name = name;
callbacks[callbacks_count].voidFunction = function;
......@@ -31,7 +31,7 @@ namespace sensor_commands {
}
}
void defineIntCallback(const char *name, void (*function)(int32_t), const char *doc) {
void defineIntCommand(const char *name, void (*function)(int32_t), const char *doc) {
if (callbacks_count < MAX_CALLBACKS) {
callbacks[callbacks_count].name = name;
callbacks[callbacks_count].intFunction = function;
......@@ -81,13 +81,13 @@ namespace sensor_commands {
* Saves bytes from Serial.read() until enter is pressed, and tries to run the corresponding command.
* http://www.gammon.com.au/serial
*/
void processIncomingByte(const byte input_byte) {
void processSerialInput(const byte input_byte) {
static char input_line[MAX_COMMAND_SIZE];
static unsigned int input_pos = 0;
switch (input_byte) {
case '\n': // end of text
input_line[input_pos] = 0;
run(input_line);
runCommand(input_line);
input_pos = 0;
break;
case '\r': // discard carriage return
......@@ -119,7 +119,7 @@ namespace sensor_commands {
/*
* Tries to find the corresponding callback for a given command. Name and number of argument should fit.
*/
void run(const char *command) {
void runCommand(const char *command) {
char function_name[MAX_COMMAND_SIZE];
int32_t argument = 0;
bool has_argument;
......
#include <Arduino.h>
#include "led_effects.h"
/** Other scripts can use this namespace, in order to define callbacks.
/** Other scripts can use this namespace, in order to define commands, via callbacks.
* Those callbacks can then be used to send commands to the sensor (reset, calibrate, night mode, ...)
* The callbacks can either have no parameter, or one int32_t parameter.
*/
namespace sensor_commands {
void processIncomingByte(const byte in_byte);
void run(const char *command);
void defineIntCallback(const char *command, void (*function)(int32_t), const char *doc);
void defineCallback(const char *command, void (*function)(void), const char *doc);
namespace sensor_console {
void processSerialInput(const byte in_byte);
void runCommand(const char *command);
void defineIntCommand(const char *command, void (*function)(int32_t), const char *doc);
void defineCommand(const char *command, void (*function)(void), const char *doc);
}
......@@ -284,7 +284,7 @@ namespace web_server {
}
http.sendHeader("Location", "/");
http.send(303);
sensor_commands::run(http.arg("send").c_str());
sensor_console::runCommand(http.arg("send").c_str());
}
void handlePageNotFound() {
......
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