diff --git a/examples/bme280_example.cpp b/examples/bme280_example.cpp index 65caedd0f..d57b1a830 100644 --- a/examples/bme280_example.cpp +++ b/examples/bme280_example.cpp @@ -21,10 +21,9 @@ ReactESP app([] () { Debug.setSerialEnabled(true); #endif - // true will disable systemHz, freemem, uptime, and ipaddress "sensors" - bool disableStandardSensors = false; - - sensesp_app = new SensESPApp(disableStandardSensors); + // Create the SensESPApp with whatever "standard sensors" you want: noStdSensors, allStdSensors, or uptimeOnly. + // The default is allStdSensors. + sensesp_app = new SensESPApp(uptimeOnly); // Create a BME280, which represents the physical sensor. // 0x77 is the default address. Some chips use 0x76, which is shown here. diff --git a/examples/ina219_example.cpp b/examples/ina219_example.cpp index 175119e52..884daca76 100644 --- a/examples/ina219_example.cpp +++ b/examples/ina219_example.cpp @@ -21,10 +21,9 @@ ReactESP app([] () { Debug.setSerialEnabled(true); #endif - // true will disable systemHz, freemem, uptime, and ipaddress "sensors" - bool disableStandardSensors = true; - - sensesp_app = new SensESPApp(disableStandardSensors); + // Create the SensESPApp with whatever "standard sensors" you want: noStdSensors, allStdSensors, or uptimeOnly. + // The default is allStdSensors. + sensesp_app = new SensESPApp(allStdSensors); // Create an INA219, which represents the physical sensor. // 0x40 is the default address. Chips can be modified to use 0x41 (shown here), 0x44, or 0x45. diff --git a/examples/sht31_example.cpp b/examples/sht31_example.cpp index 6050e1af5..f93b4598f 100644 --- a/examples/sht31_example.cpp +++ b/examples/sht31_example.cpp @@ -21,10 +21,9 @@ ReactESP app([] () { Debug.setSerialEnabled(true); #endif - // true will disable systemHz, freemem, uptime, and ipaddress "sensors" - bool disableStandardSensors = false; - - sensesp_app = new SensESPApp(disableStandardSensors); + // Create the SensESPApp with whatever "standard sensors" you want: noStdSensors, allStdSensors, or uptimeOnly. + // The default is allStdSensors. + sensesp_app = new SensESPApp(noStdSensors); // Create a SHT31, which represents the physical sensor. // 0x44 is the default address. Some chips use 0x45, which is shown here. diff --git a/src/sensesp_app.cpp b/src/sensesp_app.cpp index 1886a9e9d..f78099cb8 100644 --- a/src/sensesp_app.cpp +++ b/src/sensesp_app.cpp @@ -21,7 +21,7 @@ RemoteDebug Debug; // FIXME: Setting up the system is too verbose and repetitive -SensESPApp::SensESPApp(bool disableStdSensors) : disableStdSensors{disableStdSensors} { +SensESPApp::SensESPApp(StdSensors_t stdSensors) : stdSensors{stdSensors} { // initialize filesystem if (!SPIFFS.begin()) { @@ -35,9 +35,7 @@ SensESPApp::SensESPApp(bool disableStdSensors) : disableStdSensors{disableStdSen // setup standard sensors and their transforms - if(!disableStdSensors) { - setup_standard_sensors(hostname); - } + setup_standard_sensors(hostname, stdSensors); // create the SK delta object @@ -70,41 +68,46 @@ SensESPApp::SensESPApp(bool disableStdSensors) : disableStdSensors{disableStdSen sk_delta, ws_connected_cb, ws_delta_cb); } -void SensESPApp::setup_standard_sensors(ObservableValue* hostname) { +void SensESPApp::setup_standard_sensors(ObservableValue* hostname, StdSensors_t stdSensors) { - // connect systemhz + if (stdSensors == noStdSensors) {return;}; - connect_1to1_h>( - new SystemHz(), - new SKOutput(), - hostname - ); + if (stdSensors == allStdSensors) { + // connect systemhz - String hostname_str = hostname->get(); + connect_1to1_h>( + new SystemHz(), + new SKOutput(), + hostname + ); - // connect freemem + // connect freemem - connect_1to1_h>( - new FreeMem(), - new SKOutput(), - hostname - ); + connect_1to1_h>( + new FreeMem(), + new SKOutput(), + hostname + ); - // connect uptime + // connect ip address - connect_1to1_h>( - new Uptime(), - new SKOutput(), - hostname - ); + connect_1to1_h>( + new IPAddrDev(), + new SKOutput(), + hostname + ); + } - // connect ip address + if (stdSensors == allStdSensors || stdSensors == uptimeOnly) { + // connect uptime - connect_1to1_h>( - new IPAddrDev(), - new SKOutput(), - hostname - ); + connect_1to1_h>( + new Uptime(), + new SKOutput(), + hostname + ); + } + } void SensESPApp::enable() { diff --git a/src/sensesp_app.h b/src/sensesp_app.h index cdaf2401f..f6ef88396 100644 --- a/src/sensesp_app.h +++ b/src/sensesp_app.h @@ -15,9 +15,11 @@ #include "system/valueconsumer.h" #include "system/observablevalue.h" +enum StdSensors_t { allStdSensors, noStdSensors, uptimeOnly }; + class SensESPApp { public: - SensESPApp(bool disableStdSensors = false); + SensESPApp(StdSensors_t stdSensors = allStdSensors); void enable(); void reset(); String get_hostname(); @@ -62,8 +64,8 @@ class SensESPApp { private: - bool disableStdSensors; - void setup_standard_sensors(ObservableValue* hostname); + StdSensors_t stdSensors; + void setup_standard_sensors(ObservableValue* hostname, StdSensors_t stdSensors = allStdSensors); HTTPServer* http_server; LedBlinker led_blinker;