Skip to content
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.

Update MainPage.xaml.h #505

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions GpioOneWire/MainPage.xaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@ namespace GpioOneWire

double Humidity ( ) const
{
unsigned long long value = this->bits.to_ullong();
return ((value >> 24) & 0xffff) * 0.1;
//Humidity Bytes are bits 1 & 2 out of 5
//Byte 1 is inteteger Humidity - bit 2 is decimal humidity
//Byte 2 is always 00000000 for a DHT 11 - the DHT22 does decimal points
unsigned long long value = this->bits.to_ullong();
double humidity = ((value >> 24) & 0xFF) * 0.1; //Decode the Decimal into Humidity
humidity = humidity + ((value >> 32) & 0xFF);// And add on the integer part of humidity
return humidity;
}

double Temperature ( ) const
{
unsigned long long value = this->bits.to_ullong();
double temp = ((value >> 8) & 0x7FFF) * 0.1;
if ((value >> 8) & 0x8000)
//Temp Bytes are bits 3 & 4 out of 5
//Byte 3 is inteteger temp - bit 4 is decimal temp
//Byte 4 is always 00000000 for a DHT 11 - the DHT22 does decimal points
unsigned long long value = this->bits.to_ullong();
double temp = ((value >> 8) & 0xFF) * 0.1; //Decode the Decimal into Temp
temp = temp + ((value >> 16) & 0x7F);// And add on the integer part of temp
if ((value >> 8) & 0x8000) // if the MSB of temp is 1 then its negative
temp = -temp;
return temp;
}
Expand Down