Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
777b0531
Commit
777b0531
authored
Apr 18, 2021
by
Eric Duminil
Browse files
Renaming sensor_commands
parent
36230378
Pipeline
#2830
passed with stage
in 1 minute and 42 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
777b0531
...
...
@@ -148,7 +148,7 @@ void loop() {
checkFlashButton
();
while
(
Serial
.
available
()
>
0
)
{
sensor_co
mmands
::
process
IncomingByte
(
Serial
.
read
());
sensor_co
nsole
::
process
SerialInput
(
Serial
.
read
());
}
if
(
sensor
::
processData
())
{
...
...
ampel-firmware/co2_sensor.cpp
View file @
777b0531
...
...
@@ -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_co
mmands
::
defineIntC
allback
(
"calibrate!"
,
calibrateSensorRightNow
,
sensor_co
nsole
::
defineIntC
ommand
(
"calibrate!"
,
calibrateSensorRightNow
,
" 600 (Calibrates right now, to given ppm)"
);
sensor_co
mmands
::
defineC
allback
(
"reset"
,
[]()
{
sensor_co
nsole
::
defineC
ommand
(
"reset"
,
[]()
{
ESP
.
restart
();
},
" (Restarts the sensor)"
);
sensor_co
mmands
::
defineC
allback
(
"night_mode"
,
led_effects
::
toggleNightMode
,
" (Toggles night mode on/off)"
);
sensor_co
nsole
::
defineC
ommand
(
"night_mode"
,
led_effects
::
toggleNightMode
,
" (Toggles night mode on/off)"
);
}
//NOTE: should timer deviation be used to adjust measurement_timestep?
...
...
ampel-firmware/csv_writer.cpp
View file @
777b0531
...
...
@@ -115,9 +115,9 @@ namespace csv_writer {
showFilesystemContent
();
Serial
.
println
();
sensor_co
mmands
::
defineIntC
allback
(
"csv"
,
setCSVinterval
,
" 60 (Sets CSV writing interval, in s)"
);
sensor_co
mmands
::
defineC
allback
(
"format_filesystem"
,
formatFilesystem
,
" (Deletes the whole filesystem)"
);
sensor_co
mmands
::
defineC
allback
(
"show_csv"
,
showCSVContent
,
" (Displays the complete CSV file on Serial)"
);
sensor_co
nsole
::
defineIntC
ommand
(
"csv"
,
setCSVinterval
,
" 60 (Sets CSV writing interval, in s)"
);
sensor_co
nsole
::
defineC
ommand
(
"format_filesystem"
,
formatFilesystem
,
" (Deletes the whole filesystem)"
);
sensor_co
nsole
::
defineC
ommand
(
"show_csv"
,
showCSVContent
,
" (Displays the complete CSV file on Serial)"
);
}
File
openOrCreate
()
{
...
...
ampel-firmware/lorawan.cpp
View file @
777b0531
...
...
@@ -47,7 +47,7 @@ namespace lorawan {
LMIC_reset
();
// Join, but don't send anything yet.
LMIC_startJoining
();
sensor_co
mmands
::
defineIntC
allback
(
"lora"
,
setLoRaInterval
,
" 300 (Sets LoRaWAN sending interval, in s)"
);
sensor_co
nsole
::
defineIntC
ommand
(
"lora"
,
setLoRaInterval
,
" 300 (Sets LoRaWAN sending interval, in s)"
);
}
// Checks if OTAA is connected, or if payload should be sent.
...
...
ampel-firmware/mqtt.cpp
View file @
777b0531
...
...
@@ -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_co
mmands
::
defineIntC
allback
(
"mqtt"
,
setMQTTinterval
,
" 60 (Sets MQTT sending interval, in s)"
);
sensor_co
mmands
::
defineC
allback
(
"local_ip"
,
sendInfoAboutLocalNetwork
,
sensor_co
nsole
::
defineIntC
ommand
(
"mqtt"
,
setMQTTinterval
,
" 60 (Sets MQTT sending interval, in s)"
);
sensor_co
nsole
::
defineC
ommand
(
"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_co
mmands
::
run
(
command
);
sensor_co
nsole
::
runCommand
(
command
);
led_effects
::
onBoardLEDOff
();
}
...
...
ampel-firmware/sensor_commands.cpp
View file @
777b0531
#include
"sensor_commands.h"
namespace
sensor_co
mmands
{
namespace
sensor_co
nsole
{
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
defineC
allback
(
const
char
*
name
,
void
(
*
function
)(
void
),
const
char
*
doc
)
{
void
defineC
ommand
(
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
defineIntC
allback
(
const
char
*
name
,
void
(
*
function
)(
int32_t
),
const
char
*
doc
)
{
void
defineIntC
ommand
(
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
process
IncomingByte
(
const
byte
input_byte
)
{
void
process
SerialInput
(
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
);
run
Command
(
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
run
Command
(
const
char
*
command
)
{
char
function_name
[
MAX_COMMAND_SIZE
];
int32_t
argument
=
0
;
bool
has_argument
;
...
...
ampel-firmware/sensor_commands.h
View file @
777b0531
#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_co
mmands
{
void
process
IncomingByte
(
const
byte
in_byte
);
void
run
(
const
char
*
command
);
void
defineIntC
allback
(
const
char
*
command
,
void
(
*
function
)(
int32_t
),
const
char
*
doc
);
void
defineC
allback
(
const
char
*
command
,
void
(
*
function
)(
void
),
const
char
*
doc
);
namespace
sensor_co
nsole
{
void
process
SerialInput
(
const
byte
in_byte
);
void
run
Command
(
const
char
*
command
);
void
defineIntC
ommand
(
const
char
*
command
,
void
(
*
function
)(
int32_t
),
const
char
*
doc
);
void
defineC
ommand
(
const
char
*
command
,
void
(
*
function
)(
void
),
const
char
*
doc
);
}
ampel-firmware/web_server.cpp
View file @
777b0531
...
...
@@ -284,7 +284,7 @@ namespace web_server {
}
http
.
sendHeader
(
"Location"
,
"/"
);
http
.
send
(
303
);
sensor_co
mmands
::
run
(
http
.
arg
(
"send"
).
c_str
());
sensor_co
nsole
::
runCommand
(
http
.
arg
(
"send"
).
c_str
());
}
void
handlePageNotFound
()
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment