Fixed build issue
This commit is contained in:
parent
bfc7308cce
commit
853f1d0fe8
14 changed files with 172 additions and 115 deletions
|
|
@ -1,18 +1,18 @@
|
|||
#ifndef HALCONFIGURATION_H
|
||||
#define HALCONFIGURATION_H
|
||||
|
||||
#include "Definitions.h"
|
||||
#include "HalDefinitions.h"
|
||||
|
||||
|
||||
// POWER CONSUMPTION SENSOR
|
||||
#define POWERCON_ENABLED // comment out to disable sensor
|
||||
#define POWERCON_HARDWARE HardwareDH1750()
|
||||
#define POWERCON_HARDWARE HardwareBH1750()
|
||||
#define POWERCON_PROTOCOL ProtocolOregon(118)
|
||||
#define POWER_TIMER_MULTIPLIER 1 // poling in minutes
|
||||
|
||||
// TEMPERATURE SENSOR
|
||||
#define TEMPERATURE_ENABLED // comment out to disable sensor
|
||||
#define TEMPERATURE_HARDWARE HW_DHT11
|
||||
#define TEMPERATURE_HARDWARE HardwareDHT11(5)
|
||||
#define TEMPERATURE_PROTOCOL ProtocolOregon(100)
|
||||
#define TEMPERATURE_TIMER_MULTIPLIER 1 // poling in minutes
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#ifndef HALINTERFACES_H
|
||||
#define HALINTERFACES_H
|
||||
|
||||
|
||||
class Hardware
|
||||
{
|
||||
public:
|
||||
|
|
@ -11,7 +12,7 @@ class HardwarePowerConsumption : public Hardware
|
|||
{
|
||||
public:
|
||||
// returns number of pulses from power meter
|
||||
virtual int getConsumption() = 0;
|
||||
virtual unsigned int getConsumption() = 0;
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
|
||||
|
|
@ -26,7 +27,7 @@ class HardwareLight : public Hardware
|
|||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual int getLuminosity() = 0;
|
||||
virtual unsigned int getLuminosity() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -38,4 +39,23 @@ public:
|
|||
virtual void send() = 0;
|
||||
};
|
||||
|
||||
class ProtocolPowerConsumption : public Protocol
|
||||
{
|
||||
public:
|
||||
virtual void setConsumption(unsigned int cons) = 0;
|
||||
};
|
||||
|
||||
class ProtocolTemperature : public Protocol
|
||||
{
|
||||
public:
|
||||
virtual void setTemperature(float temp) = 0;
|
||||
virtual void setHumidity(unsigned char humidity) = 0;
|
||||
};
|
||||
|
||||
class ProtocolLight : public Protocol
|
||||
{
|
||||
public:
|
||||
virtual void setLuminosity(int lumen) = 0;
|
||||
};
|
||||
|
||||
#endif // HALINTERFACES_H
|
||||
|
|
@ -2,52 +2,64 @@
|
|||
A interrupt based sensor device that reads multiple sensors and transmits
|
||||
the data to a central location.
|
||||
*/
|
||||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
#include <Wire.h>
|
||||
|
||||
InterruptUtil timerInterrupt;
|
||||
#include "HalInterfaces.h"
|
||||
#include "HalDefinitions.h"
|
||||
#include "HalConfiguration.h"
|
||||
#include "Interrupt.h"
|
||||
|
||||
|
||||
Interrupt* interrupt;
|
||||
|
||||
unsigned int timerMultiplierMAX;
|
||||
unsigned int timerMultiplier = 0;
|
||||
|
||||
// Sensors
|
||||
HardwarePowerConsumption powerSensor;
|
||||
HardwareTemperature tempSensor;
|
||||
HardwareLight lightSensor;
|
||||
HardwarePowerConsumption* powerSensor;
|
||||
HardwareTemperature* tempSensor;
|
||||
HardwareLight* lightSensor;
|
||||
|
||||
// Protocols
|
||||
HardwarePowerConsumption powerProtocol;
|
||||
HardwareTemperature tempProtocol;
|
||||
HardwareLight lightProtocol;
|
||||
ProtocolPowerConsumption* powerProtocol;
|
||||
ProtocolTemperature* tempProtocol;
|
||||
ProtocolLight* lightProtocol;
|
||||
|
||||
|
||||
|
||||
void timerInterrupt();
|
||||
void timerInterruptFunc();
|
||||
|
||||
void setup()
|
||||
{
|
||||
timerMultipleMAX = POWER_TIMER_MULTIPLIER * TEMPERATURE_TIMER_MULTIPLIER * LIGHT_TIMER_MULTIPLIER; // Find a lowest common denominator
|
||||
pinInterrupt = InterruptUtil(timerInterrupt);
|
||||
pinInterrupt.setupTimerInterrupt(60*1000); // one minute scheduled interrupt
|
||||
timerMultiplierMAX = POWER_TIMER_MULTIPLIER * TEMPERATURE_TIMER_MULTIPLIER * LIGHT_TIMER_MULTIPLIER; // Find a lowest common denominator
|
||||
interrupt = new Interrupt(timerInterruptFunc);
|
||||
interrupt->setupTimerInterrupt(60*1000); // one minute scheduled interrupt
|
||||
|
||||
// Setup Sensors and protocols
|
||||
#ifdef POWERCON_ENABLED
|
||||
powerSensor = POWERCON_HARDWARE;
|
||||
powerSensor.setup();
|
||||
powerProtocol = POWERCON_PROTOCOL;
|
||||
powerProtocol.setup();
|
||||
powerSensor = new POWERCON_HARDWARE;
|
||||
powerSensor->setup();
|
||||
powerProtocol = new POWERCON_PROTOCOL;
|
||||
powerProtocol->setup();
|
||||
#endif
|
||||
|
||||
#ifdef TEMPERATURE_ENABLED
|
||||
tempSensor = TEMPERATURE_HARDWARE;
|
||||
tempSensor.setup();
|
||||
tempProtocol = TEMPERATURE_PROTOCOL;
|
||||
tempProtocol.setup();
|
||||
tempSensor = new TEMPERATURE_HARDWARE;
|
||||
tempSensor->setup();
|
||||
tempProtocol = new TEMPERATURE_PROTOCOL;
|
||||
tempProtocol->setup();
|
||||
#endif
|
||||
|
||||
#ifdef LIGHT_ENABLED
|
||||
lightSensor = LIGHT_HARDWARE;
|
||||
lightSensor.setup();
|
||||
lightProtocol = LIGHT_PROTOCOL;
|
||||
lightProtocol.setup();
|
||||
lightSensor = new LIGHT_HARDWARE;
|
||||
lightSensor->setup();
|
||||
lightProtocol = new LIGHT_PROTOCOL;
|
||||
lightProtocol->setup();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +67,7 @@ void setup()
|
|||
void loop() {}
|
||||
|
||||
|
||||
void timerInterrupt()
|
||||
void timerInterruptFunc()
|
||||
{
|
||||
++timerMultiplier;
|
||||
if (timerMultiplier > timerMultiplierMAX)
|
||||
|
|
@ -65,10 +77,10 @@ void timerInterrupt()
|
|||
#ifdef POWERCON_ENABLED
|
||||
if(timerMultiplier == POWER_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int consumption = powerSensor.getConsumption();
|
||||
powerSensor.reset();
|
||||
powerProtocol.setConsumption(consumption);
|
||||
powerProtocol.send();
|
||||
unsigned int consumption = powerSensor->getConsumption();
|
||||
powerSensor->reset();
|
||||
powerProtocol->setConsumption(consumption);
|
||||
powerProtocol->send();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -76,11 +88,11 @@ void timerInterrupt()
|
|||
#ifdef TEMPERATURE_ENABLED
|
||||
if(timerMultiplier == TEMPERATURE_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int temperature = tempSensor.getTemperature();
|
||||
unsigned int humidity = tempSensor.getHumidity();
|
||||
tempProtocol.setTemperature(temperature);
|
||||
tempProtocol.setHumidity(humidity);
|
||||
tempProtocol.send();
|
||||
unsigned int temperature = tempSensor->getTemperature();
|
||||
unsigned int humidity = tempSensor->getHumidity();
|
||||
tempProtocol->setTemperature(temperature);
|
||||
tempProtocol->setHumidity(humidity);
|
||||
tempProtocol->send();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -88,9 +100,9 @@ void timerInterrupt()
|
|||
#ifdef TEMPERATURE_ENABLED
|
||||
if(timerMultiplier == LIGHT_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int lumen = lightSensor.getLuminosity();
|
||||
lightProtocol.setLuminosity(lumen);
|
||||
lightProtocol.send();
|
||||
unsigned int lumen = lightSensor->getLuminosity();
|
||||
lightProtocol->setLuminosity(lumen);
|
||||
lightProtocol->send();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -15,16 +15,13 @@ based on Christopher Laws, March, 2013 code.
|
|||
#include <util/delay.h>
|
||||
|
||||
|
||||
BH1750::BH1750() {}
|
||||
|
||||
void BH1750::begin(uint8_t mode) {
|
||||
void HardwareBH1750::setup() {
|
||||
Wire.begin();
|
||||
//write8(mode);
|
||||
configure(mode);
|
||||
configure(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||
}
|
||||
|
||||
|
||||
void BH1750::configure(uint8_t mode) {
|
||||
void HardwareBH1750::configure(uint8_t mode) {
|
||||
switch (mode) {
|
||||
case BH1750_CONTINUOUS_HIGH_RES_MODE:
|
||||
case BH1750_CONTINUOUS_HIGH_RES_MODE_2:
|
||||
|
|
@ -45,8 +42,16 @@ void BH1750::configure(uint8_t mode) {
|
|||
}
|
||||
}
|
||||
|
||||
unsigned int HardwareBH1750::getConsumption()
|
||||
{
|
||||
return pulses;
|
||||
}
|
||||
void HardwareBH1750::reset()
|
||||
{
|
||||
pulses = 0;
|
||||
}
|
||||
|
||||
uint16_t BH1750::readLightLevel(void) {
|
||||
unsigned int HardwareBH1750::getLuminosity(void) {
|
||||
uint16_t level;
|
||||
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
|
|
@ -81,7 +86,7 @@ uint16_t BH1750::readLightLevel(void) {
|
|||
/*********************************************************************/
|
||||
|
||||
|
||||
void BH1750::write8(uint8_t d) {
|
||||
void HardwareBH1750::write8(uint8_t d) {
|
||||
Wire.beginTransmission(BH1750_I2CADDR);
|
||||
#if (ARDUINO >= 100)
|
||||
Wire.write(d);
|
||||
|
|
|
|||
|
|
@ -12,16 +12,12 @@ http://rohmfs.rohm.com/en/products/databook/datasheet/ic/sensor/light/bh1750fvi-
|
|||
based on Christopher Laws, March, 2013 code.
|
||||
|
||||
*/
|
||||
|
||||
#ifndef HARDWAREBH1750_H
|
||||
#define HARDWAREBH1750_H
|
||||
|
||||
#if (ARDUINO >= 100)
|
||||
#include <Arduino.h>
|
||||
#else
|
||||
#include <WProgram.h>
|
||||
#endif
|
||||
#include "Wire.h"
|
||||
#include <Wire.h>
|
||||
#include "HalInterfaces.h"
|
||||
|
||||
|
||||
#define BH1750_DEBUG 0
|
||||
|
||||
|
|
@ -58,14 +54,16 @@ based on Christopher Laws, March, 2013 code.
|
|||
#define BH1750_ONE_TIME_LOW_RES_MODE 0x23
|
||||
|
||||
|
||||
class BH1750 {
|
||||
class HardwareBH1750 : public HardwarePowerConsumption, public HardwareLight{
|
||||
public:
|
||||
BH1750();
|
||||
void begin(uint8_t mode = BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||
void configure(uint8_t mode);
|
||||
uint16_t readLightLevel(void);
|
||||
virtual void setup();
|
||||
virtual unsigned int getLuminosity();
|
||||
virtual unsigned int getConsumption();
|
||||
virtual void reset();
|
||||
|
||||
void configure(uint8_t mode);
|
||||
private:
|
||||
unsigned int pulses;
|
||||
void write8(uint8_t data);
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -15,13 +15,13 @@
|
|||
// + added references
|
||||
//
|
||||
|
||||
#include "dht11.h"
|
||||
#include "HardwareDHT11.h"
|
||||
|
||||
// returnvalues:
|
||||
// 0 : OK
|
||||
// -1 : checksum error
|
||||
// -2 : timeout
|
||||
int dht11::read(int pin)
|
||||
int HardwareDHT11::read()
|
||||
{
|
||||
// BUFFER TO RECEIVE
|
||||
uint8_t bits[5];
|
||||
|
|
@ -80,6 +80,4 @@ int dht11::read(int pin)
|
|||
if (bits[4] != sum) return -1;
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
|
|
|||
|
|
@ -12,26 +12,26 @@
|
|||
// George Hadjikyriacou - Original version
|
||||
// see dht.cpp file
|
||||
// *** Terry King: Changed include Arduino.h for 1.0x
|
||||
// include core Wiring API and now Arduino
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#ifndef dht11_h
|
||||
#define dht11_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "HalInterfaces.h"
|
||||
|
||||
#define DHT11LIB_VERSION "0.3.2"
|
||||
|
||||
class dht11
|
||||
class HardwareDHT11 : public HardwareTemperature
|
||||
{
|
||||
public:
|
||||
int read(int pin);
|
||||
int humidity;
|
||||
int temperature;
|
||||
HardwareDHT11(int pin);
|
||||
virtual void setup(){};
|
||||
virtual int getTemperature();
|
||||
virtual int getHumidity();
|
||||
int read();
|
||||
|
||||
private:
|
||||
unsigned int pin;
|
||||
float temperature;
|
||||
unsigned char humidity;
|
||||
};
|
||||
#endif
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
|
@ -1,23 +1,24 @@
|
|||
#include "HardwarePhotocell.h"
|
||||
|
||||
|
||||
public void pinInterrupt()
|
||||
void pinInterrupt()
|
||||
{
|
||||
++pulse;
|
||||
//++pulse;
|
||||
}
|
||||
|
||||
|
||||
public HardwarePhotocell::setup()
|
||||
void HardwarePhotocell::setup()
|
||||
{
|
||||
pinInterrupt = InterruptUtil(pinInterrupt);
|
||||
pinInterrupt.setupPinInterrupt(PC2); //PC3
|
||||
interrupt = new Interrupt(pinInterrupt);
|
||||
interrupt->setupPinInterrupt(PC2); //PC3
|
||||
}
|
||||
|
||||
public unsigned int HardwarePhotocell::getConsumption()
|
||||
unsigned int HardwarePhotocell::getConsumption()
|
||||
{
|
||||
return pulse;
|
||||
}
|
||||
|
||||
public unsigned int HardwarePhotocell::reset()
|
||||
void HardwarePhotocell::reset()
|
||||
{
|
||||
pulse = 0;
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef HARDWAREPHOTOCELL_H
|
||||
#define HARDWAREPHOTOCELL_H
|
||||
|
||||
#include "HalInterfaces.h"
|
||||
#include "Interrupt.h"
|
||||
|
||||
|
||||
class HardwarePhotocell : public HardwarePowerConsumption
|
||||
{
|
||||
|
|
@ -10,7 +13,8 @@ public:
|
|||
virtual void reset();
|
||||
|
||||
private:
|
||||
Interrupt* interrupt;
|
||||
unsigned int pulse;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // HARDWAREPHOTOCELL_H
|
||||
|
|
@ -1,8 +1,11 @@
|
|||
#include "Interrupt.h"
|
||||
#include <avr/power.h>
|
||||
#include <avr/sleep.h>
|
||||
|
||||
|
||||
void Interrupt::pinInterrupt() // here the interrupt is handled after wakeup
|
||||
|
||||
|
||||
void pinInterrupt() // here the interrupt is handled after wakeup
|
||||
{
|
||||
// execute code here after wake-up before returning to the loop() function
|
||||
// timers and code using timers (serial.print and more...) will not work here.
|
||||
|
|
@ -10,7 +13,12 @@ void Interrupt::pinInterrupt() // here the interrupt is handled after wak
|
|||
// just want the thing to wake up
|
||||
}
|
||||
|
||||
void Interrupt::setupInterrupt()
|
||||
void Interrupt::setupPinInterrupt(int pin)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Interrupt::setupTimerInterrupt(unsigned int milliseconds)
|
||||
{
|
||||
/*
|
||||
* The 5 different modes are:
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#ifndef INTERRUPT_H
|
||||
#define INTERRUPT_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
|
||||
typedef void (*InterruptFunction) ();
|
||||
|
||||
class Interrupt
|
||||
|
|
@ -10,9 +13,10 @@ public:
|
|||
|
||||
//static void sleep(int milliseconds);
|
||||
void setupPinInterrupt(int pin);
|
||||
void setupTimerInterrupt(int milliseconds);
|
||||
void setupTimerInterrupt(unsigned int milliseconds);
|
||||
private:
|
||||
InterruptFunction callback;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#endif // INTERRUPT_H
|
||||
|
|
@ -1,4 +1,8 @@
|
|||
#ifndef PROTOCOLNEXA_H
|
||||
#define PROTOCOLNEXA_H
|
||||
|
||||
#include "HalInterfaces.h"
|
||||
|
||||
|
||||
|
||||
#endif // PROTOCOLNEXA_H
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
#include <Wire.h>
|
||||
#include "ProtocolOregon.h"
|
||||
|
||||
#define RF_TX_PIN = 10;
|
||||
#define RF_DELAY = 512;
|
||||
#define RF_DELAY_LONG RF_DELAY*2;
|
||||
#define RF_TX_PIN 10
|
||||
#define RF_DELAY 512
|
||||
#define RF_DELAY_LONG RF_DELAY*2
|
||||
#define RF_SEND_HIGH() digitalWrite(RF_TX_PIN, HIGH)
|
||||
#define RF_SEND_LOW() digitalWrite(RF_TX_PIN, LOW)
|
||||
|
||||
|
|
@ -13,18 +13,18 @@ void ProtocolOregon::setup()
|
|||
RF_SEND_LOW();
|
||||
}
|
||||
|
||||
virtual void ProtocolOregon::setTemperature(float temp)
|
||||
void ProtocolOregon::setTemperature(float temp)
|
||||
{
|
||||
this.temperature = temp;
|
||||
this->temperature = temp;
|
||||
}
|
||||
virtual void ProtocolOregon::setHumidity(unsigned char humidity)
|
||||
void ProtocolOregon::setHumidity(unsigned char humidity)
|
||||
{
|
||||
this.humidity = humidity;
|
||||
this->humidity = humidity;
|
||||
}
|
||||
virtual void ProtocolOregon::setConsumption(unsigned int cons)
|
||||
void ProtocolOregon::setConsumption(unsigned int cons)
|
||||
{
|
||||
this.temperature = cons;
|
||||
this.humidity = 0;
|
||||
this->temperature = cons;
|
||||
this->humidity = 0;
|
||||
}
|
||||
|
||||
void ProtocolOregon::send()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
#ifndef PROTOCOLOREGON_H
|
||||
#define PROTOCOLOREGON_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "HalInterfaces.h"
|
||||
|
||||
class ProtocolOregon : public ProtocolTemperature : public ProtocolPower
|
||||
|
||||
class ProtocolOregon : public ProtocolTemperature, public ProtocolPowerConsumption
|
||||
{
|
||||
public:
|
||||
ProtocolOregon(unsigned char address) : address(address){}
|
||||
ProtocolOregon(unsigned char address) : address(address){};
|
||||
|
||||
virtual void setup();
|
||||
virtual void setTemperature(float temp);
|
||||
|
|
@ -14,7 +17,7 @@ public:
|
|||
virtual void send();
|
||||
private:
|
||||
unsigned char address;
|
||||
unsigned float temperature;
|
||||
float temperature;
|
||||
unsigned char humidity;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue