SensESP 3.0.1
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 <functional>
6#include <map>
7
8#include "Arduino.h"
12
13namespace sensesp {
14
15constexpr char kUIOutputDefaultGroup[] = "Default";
16constexpr int kUIOutputDefaultOrder = 1000;
17
19 public:
20 StatusPageItemBase(String name, String group, int order)
21 : name_(name), group_(group), order_(order) {}
22
23 String& get_name() { return name_; }
24
25 virtual JsonDocument as_json() = 0;
26
27 static const std::map<String, StatusPageItemBase*>* get_status_page_items() {
28 return &status_page_items_;
29 }
30
31 protected:
32 String name_;
35 static std::map<String, StatusPageItemBase*> status_page_items_;
36};
37
47template <typename T>
49 public:
50 StatusPageItem(String name, const T& value, String group, int order)
51 : StatusPageItemBase(name, group, order), ObservableValue<T>(value) {
52 status_page_items_[name] = this;
53 }
54
55 protected:
56 virtual JsonDocument as_json() override{
57 JsonDocument obj;
58 obj["name"] = name_;
59 obj["value"] = this->get();
60 obj["group"] = group_;
61 obj["order"] = order_;
62 return obj;
63 }
64};
65
66} // namespace sensesp
67
68#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[]