From 09f53f69fef51726615cabd7ffa238b03dc5e4b1 Mon Sep 17 00:00:00 2001 From: Wolfgang Gaar <nohum@users.noreply.github.com> Date: Sun, 6 Aug 2017 10:12:04 +0200 Subject: [PATCH] Allow to set power savings mode of BH1750 light level sensor (#197) --- NodeManager.cpp | 10 ++++++++++ NodeManager.h | 2 ++ README.md | 8 +++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/NodeManager.cpp b/NodeManager.cpp index 54e451f..9f86a13 100755 --- a/NodeManager.cpp +++ b/NodeManager.cpp @@ -1568,6 +1568,10 @@ SensorBH1750::SensorBH1750(NodeManager* node_manager, int child_id): Sensor(node _lightSensor = new BH1750(); } +void SensorBH1750::setMode(uint8_t mode) { + _lightSensor->configure(mode); +} + // what to do during before void SensorBH1750::onBefore() { _lightSensor->begin(); @@ -1596,6 +1600,12 @@ void SensorBH1750::onReceive(const MyMessage & message) { // what to do when receiving a remote message void SensorBH1750::onProcess(Request & request) { + int function = request.getFunction(); + switch(function) { + case 101: setMode(request.getValueInt()); break; + default: return; + } + _send(_msg_service.set(function)); } diff --git a/NodeManager.h b/NodeManager.h index ac40f34..4ed5a24 100755 --- a/NodeManager.h +++ b/NodeManager.h @@ -972,6 +972,8 @@ class SensorDs18b20: public Sensor { class SensorBH1750: public Sensor { public: SensorBH1750(NodeManager* node_manager, int child_id); + // [101] set sensor reading mode, e.g. BH1750_ONE_TIME_HIGH_RES_MODE + void setMode(uint8_t mode); // define what to do at each stage of the sketch void onBefore(); void onSetup(); diff --git a/README.md b/README.md index 9bc784f..094fe2d 100755 --- a/README.md +++ b/README.md @@ -685,6 +685,12 @@ Each sensor class can expose additional methods. DeviceAddress* getDeviceAddress(); ~~~ +* SensorBH1750 +~~~c + // [101] set sensor reading mode, e.g. BH1750_ONE_TIME_HIGH_RES_MODE + void setMode(uint8_t mode); +~~~ + * SensorBME280 / SensorBMP085 / SensorBMP280 ~~~c // [101] define how many pressure samples to keep track of for calculating the forecast (default: 5) @@ -1412,4 +1418,4 @@ v1.6: * SensorMQ now depends on its own module * Added automatic off capability (safeguard) to SensorDigitalOutput * Any sensor can now access all NodeManager's functions -* DHT sensor now using MySensors' DHT library \ No newline at end of file +* DHT sensor now using MySensors' DHT library -- GitLab