Skip to content
Snippets Groups Projects
Commit 79a10055 authored by fxk8y's avatar fxk8y :spider:
Browse files

Begin implementing 'birth'-time metric

parent 0ec527f7
No related branches found
No related tags found
No related merge requests found
idf_component_register( idf_component_register(
SRC_DIRS SRC_DIRS
"." "SiliconTorch" "." "SiliconTorch" "SpiderLib"
INCLUDE_DIRS INCLUDE_DIRS
"." "."
......
#include "SNTP.hpp"
// ESP32 specific
#include "esp_log.h"
#include "esp_sntp.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
// #include "driver/ledc.h"
// C++ system level
#include <ctime>
#include <functional>
#include <cinttypes>
// project specific
// #include "Metrics.hpp"
/*extern "C" {
void setenv(char* env, char* value, int overwrite);
void tzset();
}*/
static const char* TAG = "SNTP";
static void ntpTask(void* evHdl) {
std::function<void()>* syncEventHandler = (std::function<void()>*) evHdl;
time_t now = 0;
struct tm timeinfo = { 0 };
do {
vTaskDelay(100 / portTICK_PERIOD_MS);
time(&now);
localtime_r(&now, &timeinfo);
} while (timeinfo.tm_year < 2000);
(*syncEventHandler)();
ESP_LOGI(TAG, "Time sync complete: ");
vTaskDelete(NULL);
}
namespace SpiderLib {
SNTP::SNTP() {
sntp_setoperatingmode(SNTP_OPMODE_POLL);
sntp_setservername(0, "pool.ntp.org"); // TODO: make configurable!
sntp_init();
setenv("TZ", "CET-1CEST,M3.5.0,M10.5.0/3", 1);
tzset();
xTaskCreate(ntpTask, TAG, 8192, (void*)&syncEventHandler, 0, NULL);
}
void SNTP::registerTimeSyncHandler(std::function<void()> f) {
if (inSync()) {
f();
} else {
std::function<void()> _f = syncEventHandler;
syncEventHandler = [=]() {
_f();
f();
};
}
}
bool SNTP::inSync() {
return false;
}
}
#pragma once
// ESP32 specific
// #include "driver/ledc.h"
// C++ system level
// #include <cinttypes>
#include <functional>
// project specific
// #include "Metrics.hpp"
namespace SpiderLib {
class SNTP {
public:
SNTP(SNTP const&) = delete;
void operator=(SNTP const&) = delete;
static SNTP& instance() {
static SNTP sntp;
return sntp;
}
bool inSync();
void registerTimeSyncHandler(std::function<void()> f);
private:
SNTP();
std::function<void()> syncEventHandler = [](){};
};
}
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
// ### LIBS FOR TESTING ### // ### LIBS FOR TESTING ###
#include <cstdlib> #include <cstdlib>
#include "SpiderLib/SNTP.hpp"
#include "SiliconTorch/CyanBusCRC.hpp" #include "SiliconTorch/CyanBusCRC.hpp"
#include "SiliconTorch/CyanBusTOUT.hpp" #include "SiliconTorch/CyanBusTOUT.hpp"
// ### END LIBS ### // ### END LIBS ###
...@@ -24,6 +25,16 @@ CyanLight::CyanLightControl* ctrl; ...@@ -24,6 +25,16 @@ CyanLight::CyanLightControl* ctrl;
void device_main() { void device_main() {
//SpiderLib::SNTP& ntp = SpiderLib::SNTP::instance();
// ntp.registerTimeSyncHandler([](){
// ESP_LOGE("EVENT…", "…HANDLER()!");
// });
cfg.apply();
return;
// Needed for packet parsing, animation rendering and stuff // Needed for packet parsing, animation rendering and stuff
qthing::power_managment_max_power(); qthing::power_managment_max_power();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment