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
8dd0b6cd
Commit
8dd0b6cd
authored
Apr 16, 2021
by
Eric Duminil
Browse files
Very basic example, with callbacks
parent
77831ea4
Changes
4
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.h
View file @
8dd0b6cd
...
...
@@ -33,10 +33,10 @@
#endif
#include
"util.h"
#include
"sensor_commands.h"
#include
"co2_sensor.h"
#include
"led_effects.h"
void
keepServicesAlive
();
void
checkFlashButton
();
...
...
ampel-firmware/ampel-firmware.ino
View file @
8dd0b6cd
...
...
@@ -56,7 +56,6 @@
* and define your credentials and parameters in 'config.h'.
*/
/*****************************************************************
* PreInit *
*****************************************************************/
...
...
@@ -68,6 +67,7 @@ void preinit() {
#endif
}
String
commandString
;
/*****************************************************************
* Setup *
...
...
@@ -89,6 +89,8 @@ void setup() {
Serial
.
print
(
F
(
"Board : "
));
Serial
.
println
(
BOARD
);
sensor_commands
::
initialize
();
#ifdef AMPEL_WIFI
WiFiConnect
(
SENSOR_ID
);
...
...
@@ -147,6 +149,14 @@ void loop() {
// Short press for night mode, Long press for calibration.
checkFlashButton
();
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
();
}
if
(
sensor
::
processData
())
{
#ifdef AMPEL_CSV
csv_writer
::
logIfTimeHasCome
(
sensor
::
timestamp
,
sensor
::
co2
,
sensor
::
temperature
,
sensor
::
humidity
);
...
...
ampel-firmware/sensor_commands.cpp
0 → 100644
View file @
8dd0b6cd
#include
"sensor_commands.h"
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
)
{
}
void
(
*
function
)(
void
*
);
void
*
data
;
};
Callback
callbacks
[
3
];
// This callback expects an int.
void
print_int
(
void
*
data
)
{
int
parameter
=
*
(
int
*
)
data
;
Serial
.
println
(
parameter
);
}
// This one expects a C string.
void
print_string
(
void
*
data
)
{
char
*
parameter
=
(
char
*
)
data
;
Serial
.
println
(
parameter
);
}
void
initialize
()
{
// Register callbacks.
static
int
seventeen
=
17
;
static
int
forty_two
=
42
;
static
char
hello
[]
=
"Hello, World!"
;
callbacks
[
0
]
=
Callback
(
print_int
,
&
seventeen
);
callbacks
[
1
]
=
Callback
(
print_int
,
&
forty_two
);
callbacks
[
2
]
=
Callback
(
print_string
,
hello
);
}
void
run
()
{
// Test all the callbacks.
for
(
size_t
i
=
0
;
i
<
3
;
i
++
)
{
callbacks
[
i
].
function
(
callbacks
[
i
].
data
);
}
}
}
ampel-firmware/sensor_commands.h
0 → 100644
View file @
8dd0b6cd
#include
<Arduino.h>
namespace
sensor_commands
{
void
initialize
();
void
run
();
}
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