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
00798414
Commit
00798414
authored
Apr 17, 2021
by
Eric Duminil
Browse files
Slowly getting there
parent
634af243
Changes
2
Show whitespace changes
Inline
Side-by-side
ampel-firmware/csv_writer.cpp
View file @
00798414
...
...
@@ -118,7 +118,7 @@ namespace csv_writer {
Serial
.
println
();
sensor_commands
::
defineIntCallback
(
"csv"
,
setCSVinterval
,
" 60 (Sets CSV writing interval, in s)"
);
sensor_commands
::
defineCallback
(
"format_filesystem"
,
formatFilesystem
,
"(Deletes the whole filesystem.)"
);
sensor_commands
::
defineCallback
(
"format_filesystem"
,
formatFilesystem
,
"
(Deletes the whole filesystem.)"
);
}
File
openOrCreate
()
{
...
...
ampel-firmware/sensor_commands.cpp
View file @
00798414
...
...
@@ -5,24 +5,35 @@ namespace sensor_commands {
const
uint8_t
MAX_COMMAND_SIZE
=
30
;
uint8_t
callbacks_count
=
0
;
struct
Callback
{
Callback
(
const
char
*
s
=
0
,
void
(
*
f
)(
int32_t
)
=
0
,
const
char
*
d
=
0
)
:
name
(
s
),
function
(
f
),
doc
(
d
)
{
}
const
char
*
name
;
void
(
*
function
)(
int32_t
);
union
{
void
(
*
intFunction
)(
int32_t
);
void
(
*
voidFunction
)(
void
);
};
const
char
*
doc
;
};
Callback
callbacks
[
MAX_CALLBACKS
];
//NOTE: Probably possible to DRY
void
defineCallback
(
const
char
*
name
,
void
(
*
function
)(
void
),
const
char
*
doc
)
{
if
(
callbacks_count
<
MAX_CALLBACKS
)
{
callbacks
[
callbacks_count
].
name
=
name
;
callbacks
[
callbacks_count
].
voidFunction
=
function
;
callbacks
[
callbacks_count
].
doc
=
doc
;
callbacks_count
++
;
}
else
{
Serial
.
println
(
F
(
"Too many callbacks have been defined."
));
}
}
void
defineIntCallback
(
const
char
*
name
,
void
(
*
function
)(
int32_t
),
const
char
*
doc
)
{
if
(
callbacks_count
<
MAX_CALLBACKS
)
{
callbacks
[
callbacks_count
]
=
Callback
(
name
,
function
,
doc
);
callbacks
[
callbacks_count
].
name
=
name
;
callbacks
[
callbacks_count
].
intFunction
=
function
;
callbacks
[
callbacks_count
].
doc
=
doc
;
callbacks_count
++
;
}
else
{
Serial
.
println
(
F
(
"Too many callbacks have been defined."
));
...
...
@@ -81,7 +92,7 @@ namespace sensor_commands {
Serial
.
print
(
"("
);
Serial
.
print
(
parameter
);
Serial
.
println
(
")"
);
callbacks
[
i
].
f
unction
(
parameter
);
callbacks
[
i
].
intF
unction
(
parameter
);
return
;
}
}
...
...
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