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
06f4a1d9
Commit
06f4a1d9
authored
Apr 16, 2021
by
Eric Duminil
Browse files
Adding name to callbacks
parent
130d5dd4
Changes
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/sensor_commands.cpp
View file @
06f4a1d9
...
...
@@ -7,20 +7,19 @@ namespace sensor_commands {
// A callback contains both a function and a pointer to arbitrary data
// that will be passed as argument to the function.
struct
Callback
{
Callback
(
void
(
*
f
)(
void
*
)
=
0
,
void
*
d
=
0
)
:
function
(
f
),
data
(
d
)
{
Callback
(
const
char
*
s
=
0
,
void
(
*
f
)(
void
*
)
=
0
,
void
*
d
=
0
)
:
name
(
s
),
function
(
f
),
data
(
d
)
{
}
const
char
*
name
;
void
(
*
function
)(
void
*
);
void
*
data
;
};
Callback
callbacks
[
MAX_CALLBACKS
];
char
callback_names
[
MAX_CALLBACKS
][
MAX_COMMAND_SIZE
];
void
defineCallback
(
const
char
*
command
,
void
(
*
f
)(
void
*
),
void
*
d
)
{
if
(
callbacks_count
<
MAX_CALLBACKS
)
{
callbacks
[
callbacks_count
]
=
Callback
(
f
,
d
);
strlcpy
(
callback_names
[
callbacks_count
],
command
,
MAX_COMMAND_SIZE
);
callbacks
[
callbacks_count
]
=
Callback
(
command
,
f
,
d
);
callbacks_count
++
;
}
else
{
Serial
.
println
(
F
(
"Too many callbacks have been defined."
));
...
...
@@ -34,7 +33,7 @@ namespace sensor_commands {
// Test all the callbacks.
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
Serial
.
print
(
"Trying '"
);
Serial
.
print
(
callback
_names
[
i
]
);
Serial
.
print
(
callback
s
[
i
].
name
);
Serial
.
println
(
"'"
);
callbacks
[
i
].
function
(
callbacks
[
i
].
data
);
}
...
...
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