Fixed DHT sensor
This commit is contained in:
parent
c2c5935284
commit
26c909ac8d
4 changed files with 26 additions and 14 deletions
|
|
@ -1,11 +1,12 @@
|
|||
#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 60*1000 // poling in minutes
|
||||
#define INDICATOR_PIN 13 // diode
|
||||
|
||||
|
||||
// POWER CONSUMPTION SENSOR
|
||||
#define POWERCON_ENABLED // comment out to disable sensor
|
||||
#define POWERCON_SENSOR SensorPhotocell()
|
||||
|
|
@ -13,16 +14,16 @@
|
|||
#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
|
||||
#define TEMPERATURE_TIMER_MULTIPLIER 10
|
||||
|
||||
// LIGHT SENSOR
|
||||
//#define LIGHT_ENABLED // comment out to disable sensor
|
||||
#define LIGHT_SENSOR SensorDH1750()
|
||||
#define LIGHT_PROTOCOL ?
|
||||
#define LIGHT_TIMER_MULTIPLIER 1
|
||||
#define LIGHT_TIMER_MULTIPLIER 10
|
||||
|
||||
|
||||
#endif // HALCONFIGURATION_H
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ void loop()
|
|||
{
|
||||
static TemperatureData tempData;
|
||||
tempSensor->read(tempData);
|
||||
DEBUGF("Read TEMPERATURE_SENSOR= temperature:%d, humidity:%d", tempData.temperature, tempData.humidity);
|
||||
DEBUGF("Read TEMPERATURE_SENSOR= temperature:%d, humidity:%d", (int)tempData.temperature, (int)tempData.humidity);
|
||||
tempProtocol->send(tempData);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -81,21 +81,24 @@ void Interrupt::setupPinInterrupt(int pin)
|
|||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Watchdog timer
|
||||
unsigned int wdtTime;
|
||||
long wdtTimeLeft;
|
||||
uint16_t wdtTime;
|
||||
int32_t wdtTimeLeft;
|
||||
|
||||
|
||||
void Interrupt::handleWatchDogInterrupt()
|
||||
{
|
||||
//DEBUG("WDT Interrupt");
|
||||
wdt_disable();
|
||||
if (wdtTimeLeft < 0)
|
||||
if (wdtTime <= 0)
|
||||
return;
|
||||
DEBUGF("WDT interrupt, time=%d, timeLeft=%d", wdtTime, wdtTimeLeft);
|
||||
|
||||
if (wdtTimeLeft <= 0)
|
||||
{
|
||||
DEBUG("WDT interrupt");
|
||||
Interrupt::wakeUp();
|
||||
(*Interrupt::wdtCallback) ();
|
||||
wdtTimeLeft = wdtTime;
|
||||
}
|
||||
|
||||
setupWatchDogInterrupt();
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +107,7 @@ ISR(WDT_vect)
|
|||
Interrupt::handleWatchDogInterrupt();
|
||||
}
|
||||
|
||||
void Interrupt::setupWatchDogInterrupt(unsigned int milliseconds)
|
||||
void Interrupt::setupWatchDogInterrupt(uint16_t milliseconds)
|
||||
{
|
||||
wdtTimeLeft = wdtTime = milliseconds;
|
||||
setupWatchDogInterrupt();
|
||||
|
|
@ -112,6 +115,11 @@ void Interrupt::setupWatchDogInterrupt(unsigned int milliseconds)
|
|||
|
||||
void Interrupt::setupWatchDogInterrupt()
|
||||
{
|
||||
if (wdtTime <= 0){
|
||||
wdt_disable();
|
||||
return;
|
||||
}
|
||||
|
||||
noInterrupts();
|
||||
|
||||
unsigned short duration;
|
||||
|
|
@ -147,7 +155,6 @@ void Interrupt::setupWatchDogInterrupt()
|
|||
wdtTimeLeft -= 16;
|
||||
duration = 0;
|
||||
}
|
||||
//DEBUGF("WDT t -= %u", wdtTimeLeft);
|
||||
|
||||
wdt_reset();
|
||||
MCUSR &= ~(1 << WDRF); // reset status flag
|
||||
|
|
@ -177,8 +184,6 @@ void Interrupt::setupWatchDogInterrupt()
|
|||
WDTCSR = (1 << WDIE) | duration;
|
||||
//WDTCSR = (1 << WDIE) | (1 << WDP3) | (1 << WDP0);
|
||||
|
||||
//wdt_disable();
|
||||
|
||||
interrupts();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ void SensorDHT::setup()
|
|||
{
|
||||
// set up the pins!
|
||||
pinMode(_pin, INPUT_PULLUP);
|
||||
#ifdef __AVR
|
||||
_bit = digitalPinToBitMask(_pin);
|
||||
_port = digitalPinToPort(_pin);
|
||||
#endif
|
||||
_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for
|
||||
// reading pulses from DHT sensor.
|
||||
}
|
||||
|
|
@ -86,10 +90,12 @@ void SensorDHT::read(TemperatureData& retData)
|
|||
// for ~80 microseconds again.
|
||||
if (expectPulse(LOW) == 0) {
|
||||
DEBUG("DHT:Timeout waiting for start signal low pulse.");
|
||||
interrupts();
|
||||
return;
|
||||
}
|
||||
if (expectPulse(HIGH) == 0) {
|
||||
DEBUG("DHT:Timeout waiting for start signal high pulse.");
|
||||
interrupts();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue