@@ -21,10 +21,10 @@ const char* WAKEUP = "WAKEUP";
21
21
// set the vcc and ground pin the sensor is connected to
22
22
void PowerManager::setPowerPins (int ground_pin, int vcc_pin, long wait = 10 ) {
23
23
#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 );
28
28
#endif
29
29
// configure the vcc pin as output and initialize to low (power off)
30
30
_vcc_pin = vcc_pin;
@@ -619,7 +619,7 @@ void SensorDHT::onReceive(const MyMessage & message) {
619
619
*/
620
620
#if MODULE_SHT21 == 1
621
621
// 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 ) {
623
623
// store the sensor type (0: temperature, 1: humidity)
624
624
_sensor_type = sensor_type;
625
625
if (_sensor_type == 0 ) {
@@ -681,6 +681,15 @@ void SensorSHT21::onReceive(const MyMessage & message) {
681
681
}
682
682
#endif
683
683
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
+
684
693
/*
685
694
* SensorSwitch
686
695
*/
@@ -795,8 +804,81 @@ void SensorDs18b20::onLoop() {
795
804
void SensorDs18b20::onReceive (const MyMessage & message) {
796
805
onLoop ();
797
806
}
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
+ }
798
857
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
+ }
799
877
878
+ // what do to as the main task when receiving a message
879
+ void SensorMLX90614::onReceive (const MyMessage & message) {
880
+ onLoop ();
881
+ }
800
882
#endif
801
883
802
884
/* ******************************************
@@ -915,6 +997,11 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
915
997
child_id = _getAvailableChildId ();
916
998
registerSensor (new SensorSHT21 (child_id,1 ));
917
999
}
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
+ }
918
1005
#endif
919
1006
#if MODULE_SWITCH == 1
920
1007
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
944
1031
}
945
1032
}
946
1033
#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
947
1050
else {
948
1051
#if DEBUG == 1
949
1052
Serial.print (" INVALID " );
@@ -965,6 +1068,8 @@ int NodeManager::registerSensor(Sensor* sensor) {
965
1068
Serial.print (" T=" );
966
1069
Serial.println (sensor->getType ());
967
1070
#endif
1071
+ // set auto power pin
1072
+ sensor->setAutoPowerPins (_auto_power_pins);
968
1073
// add the sensor to the array of registered sensors
969
1074
_sensors[sensor->getChildId ()] = sensor;
970
1075
// return the child_id
@@ -1114,7 +1219,7 @@ void NodeManager::loop() {
1114
1219
// dispacth inbound messages
1115
1220
void NodeManager::receive (const MyMessage &message) {
1116
1221
#if DEBUG == 1
1117
- Serial.print (" RECV F =" );
1222
+ Serial.print (" RECV S =" );
1118
1223
Serial.print (message.sender );
1119
1224
Serial.print (" I=" );
1120
1225
Serial.print (message.sensor );
@@ -1133,13 +1238,13 @@ void NodeManager::receive(const MyMessage &message) {
1133
1238
else if (message.getCommand () == C_REQ && _sensors[message.sensor ] != 0 ) {
1134
1239
#if POWER_MANAGER == 1
1135
1240
// turn on the pin powering all the sensors
1136
- powerOn ();
1241
+ if (_auto_power_pins) powerOn ();
1137
1242
#endif
1138
1243
// call the sensor's receive()
1139
1244
_sensors[message.sensor ]->receive (message);
1140
1245
#if POWER_MANAGER == 1
1141
1246
// turn off the pin powering all the sensors
1142
- powerOff ();
1247
+ if (_auto_power_pins) powerOff ();
1143
1248
#endif
1144
1249
}
1145
1250
}
0 commit comments