-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
117 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#include "status_page_item.h" | ||
|
||
namespace sensesp { | ||
|
||
std::map<String, StatusPageItemBase*> StatusPageItemBase::status_page_items_; | ||
|
||
} // namespace sensesp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#ifndef SENSESP_UI_UI_OUTPUT_H | ||
#define SENSESP_UI_UI_OUTPUT_H | ||
|
||
#include <ArduinoJson.h> | ||
#include <functional> | ||
#include <map> | ||
|
||
#include "Arduino.h" | ||
#include "sensesp/system/observablevalue.h" | ||
#include "sensesp/system/valueconsumer.h" | ||
#include "sensesp/system/valueproducer.h" | ||
|
||
namespace sensesp { | ||
|
||
constexpr char kUIOutputDefaultGroup[] = "Default"; | ||
constexpr int kUIOutputDefaultOrder = 1000; | ||
|
||
class StatusPageItemBase { | ||
public: | ||
StatusPageItemBase(String name, String group, int order) | ||
: name_(name), group_(group), order_(order) {} | ||
|
||
String& get_name() { return name_; } | ||
|
||
virtual JsonDocument as_json() = 0; | ||
|
||
static const std::map<String, StatusPageItemBase*>* get_status_page_items() { | ||
return &status_page_items_; | ||
} | ||
|
||
protected: | ||
String name_; | ||
String group_ = kUIOutputDefaultGroup; | ||
int order_ = kUIOutputDefaultOrder; | ||
static std::map<String, StatusPageItemBase*> status_page_items_; | ||
}; | ||
|
||
template <typename T> | ||
class StatusPageItem : public StatusPageItemBase, public ObservableValue<T> { | ||
public: | ||
StatusPageItem(String name, T& value, String group, int order) | ||
: StatusPageItemBase(name, group, order), ObservableValue<T>(value) { | ||
ui_outputs_[name] = this; | ||
} | ||
|
||
protected: | ||
virtual JsonDocument as_json() override{ | ||
JsonDocument obj; | ||
obj["name"] = name_; | ||
obj["value"] = get(); | ||
obj["group"] = group_; | ||
obj["order"] = order_; | ||
return obj; | ||
} | ||
}; | ||
|
||
} // namespace sensesp | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters