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
240a18d9
Commit
240a18d9
authored
Apr 19, 2021
by
Eric Duminil
Browse files
Commands to set time & show free heap space
parent
402023d9
Pipeline
#2861
passed with stage
in 1 minute and 47 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
240a18d9
...
...
@@ -80,6 +80,7 @@ void setup() {
led_effects
::
setupRing
();
util
::
initialize
();
sensor
::
initialize
();
Serial
.
print
(
F
(
"Sensor ID: "
));
...
...
ampel-firmware/co2_sensor.cpp
View file @
240a18d9
...
...
@@ -78,8 +78,6 @@ namespace sensor {
" 600 (Starts calibration process, to given ppm)"
);
sensor_console
::
defineIntCommand
(
"calibrate!"
,
calibrateSensorRightNow
,
" 600 (Calibrates right now, to given ppm)"
);
sensor_console
::
defineIntCommand
(
"calibrate!"
,
calibrateSensorRightNow
,
" 600 (Calibrates right now, to given ppm)"
);
sensor_console
::
defineIntCommand
(
"auto_calibrate"
,
setAutoCalibration
,
" 0/1 (Disables/enables autocalibration)"
);
sensor_console
::
defineCommand
(
"reset"
,
[]()
{
...
...
ampel-firmware/sensor_console.cpp
View file @
240a18d9
...
...
@@ -19,6 +19,7 @@ namespace sensor_console {
Command
commands
[
MAX_COMMANDS
];
//NOTE: Probably possible to DRY (with templates?)
//TODO: Allow F-Strings
void
defineCommand
(
const
char
*
name
,
void
(
*
function
)(
void
),
const
char
*
doc
)
{
if
(
commands_count
<
MAX_COMMANDS
)
{
commands
[
commands_count
].
name
=
name
;
...
...
ampel-firmware/util.cpp
View file @
240a18d9
...
...
@@ -36,6 +36,32 @@ namespace ntp {
void
getLocalTime
(
char
*
timestamp
)
{
timeClient
.
getFormattedDate
(
timestamp
);
}
void
setLocalTime
(
int32_t
unix_seconds
)
{
char
time
[
23
];
timeClient
.
getFormattedDate
(
time
);
Serial
.
print
(
"Current time : "
);
Serial
.
println
(
time
);
Serial
.
print
(
"Setting UNIX time to : "
);
Serial
.
println
(
unix_seconds
);
timeClient
.
setEpochTime
(
unix_seconds
-
seconds
());
timeClient
.
getFormattedDate
(
time
);
Serial
.
print
(
"Current time : "
);
Serial
.
println
(
time
);
}
}
namespace
util
{
void
initialize
()
{
// Define SENSOR ID
// Add callbacks
sensor_console
::
defineIntCommand
(
"set_time"
,
ntp
::
setLocalTime
,
" 1618829570 (Sets time to the given UNIX time)"
);
sensor_console
::
defineCommand
(
"free"
,
[]()
{
Serial
.
print
(
F
(
"Free heap space : "
));
Serial
.
print
(
get_free_heap_size
());
Serial
.
println
(
F
(
" bytes."
));
},
" (Displays available heap space)"
);
}
}
uint32_t
max_loop_duration
=
0
;
...
...
ampel-firmware/util.h
View file @
240a18d9
...
...
@@ -2,6 +2,7 @@
#define AMPEL_UTIL_H_INCLUDED
#include
<Arduino.h>
#include
"config.h"
#include
"sensor_console.h"
#include
<WiFiUdp.h>
// required for NTP
#include
"src/lib/NTPClient-master/NTPClient.h"
// NTP
...
...
@@ -21,10 +22,12 @@
namespace
ntp
{
void
initialize
();
void
update
();
void
getLocalTime
(
char
*
timestamp
);
void
getLocalTime
(
char
*
timestamp
);
}
namespace
util
{
void
initialize
();
template
<
typename
Tpa
,
typename
Tpb
>
inline
auto
min
(
const
Tpa
&
a
,
const
Tpb
&
b
)
->
decltype
(
a
<
b
?
a
:
b
)
{
return
b
<
a
?
b
:
a
;
...
...
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