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
32f8968b
Commit
32f8968b
authored
Apr 16, 2021
by
Eric Duminil
Browse files
Set CO2 for debugging
parent
755f8578
Changes
4
Show whitespace changes
Inline
Side-by-side
ampel-firmware/co2_sensor.cpp
View file @
32f8968b
...
...
@@ -25,11 +25,10 @@ namespace sensor {
uint32_t
waiting_color
=
color
::
blue
;
bool
should_calibrate
=
false
;
void
printCO2
(
void
*
data
)
{
int
parameter
=
*
(
uint16_t
*
)
data
;
Serial
.
print
(
"NICE! HELLO FROM SENSOR."
);
Serial
.
print
(
"CO2 : "
);
Serial
.
println
(
parameter
);
void
setCO2forDebugging
(
int32_t
fakeCo2
)
{
Serial
.
print
(
F
(
"DEBUG. Setting CO2 to "
));
co2
=
fakeCo2
;
Serial
.
println
(
co2
);
}
void
initialize
()
{
...
...
@@ -76,7 +75,7 @@ namespace sensor {
Serial
.
print
(
F
(
"Auto-calibration is "
));
Serial
.
println
(
config
::
auto_calibrate_sensor
?
"ON."
:
"OFF."
);
sensor_commands
::
defineCallback
(
"co2"
,
printCO2
,
&
co2
);
sensor_commands
::
defineCallback
(
"co2"
,
setCO2forDebugging
);
}
//NOTE: should timer deviation be used to adjust measurement_timestep?
...
...
ampel-firmware/led_effects.cpp
View file @
32f8968b
...
...
@@ -70,7 +70,7 @@ namespace led_effects {
onBoardLEDOff
();
}
void
helloRing
(
void
*
c
)
{
void
helloRing
(
int32_t
x
)
{
Serial
.
print
(
"HELLO FROM LED RINGS!"
);
Serial
.
print
(
"I have "
);
Serial
.
print
(
NUMPIXELS
);
...
...
@@ -83,7 +83,7 @@ namespace led_effects {
pixels
.
setBrightness
(
config
::
max_brightness
);
LEDsOff
();
sensor_commands
::
defineCallback
(
"led"
,
helloRing
,
0
);
sensor_commands
::
defineCallback
(
"led"
,
helloRing
);
}
void
toggleNightMode
()
{
...
...
ampel-firmware/sensor_commands.cpp
View file @
32f8968b
...
...
@@ -8,19 +8,18 @@ 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
(
const
char
*
s
=
0
,
void
(
*
f
)(
void
*
)
=
0
,
void
*
d
=
0
)
:
name
(
s
),
function
(
f
)
,
data
(
d
)
{
Callback
(
const
char
*
s
=
0
,
void
(
*
f
)(
int32_t
)
=
0
)
:
name
(
s
),
function
(
f
)
{
}
const
char
*
name
;
void
(
*
function
)(
void
*
);
void
*
data
;
void
(
*
function
)(
int32_t
);
};
Callback
callbacks
[
MAX_CALLBACKS
];
void
defineCallback
(
const
char
*
n
,
void
(
*
f
)(
void
*
),
void
*
d
)
{
void
defineCallback
(
const
char
*
n
,
void
(
*
f
)(
int32_t
)
)
{
if
(
callbacks_count
<
MAX_CALLBACKS
)
{
callbacks
[
callbacks_count
]
=
Callback
(
n
,
f
,
d
);
callbacks
[
callbacks_count
]
=
Callback
(
n
,
f
);
callbacks_count
++
;
}
else
{
Serial
.
println
(
F
(
"Too many callbacks have been defined."
));
...
...
@@ -31,7 +30,7 @@ namespace sensor_commands {
return
!
strncmp
(
a
,
b
,
strlen
(
b
));
}
bool
parseCommand
(
const
char
*
command
,
char
*
function_name
,
long
&
parameter
)
{
bool
parseCommand
(
const
char
*
command
,
char
*
function_name
,
int32_t
&
parameter
)
{
char
split_command
[
MAX_COMMAND_SIZE
];
strlcpy
(
split_command
,
command
,
MAX_COMMAND_SIZE
);
Serial
.
print
(
F
(
"Received : '"
));
...
...
@@ -69,7 +68,7 @@ namespace sensor_commands {
void
run
(
const
char
*
command
)
{
char
function_name
[
MAX_COMMAND_SIZE
];
long
parameter
;
int32_t
parameter
;
if
(
parseCommand
(
command
,
function_name
,
parameter
))
{
listAvailableCallbacks
();
return
;
...
...
@@ -79,14 +78,13 @@ namespace sensor_commands {
Serial
.
print
(
"'. Parameter : "
);
Serial
.
println
(
parameter
);
// Test all the callbacks.
for
(
uint8_t
i
=
0
;
i
<
callbacks_count
;
i
++
)
{
if
(
!
strcmp
(
function_name
,
callbacks
[
i
].
name
))
{
Serial
.
print
(
"Function found!!!"
);
Serial
.
print
(
"Trying '"
);
Serial
.
print
(
callbacks
[
i
].
name
);
Serial
.
println
(
"'"
);
callbacks
[
i
].
function
(
callbacks
[
i
].
data
);
callbacks
[
i
].
function
(
parameter
);
return
;
}
}
...
...
ampel-firmware/sensor_commands.h
View file @
32f8968b
...
...
@@ -7,5 +7,5 @@
namespace
sensor_commands
{
void
run
(
const
char
*
command
);
void
defineCallback
(
const
char
*
command
,
void
(
*
f
)(
void
*
),
void
*
d
);
void
defineCallback
(
const
char
*
command
,
void
(
*
f
)(
int32_t
)
);
}
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