Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Käppler
ampel-firmware
Commits
130d5dd4
Commit
130d5dd4
authored
Apr 16, 2021
by
Eric Duminil
Browse files
Callback names
parent
81c4e10d
Changes
7
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
130d5dd4
...
...
@@ -149,10 +149,7 @@ void loop() {
if
(
Serial
.
available
()
>
0
)
{
commandString
=
Serial
.
readStringUntil
(
'\n'
);
Serial
.
print
(
F
(
"OHHHH. It would be cool to do something with : '"
));
Serial
.
print
(
commandString
);
Serial
.
println
(
"'"
);
sensor_commands
::
run
();
sensor_commands
::
run
(
commandString
.
c_str
());
}
if
(
sensor
::
processData
())
{
...
...
ampel-firmware/co2_sensor.cpp
View file @
130d5dd4
...
...
@@ -76,7 +76,7 @@ namespace sensor {
Serial
.
print
(
F
(
"Auto-calibration is "
));
Serial
.
println
(
config
::
auto_calibrate_sensor
?
"ON."
:
"OFF."
);
sensor_commands
::
defineCallback
(
printCO2
,
&
co2
);
sensor_commands
::
defineCallback
(
"co2"
,
printCO2
,
&
co2
);
}
//NOTE: should timer deviation be used to adjust measurement_timestep?
...
...
ampel-firmware/led_effects.cpp
View file @
130d5dd4
...
...
@@ -83,7 +83,7 @@ namespace led_effects {
pixels
.
setBrightness
(
config
::
max_brightness
);
LEDsOff
();
sensor_commands
::
defineCallback
(
helloRing
,
0
);
sensor_commands
::
defineCallback
(
"led"
,
helloRing
,
0
);
}
void
toggleNightMode
()
{
...
...
ampel-firmware/mqtt.cpp
View file @
130d5dd4
...
...
@@ -141,6 +141,8 @@ namespace mqtt {
messageString
+=
(
char
)
message
[
i
];
}
Serial
.
println
(
"'."
);
sensor_commands
::
run
(
messageString
.
c_str
());
return
;
//TODO: Move this logic to a separate class, which could be used by Serial/MQTT/WebServer
...
...
ampel-firmware/mqtt.h
View file @
130d5dd4
...
...
@@ -4,6 +4,7 @@
#include
<Arduino.h>
#include
"config.h"
#include
"led_effects.h"
#include
"sensor_commands.h"
#ifdef AMPEL_CSV
# include "csv_writer.h"
#endif
...
...
ampel-firmware/sensor_commands.cpp
View file @
130d5dd4
...
...
@@ -2,6 +2,7 @@
namespace
sensor_commands
{
const
uint8_t
MAX_CALLBACKS
=
20
;
const
uint8_t
MAX_COMMAND_SIZE
=
20
;
uint8_t
callbacks_count
=
0
;
// A callback contains both a function and a pointer to arbitrary data
// that will be passed as argument to the function.
...
...
@@ -14,19 +15,29 @@ namespace sensor_commands {
};
Callback
callbacks
[
MAX_CALLBACKS
];
char
callback_names
[
MAX_CALLBACKS
][
MAX_COMMAND_SIZE
];
void
defineCallback
(
void
(
*
f
)(
void
*
),
void
*
d
)
{
void
defineCallback
(
const
char
*
command
,
void
(
*
f
)(
void
*
),
void
*
d
)
{
if
(
callbacks_count
<
MAX_CALLBACKS
)
{
callbacks
[
callbacks_count
++
]
=
Callback
(
f
,
d
);
callbacks
[
callbacks_count
]
=
Callback
(
f
,
d
);
strlcpy
(
callback_names
[
callbacks_count
],
command
,
MAX_COMMAND_SIZE
);
callbacks_count
++
;
}
else
{
Serial
.
println
(
"OH NOOEEEESSS!!!! TOO MANY CALLBACKS"
);
Serial
.
println
(
F
(
"Too many callbacks have been defined."
)
);
}
}
void
run
()
{
void
run
(
const
char
*
command
)
{
Serial
.
print
(
F
(
"Received command : '"
));
Serial
.
print
(
command
);
Serial
.
println
(
"'"
);
// Test all the callbacks.
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
Serial
.
print
(
"Trying '"
);
Serial
.
print
(
callback_names
[
i
]);
Serial
.
println
(
"'"
);
callbacks
[
i
].
function
(
callbacks
[
i
].
data
);
}
Serial
.
println
(
"Done."
);
}
}
ampel-firmware/sensor_commands.h
View file @
130d5dd4
...
...
@@ -6,6 +6,6 @@
*/
namespace
sensor_commands
{
void
run
();
void
defineCallback
(
void
(
*
f
)(
void
*
),
void
*
d
);
void
run
(
const
char
*
command
);
void
defineCallback
(
const
char
*
command
,
void
(
*
f
)(
void
*
),
void
*
d
);
}
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