Skip to content

Commit

Permalink
Release v1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
DV committed Mar 22, 2017
1 parent ae3029a commit f22ad11
Show file tree
Hide file tree
Showing 5 changed files with 247 additions and 55 deletions.
121 changes: 113 additions & 8 deletions NodeManagerTemplate/NodeManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ const char* WAKEUP = "WAKEUP";
// set the vcc and ground pin the sensor is connected to
void PowerManager::setPowerPins(int ground_pin, int vcc_pin, long wait = 10) {
#if DEBUG == 1
Serial.print("POWER V=");
Serial.print(vcc_pin);
Serial.print(" G=");
Serial.println(ground_pin);
Serial.print("POWER G=");
Serial.print(ground_pin);
Serial.print(" V=");
Serial.println(vcc_pin);
#endif
// configure the vcc pin as output and initialize to low (power off)
_vcc_pin = vcc_pin;
Expand Down Expand Up @@ -619,7 +619,7 @@ void SensorDHT::onReceive(const MyMessage & message) {
*/
#if MODULE_SHT21 == 1
// contructor
SensorSHT21::SensorSHT21(int child_id, int sensor_type): Sensor(child_id, -1) {
SensorSHT21::SensorSHT21(int child_id, int sensor_type): Sensor(child_id,A2) {
// store the sensor type (0: temperature, 1: humidity)
_sensor_type = sensor_type;
if (_sensor_type == 0) {
Expand Down Expand Up @@ -681,6 +681,15 @@ void SensorSHT21::onReceive(const MyMessage & message) {
}
#endif

/*
* SensorHTU21D
*/
#if MODULE_SHT21 == 1
// constructor
SensorHTU21D::SensorHTU21D(int child_id, int pin): SensorSHT21(child_id, pin) {
}
#endif

/*
* SensorSwitch
*/
Expand Down Expand Up @@ -795,8 +804,81 @@ void SensorDs18b20::onLoop() {
void SensorDs18b20::onReceive(const MyMessage & message) {
onLoop();
}
#endif

/*
SensorBH1750
*/
#if MODULE_BH1750 == 1
// contructor
SensorBH1750::SensorBH1750(int child_id): Sensor(child_id,A4) {
setPresentation(S_LIGHT_LEVEL);
setType(V_LEVEL);
_lightSensor = new BH1750();
}

// what do to during setup
void SensorBH1750::onBefore() {
_lightSensor->begin();
}

// what do to during loop
void SensorBH1750::onLoop() {
// request the light level
_value_int = _lightSensor->readLightLevel();
#if DEBUG == 1
Serial.print("BH1 I=");
Serial.print(_child_id);
Serial.print(" L=");
Serial.println(_value_int);
#endif
}

// what do to as the main task when receiving a message
void SensorBH1750::onReceive(const MyMessage & message) {
onLoop();
}
#endif

/*
SensorMLX90614
*/
#if MODULE_MLX90614 == 1
// contructor
SensorMLX90614::SensorMLX90614(int child_id, Adafruit_MLX90614* mlx, int sensor_type): Sensor(child_id,A4) {
// store the sensor type (0: ambient, 1: object)
_sensor_type = sensor_type;
_mlx = mlx;
// set presentation and type
setPresentation(S_TEMP);
setType(V_TEMP);
setValueType(TYPE_FLOAT);
}

// what do to during setup
void SensorMLX90614::onBefore() {
// initialize the library
_mlx->begin();
}

// what do to during loop
void SensorMLX90614::onLoop() {
float temperature = _sensor_type == 0 ? _mlx->readAmbientTempC() : _mlx->readObjectTempC();
// convert it
if (! getControllerConfig().isMetric) temperature = temperature * 1.8 + 32;
#if DEBUG == 1
Serial.print("MLX I=");
Serial.print(_child_id);
Serial.print(" T=");
Serial.println(temperature);
#endif
if (! isnan(temperature)) _value_float = temperature;
}

// what do to as the main task when receiving a message
void SensorMLX90614::onReceive(const MyMessage & message) {
onLoop();
}
#endif

/*******************************************
Expand Down Expand Up @@ -915,6 +997,11 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
child_id = _getAvailableChildId();
registerSensor(new SensorSHT21(child_id,1));
}
else if (sensor_type == SENSOR_HTU21D) {
registerSensor(new SensorHTU21D(child_id,0));
child_id = _getAvailableChildId();
registerSensor(new SensorHTU21D(child_id,1));
}
#endif
#if MODULE_SWITCH == 1
else if (sensor_type == SENSOR_SWITCH || sensor_type == SENSOR_DOOR || sensor_type == SENSOR_MOTION) {
Expand Down Expand Up @@ -944,6 +1031,22 @@ int NodeManager::registerSensor(int sensor_type, int pin = -1, int child_id = -1
}
}
#endif
#if MODULE_BH1750 == 1
else if (sensor_type == SENSOR_BH1750) {
return registerSensor(new SensorBH1750(child_id));
}
#endif
#if MODULE_MLX90614 == 1
else if (sensor_type == SENSOR_MLX90614) {
Serial.println("1");
Adafruit_MLX90614* mlx = new Adafruit_MLX90614();
Serial.println("2");
registerSensor(new SensorMLX90614(child_id,mlx,0));
Serial.println("3");
child_id = _getAvailableChildId();
registerSensor(new SensorMLX90614(child_id,mlx,1));
}
#endif
else {
#if DEBUG == 1
Serial.print("INVALID ");
Expand All @@ -965,6 +1068,8 @@ int NodeManager::registerSensor(Sensor* sensor) {
Serial.print(" T=");
Serial.println(sensor->getType());
#endif
// set auto power pin
sensor->setAutoPowerPins(_auto_power_pins);
// add the sensor to the array of registered sensors
_sensors[sensor->getChildId()] = sensor;
// return the child_id
Expand Down Expand Up @@ -1114,7 +1219,7 @@ void NodeManager::loop() {
// dispacth inbound messages
void NodeManager::receive(const MyMessage &message) {
#if DEBUG == 1
Serial.print("RECV F=");
Serial.print("RECV S=");
Serial.print(message.sender);
Serial.print(" I=");
Serial.print(message.sensor);
Expand All @@ -1133,13 +1238,13 @@ void NodeManager::receive(const MyMessage &message) {
else if (message.getCommand() == C_REQ && _sensors[message.sensor] != 0) {
#if POWER_MANAGER == 1
// turn on the pin powering all the sensors
powerOn();
if (_auto_power_pins) powerOn();
#endif
// call the sensor's receive()
_sensors[message.sensor]->receive(message);
#if POWER_MANAGER == 1
// turn off the pin powering all the sensors
powerOff();
if (_auto_power_pins) powerOff();
#endif
}
}
Expand Down
79 changes: 70 additions & 9 deletions NodeManagerTemplate/NodeManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define EEPROM_SLEEP_UNIT 4

// define NodeManager version
#define VERSION 1.1
#define VERSION 1.2

/************************************
* Include user defined configuration settings
Expand Down Expand Up @@ -109,7 +109,7 @@
#ifndef MODULE_DIGITAL_OUTPUT
#define MODULE_DIGITAL_OUTPUT 0
#endif
// Enable this module to use one of the following sensors: SENSOR_SHT21
// Enable this module to use one of the following sensors: SENSOR_SHT21, SENSOR_HTU21D
#ifndef MODULE_SHT21
#define MODULE_SHT21 0
#endif
Expand All @@ -125,7 +125,14 @@
#ifndef MODULE_DS18B20
#define MODULE_DS18B20 0
#endif

// Enable this module to use one of the following sensors: SENSOR_BH1750
#ifndef MODULE_BH1750
#define MODULE_BH1750 0
#endif
// Enable this module to use one of the following sensors: SENSOR_MLX90614
#ifndef MODULE_MLX90614
#define MODULE_MLX90614 0
#endif

/***********************************
Sensors types
Expand Down Expand Up @@ -158,6 +165,7 @@
#if MODULE_SHT21 == 1
// SHT21 sensor, return temperature/humidity based on the attached SHT21 sensor
#define SENSOR_SHT21 10
#define SENSOR_HTU21D 15
#endif
#if MODULE_SWITCH == 1
// Generic switch, wake up the board when a pin changes status
Expand All @@ -171,7 +179,16 @@
// DS18B20 sensor, return the temperature based on the attached sensor
#define SENSOR_DS18B20 14
#endif
#if MODULE_BH1750 == 1
// BH1750 sensor, return light in lux
#define SENSOR_BH1750 16
#endif
#if MODULE_MLX90614 == 1
// MLX90614 sensor, contactless temperature sensor
#define SENSOR_MLX90614 17
#endif

// last Id: 17
/***********************************
Libraries
*/
Expand All @@ -188,15 +205,18 @@
#include <Wire.h>
#include <Sodaq_SHT2x.h>
#endif
#if MODULE_SHT21 == 1
#include <Wire.h>
#include <Sodaq_SHT2x.h>
#endif
#if MODULE_DS18B20 == 1
#include <OneWire.h>
#include <DallasTemperature.h>
#endif

#if MODULE_BH1750 == 1
#include <BH1750.h>
#include <Wire.h>
#endif
#if MODULE_MLX90614 == 1
#include <Wire.h>
#include <Adafruit_MLX90614.h>
#endif

/**************************************
Classes
Expand Down Expand Up @@ -438,7 +458,7 @@ class SensorDHT: public Sensor {
#endif

/*
SensorSHT21
SensorSHT21: temperature and humidity sensor
*/
#if MODULE_SHT21 == 1
class SensorSHT21: public Sensor {
Expand All @@ -452,6 +472,15 @@ class SensorSHT21: public Sensor {
float _offset = 0;
int _sensor_type = 0;
};

/*
SensorHTU21D: temperature and humidity sensor
*/

class SensorHTU21D: public SensorSHT21 {
public:
SensorHTU21D(int child_id, int pin);
};
#endif

/*
Expand Down Expand Up @@ -511,6 +540,38 @@ class SensorDs18b20: public Sensor {
};
#endif

/*
SensorBH1750
*/
#if MODULE_BH1750 == 1
class SensorBH1750: public Sensor {
public:
SensorBH1750(int child_id);
// define what to do at each stage of the sketch
void onBefore();
void onLoop();
void onReceive(const MyMessage & message);
protected:
BH1750* _lightSensor;
};
#endif

/*
SensorMLX90614
*/
#if MODULE_MLX90614 == 1
class SensorMLX90614: public Sensor {
public:
SensorMLX90614(int child_id, Adafruit_MLX90614* mlx, int sensor_type);
// define what to do at each stage of the sketch
void onBefore();
void onLoop();
void onReceive(const MyMessage & message);
protected:
Adafruit_MLX90614* _mlx;
int _sensor_type;
};
#endif

/***************************************
NodeManager: manages all the aspects of the node
Expand Down
6 changes: 3 additions & 3 deletions NodeManagerTemplate/NodeManagerTemplate.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ void before() {
Serial.begin(9600);
/*
* Register below your sensors
*/

*/

/*
* Register above your sensors
*/
*/
nodeManager.before();
}

Expand Down
Loading

0 comments on commit f22ad11

Please sign in to comment.