util.h 1.04 KB
Newer Older
1
2
3
#ifndef AMPEL_UTIL_H_INCLUDED
#define AMPEL_UTIL_H_INCLUDED

Eric Duminil's avatar
Eric Duminil committed
4
5
#include <stdint.h> // For uint32_t

6
#if defined(ESP8266)
Eric Duminil's avatar
Eric Duminil committed
7
8
#  define esp_get_max_free_block_size() ESP.getMaxFreeBlockSize()
#  define esp_get_heap_fragmentation() ESP.getHeapFragmentation()
9
#elif defined(ESP32)
Eric Duminil's avatar
Eric Duminil committed
10
11
#  define esp_get_max_free_block_size() ESP.getMaxAllocHeap() //largest block of heap that can be allocated.
#  define esp_get_heap_fragmentation() "?" // apparently not available for ESP32
12
13
#endif

14
15
16
17
18
19
20
21
22
23
24
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;
  }
}
25
class Ampel {
Eric Duminil's avatar
Eric Duminil committed
26
27
private:
  static void showFreeSpace();
28
public:
Eric Duminil's avatar
Eric Duminil committed
29
  const char *version = "v0.2.3-DEV"; // Update manually after significant changes.
Eric Duminil's avatar
Eric Duminil committed
30
  const char *board;
Eric Duminil's avatar
Eric Duminil committed
31
  const char *sensorId;
32
  const char *macAddress;
Eric Duminil's avatar
Eric Duminil committed
33
  uint32_t max_loop_duration;
34
35
  Ampel();
};
36

Eric Duminil's avatar
Eric Duminil committed
37
38
extern Ampel ampel;

39
#endif