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
c6e6f831
Commit
c6e6f831
authored
Apr 16, 2021
by
Eric Duminil
Browse files
Command starts with
parent
06f4a1d9
Changes
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/sensor_commands.cpp
View file @
c6e6f831
...
...
@@ -2,7 +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.
...
...
@@ -17,21 +17,30 @@ namespace sensor_commands {
Callback
callbacks
[
MAX_CALLBACKS
];
void
defineCallback
(
const
char
*
command
,
void
(
*
f
)(
void
*
),
void
*
d
)
{
void
defineCallback
(
const
char
*
n
,
void
(
*
f
)(
void
*
),
void
*
d
)
{
if
(
callbacks_count
<
MAX_CALLBACKS
)
{
callbacks
[
callbacks_count
]
=
Callback
(
command
,
f
,
d
);
callbacks
[
callbacks_count
]
=
Callback
(
n
,
f
,
d
);
callbacks_count
++
;
}
else
{
Serial
.
println
(
F
(
"Too many callbacks have been defined."
));
}
}
bool
startsWith
(
const
char
*
a
,
const
char
*
b
)
{
if
(
strncmp
(
a
,
b
,
strlen
(
b
))
==
0
)
return
1
;
return
0
;
}
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
++
)
{
if
(
startsWith
(
command
,
callbacks
[
i
].
name
))
{
Serial
.
print
(
"OHHHH YES!!!"
);
}
Serial
.
print
(
"Trying '"
);
Serial
.
print
(
callbacks
[
i
].
name
);
Serial
.
println
(
"'"
);
...
...
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