Commit 240a18d9 authored by Eric Duminil's avatar 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
......@@ -80,6 +80,7 @@ void setup() {
led_effects::setupRing();
util::initialize();
sensor::initialize();
Serial.print(F("Sensor ID: "));
......
......@@ -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", []() {
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment