Fixed some issues with oregon protocoll and first version of HalMultiSensor done.

This commit is contained in:
Ziver Koc 2016-05-31 21:11:53 +02:00
parent 4f6066fe7a
commit 92fb46ea0f
14 changed files with 333 additions and 536 deletions

View file

@ -1,19 +1,19 @@
#ifndef HALCONFIGURATION_H
#define HALCONFIGURATION_H
#define ENABLE_DEBUG // comment out to disable debug
//#define ENABLE_DEBUG // comment out to disable debug
#define TIMER_MILLISECOND 10*1000 // poling in minutes
#define INDICATOR_PIN 13 // diod
#define TIMER_MILLISECOND 60*1000 // poling in minutes
#define INDICATOR_PIN 13 // diode
// POWER CONSUMPTION SENSOR
#define POWERCON_ENABLED // comment out to disable sensor
#define POWERCON_SENSOR SensorBH1750()
#define POWERCON_PROTOCOL ProtocolOregon(11, 118)
#define POWERCON_SENSOR SensorPhotocell()
#define POWERCON_PROTOCOL ProtocolOregon(11, 186)
#define POWER_TIMER_MULTIPLIER 1
// TEMPERATURE SENSOR
#define TEMPERATURE_ENABLED // comment out to disable sensor
//#define TEMPERATURE_ENABLED // comment out to disable sensor
#define TEMPERATURE_SENSOR SensorDHT(DHT22, 10)
#define TEMPERATURE_PROTOCOL ProtocolOregon(11, 100)
#define TEMPERATURE_TIMER_MULTIPLIER 1

View file

@ -1,13 +1,12 @@
#ifndef HALINTERFACES_H
#define HALINTERFACES_H
#include <Arduino.h>
#include "HalConfiguration.h"
// Utility functions
#ifdef ENABLE_DEBUG
#include <Arduino.h>
#define DEBUG(msg) \
Serial.println(msg); \
Serial.flush();

View file

@ -60,7 +60,7 @@ void setup()
lightProtocol->setup();
#endif
DEBUG("Setup INTERRUPT");
DEBUG("Setup SLEEP_INTERRUPT");
Interrupt::setWatchDogCallback(timerInterruptFunc);
Interrupt::setupWatchDogInterrupt(TIMER_MILLISECOND); // one minute scheduled interrupt
@ -80,7 +80,7 @@ void timerInterruptFunc()
void loop()
{
digitalWrite(INDICATOR_PIN, HIGH);
noInterrupts();
//noInterrupts();
// Send power consumption
#ifdef POWERCON_ENABLED
@ -115,7 +115,7 @@ void loop()
}
#endif
interrupts();
//interrupts();
digitalWrite(INDICATOR_PIN, LOW);
DEBUG("Sleeping");

View file

@ -71,7 +71,7 @@ void Interrupt::setupPinInterrupt(int pin)
*
* In all but the IDLE sleep modes only LOW can be used.
*/
attachInterrupt((pin == PIND2 ? 0 : 1), Interrupt::handlePinInterrupt, LOW);
attachInterrupt((pin == PIND2 ? 0 : 1), Interrupt::handlePinInterrupt, RISING);
//detachInterrupt(0); // disables interrupt 0 on pin 2 so the
// wakeUpNow code will not be executed

View file

@ -49,7 +49,7 @@ void ProtocolOregon::send(float temperature, short humidity)
* \param data Oregon message
* \param type Sensor type
*/
inline void ProtocolOregon::setType(byte *data, byte b1, byte b2)
inline void ProtocolOregon::setType(byte data[], byte b1, byte b2)
{
data[0] = b1;
data[1] = b2;
@ -60,13 +60,13 @@ inline void ProtocolOregon::setType(byte *data, byte b1, byte b2)
* \param data Oregon message
* \param channel Sensor channel (0x10, 0x20, 0x30)
*/
inline void ProtocolOregon::setChannel(byte *data, byte channel)
inline void ProtocolOregon::setChannel(byte data[], byte channel)
{
data[2] = channel;
}
inline void ProtocolOregon::setId(byte *data, byte id)
inline void ProtocolOregon::setId(byte data[], byte id)
{
data[3] = id;
}
@ -74,13 +74,13 @@ inline void ProtocolOregon::setId(byte *data, byte id)
/**
* \param level false: low, true: high
*/
inline void ProtocolOregon::setBatteryLevel(byte *data, bool level)
inline void ProtocolOregon::setBatteryLevel(byte data[], bool level)
{
if(!level) data[4] = 0x0C;
else data[4] = 0x00;
}
inline void ProtocolOregon::setTemperature(byte *data, float temp)
inline void ProtocolOregon::setTemperature(byte data[], float temp)
{
// Set temperature sign
if(temp < 0)
@ -108,13 +108,13 @@ inline void ProtocolOregon::setTemperature(byte *data, float temp)
data[4] |= (tempFloat << 4);
}
inline void ProtocolOregon::setHumidity(byte* data, byte hum)
inline void ProtocolOregon::setHumidity(byte data[], byte hum)
{
data[7] = (hum/10);
data[6] |= (hum - data[7]*10) << 4;
}
inline void ProtocolOregon::calculateAndSetChecksum(byte* data)
inline void ProtocolOregon::calculateAndSetChecksum(byte data[])
{
int sum = 0;
for(byte i = 0; i<8;i++)
@ -173,9 +173,9 @@ inline void ProtocolOregon::sendOne(void)
* \param data Data to send
* \param length size of data array
*/
void ProtocolOregon::sendData(byte *data, byte length)
void ProtocolOregon::sendData(byte data[], byte length)
{
for(byte i = 0; i < length; ++i)
for (byte i=0; i<length; ++i)
{
(bitRead(data[i], 0)) ? sendOne() : sendZero();
(bitRead(data[i], 1)) ? sendOne() : sendZero();
@ -192,7 +192,7 @@ void ProtocolOregon::sendData(byte *data, byte length)
* \brief Send an Oregon message
* \param data The Oregon message
*/
void ProtocolOregon::rfSend(byte *data, byte size)
void ProtocolOregon::rfSend(byte data[], byte size)
{
// Send preamble
byte preamble[] = { 0xFF,0xFF };

View file

@ -1,9 +1,14 @@
#include "SensorPhotocell.h"
#include <Arduino.h>
unsigned int SensorPhotocell::pulse = 0;
void SensorPhotocell::interruptHandler()
{
digitalWrite(INDICATOR_PIN, HIGH);
DEBUG("PHCELL: INTERRUPT");
++pulse;
digitalWrite(INDICATOR_PIN, LOW);
}