1#ifndef SENSESP_BASE_APP_H_
2#define SENSESP_BASE_APP_H_
4#ifndef SENSESP_BUTTON_PIN
6#define SENSESP_BUTTON_PIN 0
21inline void SetupLogging(esp_log_level_t default_level = ESP_LOG_VERBOSE) {
22 esp_log_level_set(
"*", default_level);
28 if (baudrate != 115200) {
29 ESP_LOGW(__FILENAME__,
"SetupSerialDebug baudrate parameter is ignored.");
50 static const std::shared_ptr<SensESPBaseApp>&
get() {
return instance_; }
56 bool outside_users =
instance_.use_count() > 1;
59 ESP_LOGW(__FILENAME__,
60 "SensESPBaseApp instance has active references and won't be "
61 "properly destroyed.");
64 return !outside_users;
72 ESP_LOGW(__FILENAME__,
"start() call is deprecated and can be removed.");
80 ESP_LOGW(__FILENAME__,
81 "Resetting the device configuration to system defaults.");
84 this->event_loop_->onDelay(1000, []() {
96 return std::static_pointer_cast<ObservableValue<String>>(
hostname_);
127 event_loop_{std::make_shared<reactesp::EventLoop>()} {
134 hostname_ = std::make_shared<PersistingObservableValue<String>>(
158 std::shared_ptr<PersistingObservableValue<String>>
hostname_;
The base class for SensESP applications.
static String get_hostname()
Get the current hostname.
static std::shared_ptr< reactesp::EventLoop > get_event_loop()
Get the event loop object from the singleton SensESPBaseApp instance.
static std::shared_ptr< SensESPBaseApp > instance_
std::shared_ptr< reactesp::EventLoop > event_loop_
void set_instance(const std::shared_ptr< SensESPBaseApp > &instance)
const SensESPBaseApp * set_hostname(String hostname)
std::shared_ptr< PersistingObservableValue< String > > hostname_
virtual void start()
Start the app (activate all the subcomponents)
std::shared_ptr< ObservableValue< String > > get_hostname_observable()
Get the hostname observable object.
virtual void setup()
Perform initialization of SensESPBaseApp once builder configuration is done.
SensESPBaseApp()
Construct a new SensESP Base App object.
virtual void reset()
Reset the device to factory defaults.
virtual bool destroy()
Destroy the SensESPBaseApp instance.
std::shared_ptr< Filesystem > filesystem_
static const std::shared_ptr< SensESPBaseApp > & get()
Get the singleton instance of the SensESPBaseApp.
constexpr auto kDefaultHostname
void SetupSerialDebug(uint32_t baudrate)
std::shared_ptr< ConfigItemT< T > > ConfigItem(std::shared_ptr< T >)
Register a ConfigItemT with the ConfigItemBase.
void SetupLogging(esp_log_level_t default_level=ESP_LOG_VERBOSE)