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
6d71a41e
Commit
6d71a41e
authored
Apr 17, 2021
by
Eric Duminil
Browse files
Refactor
parent
3546cc81
Changes
4
Show whitespace changes
Inline
Side-by-side
ampel-firmware/co2_sensor.cpp
View file @
6d71a41e
...
...
@@ -104,7 +104,7 @@ namespace sensor {
Serial
.
println
(
config
::
auto_calibrate_sensor
?
"ON."
:
"OFF."
);
sensor_commands
::
defineCallback
(
"co2"
,
setCO2forDebugging
,
" 1500 (Sets co2 level, for debugging purposes)"
);
sensor_commands
::
defineCallback
(
"timer"
,
setTimer
,
" 30 (Sets measurement interval)"
);
sensor_commands
::
defineCallback
(
"timer"
,
setTimer
,
" 30 (Sets measurement interval
, in s
)"
);
sensor_commands
::
defineCallback
(
"calibrate"
,
calibrateSensorToSpecificPPM
,
" 600 (Starts calibration process, to given ppm)"
);
sensor_commands
::
defineCallback
(
"calibrate!"
,
calibrateSensorRightNow
,
" 600 (Calibrates right now, to given ppm)"
);
...
...
ampel-firmware/csv_writer.cpp
View file @
6d71a41e
...
...
@@ -125,7 +125,7 @@ namespace csv_writer {
showFilesystemContent
();
Serial
.
println
();
sensor_commands
::
defineCallback
(
"csv"
,
setCSVinterval
,
" 60 (Sets CSV writing interval)"
);
sensor_commands
::
defineCallback
(
"csv"
,
setCSVinterval
,
" 60 (Sets CSV writing interval
, in s
)"
);
// sensor_commands::defineCallback("format_filesystem", FS_LIB.format);
}
...
...
ampel-firmware/mqtt.cpp
View file @
6d71a41e
...
...
@@ -44,7 +44,7 @@ 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
::
defineCallback
(
"mqtt"
,
setMQTTinterval
,
" 60 (Sets MQTT sending interval)"
);
sensor_commands
::
defineCallback
(
"mqtt"
,
setMQTTinterval
,
" 60 (Sets MQTT sending interval
, in s
)"
);
}
void
publish
(
const
String
&
timestamp
,
int16_t
co2
,
float
temperature
,
float
humidity
)
{
...
...
ampel-firmware/sensor_commands.cpp
View file @
6d71a41e
...
...
@@ -25,11 +25,7 @@ namespace sensor_commands {
}
}
bool
startsWith
(
const
char
*
a
,
const
char
*
b
)
{
return
!
strncmp
(
a
,
b
,
strlen
(
b
));
}
bool
parseCommand
(
const
char
*
command
,
char
*
function_name
,
int32_t
&
parameter
)
{
uint8_t
parseCommand
(
const
char
*
command
,
char
*
function_name
,
int32_t
&
parameter
)
{
char
split_command
[
MAX_COMMAND_SIZE
];
strlcpy
(
split_command
,
command
,
MAX_COMMAND_SIZE
);
Serial
.
print
(
F
(
"Received : '"
));
...
...
@@ -44,21 +40,22 @@ namespace sensor_commands {
}
strlcpy
(
function_name
,
part1
,
MAX_COMMAND_SIZE
);
arg
=
strtok
(
NULL
,
" "
);
uint8_t
code
=
0
;
if
(
arg
)
{
char
*
end
;
parameter
=
strtol
(
arg
,
&
end
,
10
);
if
(
*
end
)
{
// Second argument isn't a number
parameter
=
-
9999
;
code
=
2
;
}
}
else
{
parameter
=
-
9999
;
// No parameter
code
=
2
;
}
return
0
;
return
code
;
}
void
listAvailableCallbacks
()
{
Serial
.
println
(
F
(
"Message not supported. Available commands :"
));
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
Serial
.
print
(
" "
);
Serial
.
print
(
callbacks
[
i
].
name
);
...
...
@@ -70,7 +67,7 @@ namespace sensor_commands {
void
run
(
const
char
*
command
)
{
char
function_name
[
MAX_COMMAND_SIZE
];
int32_t
parameter
;
int32_t
parameter
=
0
;
parseCommand
(
command
,
function_name
,
parameter
);
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
...
...
@@ -84,6 +81,7 @@ namespace sensor_commands {
return
;
}
}
Serial
.
println
(
F
(
"Message not supported. Available commands :"
));
listAvailableCallbacks
();
}
}
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