45 lines
1.2 KiB
C++
45 lines
1.2 KiB
C++
#ifndef AMPEL_UTIL_H_INCLUDED
|
|
#define AMPEL_UTIL_H_INCLUDED
|
|
#include <Arduino.h>
|
|
#include "config.h"
|
|
|
|
#include <WiFiUdp.h> // required for NTP
|
|
#include "src/lib/NTPClient-master/NTPClient.h" // NTP
|
|
|
|
#if defined(ESP8266)
|
|
# define BOARD "ESP8266"
|
|
# include <ESP8266WiFi.h> // required to get MAC address
|
|
# define get_free_heap_size() system_get_free_heap_size()
|
|
#elif defined(ESP32)
|
|
# define BOARD "ESP32"
|
|
# include <WiFi.h> // required to get MAC address
|
|
# define get_free_heap_size() esp_get_free_heap_size()
|
|
#else
|
|
# define BOARD "Unknown"
|
|
#endif
|
|
|
|
namespace ntp {
|
|
void initialize();
|
|
void update();
|
|
String getLocalTime();
|
|
}
|
|
|
|
namespace util {
|
|
template<typename Tpa, typename Tpb>
|
|
inline auto min(const Tpa &a, const Tpb &b) -> decltype(a < b ? a : b) {
|
|
return b < a ? b : a;
|
|
}
|
|
|
|
template<typename Tpa, typename Tpb>
|
|
inline auto max(const Tpa &a, const Tpb &b) -> decltype(b > a ? b : a) {
|
|
return b > a ? b : a;
|
|
}
|
|
}
|
|
|
|
//NOTE: Only use seconds() for duration comparison, not timestamps comparison. Otherwise, problems happen when millis roll over.
|
|
#define seconds() (millis() / 1000UL)
|
|
extern uint32_t max_loop_duration;
|
|
const extern String SENSOR_ID;
|
|
|
|
#endif
|