Some more work on Hal Arduino sensor. issue 18
This commit is contained in:
parent
050addfa31
commit
c9a030774b
8 changed files with 128 additions and 33 deletions
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "Definitions.h"
|
||||
|
||||
#define POLTIME 60*10 // poling in seconds
|
||||
|
||||
// POWER CONSUMPTION SENSOR
|
||||
#define POWERCON_ENABLED // comment out to disable sensor
|
||||
|
|
@ -14,13 +13,13 @@
|
|||
#define TEMPERATURE_ENABLED // comment out to disable sensor
|
||||
#define TEMPERATURE_HARDWARE HW_DHT11
|
||||
#define TEMPERATURE_PROTOCOL PROT_OREGON
|
||||
#define TEMPERATURE_POL_MULTIPLE 1 // poling in seconds
|
||||
#define TEMPERATURE_TIMER_MULTIPLIER 1 // poling in minutes
|
||||
|
||||
// LIGHT SENSOR
|
||||
#define LIGHT_ENABLED // comment out to disable sensor
|
||||
#define LIGHT_HARDWARE HW_BHI750
|
||||
#define LIGHT_PROTOCOL PROT_OREGON
|
||||
#define LIGHT_POL_MULTIPLE 1 // poling in seconds
|
||||
#define LIGHT_TIMER_MULTIPLIER 1 // poling in minutes
|
||||
|
||||
|
||||
#endif // HALCONFIGURATION_H
|
||||
|
|
@ -1,33 +1,34 @@
|
|||
#ifndef HALINTERFACES_H
|
||||
#define HALINTERFACES_H
|
||||
|
||||
class HardwarePowerConsumption
|
||||
class Hardware
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual int getConsumption() = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class HardwareTemperature
|
||||
class HardwarePowerConsumption : public Hardware
|
||||
{
|
||||
public:
|
||||
// returns number of pulses from power meter
|
||||
virtual int getConsumption() = 0;
|
||||
virtual void reset() = 0;
|
||||
};
|
||||
|
||||
class HardwareTemperature : public Hardware
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual int getTemperature() = 0;
|
||||
virtual int getHumidity() = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class HardwareLight
|
||||
class HardwareLight : public Hardware
|
||||
{
|
||||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual int getLuminosity() = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class HardwareInterrupt
|
||||
{
|
||||
public:
|
||||
virtual void interrupt(bool enable) = 0;
|
||||
}
|
||||
|
||||
|
||||
class Protocol
|
||||
|
|
@ -35,6 +36,6 @@ class Protocol
|
|||
public:
|
||||
virtual void setup() = 0;
|
||||
virtual void send() = 0;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // HALINTERFACES_H
|
||||
|
|
@ -3,13 +3,68 @@ A interrupt based sensor device that reads multiple sensors and transmits
|
|||
the data to a central location.
|
||||
*/
|
||||
|
||||
InterruptUtil timerInterrupt;
|
||||
|
||||
unsigned int timerMultiplierMAX;
|
||||
unsigned int timerMultiplier = 0;
|
||||
|
||||
// Sensors
|
||||
HardwarePowerConsumption powerSensor;
|
||||
HardwareTemperature temperatureSensor;
|
||||
HardwareLight lightSensor;
|
||||
|
||||
// Protocols
|
||||
HardwarePowerConsumption powerProtocol;
|
||||
HardwareTemperature temperatureProtocol;
|
||||
HardwareLight lightProtocol;
|
||||
|
||||
|
||||
|
||||
void timerInterrupt()
|
||||
{
|
||||
++timerMultiplier;
|
||||
if (timerMultiplier > timerMultiplierMAX)
|
||||
timerMultiplier = 1;
|
||||
|
||||
// Send power consumption
|
||||
#ifndef POWERCON_ENABLED
|
||||
unsigned int consumption = powerSensor.getConsumption();
|
||||
powerSensor.reset();
|
||||
powerProtocol.setConsumption(consumption);
|
||||
powerProtocol.send();
|
||||
#endif
|
||||
|
||||
// Handle temperature sensor
|
||||
#ifndef TEMPERATURE_ENABLED
|
||||
if(timerMultiplier == TEMPERATURE_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int temperature = temperatureSensor.getTemperature();
|
||||
unsigned int humidity = temperatureSensor.getHumidity();
|
||||
temperatureProtocol.setTemperature(temperature);
|
||||
temperatureProtocol.setHumidity(humidity);
|
||||
temperatureProtocol.send();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Handle light sensor
|
||||
#ifndef TEMPERATURE_ENABLED
|
||||
if(timerMultiplier == LIGHT_TIMER_MULTIPLIER)
|
||||
{
|
||||
unsigned int lumen = lightSensor.getLuminosity();
|
||||
lightProtocol.setLuminosity(lumen);
|
||||
lightProtocol.send();
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
timerMultipleMAX = LIGHT_TIMER_MULTIPLIER * TEMPERATURE_TIMER_MULTIPLIER; // Find a lowest common denominator
|
||||
pinInterrupt = InterruptUtil(timerInterrupt);
|
||||
pinInterrupt.setupTimerInterrupt(60*1000); // one minute scheduled interrupt
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
void loop() {}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
|
||||
public void pinInterrupt()
|
||||
{
|
||||
++pulse;
|
||||
}
|
||||
|
||||
|
||||
public HardwarePhotocell::setup()
|
||||
{
|
||||
pinInterrupt = InterruptUtil(pinInterrupt);
|
||||
pinInterrupt.setupPinInterrupt(PC2); //PC3
|
||||
}
|
||||
|
||||
public unsigned int HardwarePhotocell::getConsumption()
|
||||
{
|
||||
return pulse;
|
||||
}
|
||||
|
||||
public unsigned int HardwarePhotocell::reset()
|
||||
{
|
||||
pulse = 0;
|
||||
}
|
||||
|
|
@ -1,4 +1,16 @@
|
|||
#ifndef HARDWAREPHOTOCELL_H
|
||||
#define HARDWAREPHOTOCELL_H
|
||||
|
||||
|
||||
class HardwarePhotocell : public HardwarePowerConsumption
|
||||
{
|
||||
public:
|
||||
virtual void setup();
|
||||
virtual unsigned int getConsumption();
|
||||
virtual void reset();
|
||||
|
||||
private:
|
||||
unsigned int pulse;
|
||||
}
|
||||
|
||||
#endif // HARDWAREPHOTOCELL_H
|
||||
18
arduino/HalMultiSensor/Interrupt.h
Executable file
18
arduino/HalMultiSensor/Interrupt.h
Executable file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef INTERRUPT_H
|
||||
#define INTERRUPT_H
|
||||
|
||||
typedef void (*InterruptFunction) ();
|
||||
|
||||
class Interrupt
|
||||
{
|
||||
public:
|
||||
Interrupt(InterruptFunction callback) : callback(callback) {};
|
||||
|
||||
//static void sleep(int milliseconds);
|
||||
void setupPinInterrupt(int pin);
|
||||
void setupTimerInterrupt(int milliseconds);
|
||||
private:
|
||||
InterruptFunction callback;
|
||||
}
|
||||
|
||||
#endif // INTERRUPT_H
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
#ifndef INTERRUPT_H
|
||||
#define INTERRUPT_H
|
||||
|
||||
|
||||
class INTERRUPT_H
|
||||
{
|
||||
public:
|
||||
sleep();
|
||||
private:
|
||||
pinInterrupt();
|
||||
}
|
||||
|
||||
#endif // INTERRUPT_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue