SensESP 3.4.1-alpha
Universal Signal K sensor toolkit ESP32
Loading...
Searching...
No Matches
status_page_item.h
Go to the documentation of this file.
1#ifndef SENSESP_UI_UI_OUTPUT_H
2#define SENSESP_UI_UI_OUTPUT_H
3
4#include <ArduinoJson.h>
5#include <esp_log.h>
6#include <functional>
7#include <map>
8
9#include "Arduino.h"
13
14namespace sensesp {
15
16constexpr char kUIOutputDefaultGroup[] = "Default";
17constexpr int kUIOutputDefaultOrder = 1000;
18
20 public:
21 StatusPageItemBase(String name, String group, int order)
22 : name_(name), group_(group), order_(order) {}
23
28 virtual ~StatusPageItemBase();
29
30 String& get_name() { return name_; }
31
32 virtual JsonDocument as_json() = 0;
33
34 static const std::map<String, StatusPageItemBase*>* get_status_page_items() {
35 return &status_page_items_;
36 }
37
42 static void clear_registry();
43
44 protected:
45 String name_;
48 static std::map<String, StatusPageItemBase*> status_page_items_;
49};
50
60template <typename T>
62 public:
63 StatusPageItem(String name, const T& value, String group, int order)
64 : StatusPageItemBase(name, group, order), ObservableValue<T>(value) {
65 if (status_page_items_.count(name) > 0) {
66 ESP_LOGW("StatusPageItem",
67 "Duplicate status page item name: %s; keeping the first "
68 "registration and ignoring this one",
69 name.c_str());
70 } else {
71 status_page_items_[name] = this;
72 }
73 }
74
75 protected:
76 virtual JsonDocument as_json() override{
77 JsonDocument obj;
78 obj["name"] = name_;
79 obj["value"] = this->get();
80 obj["group"] = group_;
81 obj["order"] = order_;
82 return obj;
83 }
84};
85
86} // namespace sensesp
87
88#endif
A value container that notifies its observers if it gets changed.
StatusPageItemBase(String name, String group, int order)
static std::map< String, StatusPageItemBase * > status_page_items_
static const std::map< String, StatusPageItemBase * > * get_status_page_items()
virtual JsonDocument as_json()=0
Item that renders its own value on the web UI status page.
virtual JsonDocument as_json() override
StatusPageItem(String name, const T &value, String group, int order)
virtual const T & get() const
constexpr int kUIOutputDefaultOrder
constexpr char kUIOutputDefaultGroup[]