@@ -21,10 +21,10 @@ const char* WAKEUP = "WAKEUP";
2121// set the vcc and ground pin the sensor is connected to
2222void PowerManager::setPowerPins (int ground_pin, int vcc_pin, long wait = 10 ) {
2323 #if DEBUG == 1
24- Serial.print (" POWER V =" );
25- Serial.print (vcc_pin );
26- Serial.print (" G =" );
27- Serial.println (ground_pin );
24+ Serial.print (" POWER G =" );
25+ Serial.print (ground_pin );
26+ Serial.print (" V =" );
27+ Serial.println (vcc_pin );
2828 #endif
2929 // configure the vcc pin as output and initialize to low (power off)
3030 _vcc_pin = vcc_pin;
@@ -619,7 +619,7 @@ void SensorDHT::onReceive(const MyMessage & message) {
619619*/
620620#if MODULE_SHT21 == 1
621621// contructor
622- SensorSHT21::SensorSHT21 (int child_id, int sensor_type): Sensor(child_id, - 1 ) {
622+ SensorSHT21::SensorSHT21 (int child_id, int sensor_type): Sensor(child_id,A2 ) {
623623 // store the sensor type (0: temperature, 1: humidity)
624624 _sensor_type = sensor_type;
625625 if (_sensor_type == 0 ) {
@@ -681,6 +681,15 @@ void SensorSHT21::onReceive(const MyMessage & message) {
681681}
682682#endif
683683
684+ /*
685+ * SensorHTU21D
686+ */
687+ #if MODULE_SHT21 == 1
688+ // constructor
689+ SensorHTU21D::SensorHTU21D (int child_id, int pin): SensorSHT21(child_id, pin) {
690+ }
691+ #endif
692+
684693/*
685694 * SensorSwitch
686695 */
@@ -795,8 +804,81 @@ void SensorDs18b20::onLoop() {
795804void SensorDs18b20::onReceive (const MyMessage & message) {
796805 onLoop ();
797806}
807+ #endif
808+
809+ /*
810+ SensorBH1750
811+ */
812+ #if MODULE_BH1750 == 1
813+ // contructor
814+ SensorBH1750::SensorBH1750 (int child_id): Sensor(child_id,A4) {
815+ setPresentation (S_LIGHT_LEVEL);
816+ setType (V_LEVEL);
817+ _lightSensor = new BH1750 ();
818+ }
819+
820+ // what do to during setup
821+ void SensorBH1750::onBefore () {
822+ _lightSensor->begin ();
823+ }
824+
825+ // what do to during loop
826+ void SensorBH1750::onLoop () {
827+ // request the light level
828+ _value_int = _lightSensor->readLightLevel ();
829+ #if DEBUG == 1
830+ Serial.print (" BH1 I=" );
831+ Serial.print (_child_id);
832+ Serial.print (" L=" );
833+ Serial.println (_value_int);
834+ #endif
835+ }
836+
837+ // what do to as the main task when receiving a message
838+ void SensorBH1750::onReceive (const MyMessage & message) {
839+ onLoop ();
840+ }
841+ #endif
842+
843+ /*
844+ SensorMLX90614
845+ */
846+ #if MODULE_MLX90614 == 1
847+ // contructor
848+ SensorMLX90614::SensorMLX90614 (int child_id, Adafruit_MLX90614* mlx, int sensor_type): Sensor(child_id,A4) {
849+ // store the sensor type (0: ambient, 1: object)
850+ _sensor_type = sensor_type;
851+ _mlx = mlx;
852+ // set presentation and type
853+ setPresentation (S_TEMP);
854+ setType (V_TEMP);
855+ setValueType (TYPE_FLOAT);
856+ }
798857
858+ // what do to during setup
859+ void SensorMLX90614::onBefore () {
860+ // initialize the library
861+ _mlx->begin ();
862+ }
863+
864+ // what do to during loop
865+ void SensorMLX90614::onLoop () {
866+ float temperature = _sensor_type == 0 ? _mlx->readAmbientTempC () : _mlx->readObjectTempC ();
867+ // convert it
868+ if (! getControllerConfig ().isMetric ) temperature = temperature * 1.8 + 32 ;
869+ #if DEBUG == 1
870+ Serial.print (" MLX I=" );
871+ Serial.print (_child_id);
872+ Serial.print (" T=" );
873+ Serial.println (temperature);
874+ #endif
875+ if (! isnan (temperature)) _value_float = temperature;
876+ }
799877
878+ // what do to as the main task when receiving a message
879+ void SensorMLX90614::onReceive (const MyMessage & message) {
880+ onLoop ();
881+ }
800882#endif
801883
802884/* ******************************************
@@ -915,6 +997,11 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
915997 child_id = _getAvailableChildId ();
916998 registerSensor (new SensorSHT21 (child_id,1 ));
917999 }
1000+ else if (sensor_type == SENSOR_HTU21D) {
1001+ registerSensor (new SensorHTU21D (child_id,0 ));
1002+ child_id = _getAvailableChildId ();
1003+ registerSensor (new SensorHTU21D (child_id,1 ));
1004+ }
9181005 #endif
9191006 #if MODULE_SWITCH == 1
9201007 else if (sensor_type == SENSOR_SWITCH || sensor_type == SENSOR_DOOR || sensor_type == SENSOR_MOTION) {
@@ -944,6 +1031,22 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
9441031 }
9451032 }
9461033 #endif
1034+ #if MODULE_BH1750 == 1
1035+ else if (sensor_type == SENSOR_BH1750) {
1036+ return registerSensor (new SensorBH1750 (child_id));
1037+ }
1038+ #endif
1039+ #if MODULE_MLX90614 == 1
1040+ else if (sensor_type == SENSOR_MLX90614) {
1041+ Serial.println (" 1" );
1042+ Adafruit_MLX90614* mlx = new Adafruit_MLX90614 ();
1043+ Serial.println (" 2" );
1044+ registerSensor (new SensorMLX90614 (child_id,mlx,0 ));
1045+ Serial.println (" 3" );
1046+ child_id = _getAvailableChildId ();
1047+ registerSensor (new SensorMLX90614 (child_id,mlx,1 ));
1048+ }
1049+ #endif
9471050 else {
9481051 #if DEBUG == 1
9491052 Serial.print (" INVALID " );
@@ -965,6 +1068,8 @@ int NodeManager::registerSensor(Sensor* sensor) {
9651068 Serial.print (" T=" );
9661069 Serial.println (sensor->getType ());
9671070 #endif
1071+ // set auto power pin
1072+ sensor->setAutoPowerPins (_auto_power_pins);
9681073 // add the sensor to the array of registered sensors
9691074 _sensors[sensor->getChildId ()] = sensor;
9701075 // return the child_id
@@ -1114,7 +1219,7 @@ void NodeManager::loop() {
11141219// dispacth inbound messages
11151220void NodeManager::receive (const MyMessage &message) {
11161221 #if DEBUG == 1
1117- Serial.print (" RECV F =" );
1222+ Serial.print (" RECV S =" );
11181223 Serial.print (message.sender );
11191224 Serial.print (" I=" );
11201225 Serial.print (message.sensor );
@@ -1133,13 +1238,13 @@ void NodeManager::receive(const MyMessage &message) {
11331238 else if (message.getCommand () == C_REQ && _sensors[message.sensor ] != 0 ) {
11341239 #if POWER_MANAGER == 1
11351240 // turn on the pin powering all the sensors
1136- powerOn ();
1241+ if (_auto_power_pins) powerOn ();
11371242 #endif
11381243 // call the sensor's receive()
11391244 _sensors[message.sensor ]->receive (message);
11401245 #if POWER_MANAGER == 1
11411246 // turn off the pin powering all the sensors
1142- powerOff ();
1247+ if (_auto_power_pins) powerOff ();
11431248 #endif
11441249 }
11451250}
0 commit comments