Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve method for disabling std sensors, incl in examples #107

Merged
merged 2 commits into from
Apr 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions examples/bme280_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions examples/ina219_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 3 additions & 4 deletions examples/sht31_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
63 changes: 33 additions & 30 deletions src/sensesp_app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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

Expand Down Expand Up @@ -70,41 +68,46 @@ SensESPApp::SensESPApp(bool disableStdSensors) : disableStdSensors{disableStdSen
sk_delta, ws_connected_cb, ws_delta_cb);
}

void SensESPApp::setup_standard_sensors(ObservableValue<String>* hostname) {
void SensESPApp::setup_standard_sensors(ObservableValue<String>* hostname, StdSensors_t stdSensors) {

// connect systemhz
if (stdSensors == noStdSensors) {return;};

connect_1to1_h<SystemHz, SKOutput<float>>(
new SystemHz(),
new SKOutput<float>(),
hostname
);
if (stdSensors == allStdSensors) {
// connect systemhz

String hostname_str = hostname->get();
connect_1to1_h<SystemHz, SKOutput<float>>(
new SystemHz(),
new SKOutput<float>(),
hostname
);

// connect freemem
// connect freemem

connect_1to1_h<FreeMem, SKOutput<float>>(
new FreeMem(),
new SKOutput<float>(),
hostname
);
connect_1to1_h<FreeMem, SKOutput<float>>(
new FreeMem(),
new SKOutput<float>(),
hostname
);

// connect uptime
// connect ip address

connect_1to1_h<Uptime, SKOutput<float>>(
new Uptime(),
new SKOutput<float>(),
hostname
);
connect_1to1_h<IPAddrDev, SKOutput<String>>(
new IPAddrDev(),
new SKOutput<String>(),
hostname
);
}

// connect ip address
if (stdSensors == allStdSensors || stdSensors == uptimeOnly) {
// connect uptime

connect_1to1_h<IPAddrDev, SKOutput<String>>(
new IPAddrDev(),
new SKOutput<String>(),
hostname
);
connect_1to1_h<Uptime, SKOutput<float>>(
new Uptime(),
new SKOutput<float>(),
hostname
);
}

}

void SensESPApp::enable() {
Expand Down
8 changes: 5 additions & 3 deletions src/sensesp_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -62,8 +64,8 @@ class SensESPApp {


private:
bool disableStdSensors;
void setup_standard_sensors(ObservableValue<String>* hostname);
StdSensors_t stdSensors;
void setup_standard_sensors(ObservableValue<String>* hostname, StdSensors_t stdSensors = allStdSensors);

HTTPServer* http_server;
LedBlinker led_blinker;
Expand Down