forked from ms-iot/samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainPage.xaml.h
More file actions
85 lines (67 loc) · 2.17 KB
/
MainPage.xaml.h
File metadata and controls
85 lines (67 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright (c) Microsoft. All rights reserved.
//
// MainPage.xaml.h
// Declaration of the MainPage class.
//
#pragma once
#include "MainPage.g.h"
namespace GpioOneWire
{
struct Dht11Reading {
bool IsValid ( ) const
{
unsigned long long value = this->bits.to_ullong();
unsigned int checksum =
((value >> 32) & 0xff) +
((value >> 24) & 0xff) +
((value >> 16) & 0xff) +
((value >> 8) & 0xff);
return (checksum & 0xff) == (value & 0xff);
}
double Humidity ( ) const
{
unsigned long long value = this->bits.to_ullong();
return (((value >> 24) & 0xff00) + ((value >> 24) & 0xff)) / 10.0;
}
double Temperature ( ) const
{
unsigned long long value = this->bits.to_ullong();
double temp = (((value >> 8) & 0x7f00) + ((value >> 8) & 0xff)) / 10.0;
if ((value >> 16) & 0x80) temp = -temp;
return temp;
}
std::bitset<40> bits;
};
class Dht11
{
enum { SAMPLE_HOLD_LOW_MILLIS = 18 };
public:
Dht11 ( ) :
pin(nullptr),
inputDriveMode(Windows::Devices::Gpio::GpioPinDriveMode::Input)
{ }
void Init (Windows::Devices::Gpio::GpioPin^ Pin);
HRESULT Sample (_Out_ Dht11Reading& Reading);
bool PullResistorRequired ( ) const
{
return inputDriveMode != Windows::Devices::Gpio::GpioPinDriveMode::InputPullUp;
}
private:
Windows::Devices::Gpio::GpioPin^ pin;
Windows::Devices::Gpio::GpioPinDriveMode inputDriveMode;
};
/// <summary>
/// The main page of the application - used to show samples from the DHT11.
/// </summary>
public ref class MainPage sealed
{
enum { DHT11_PIN_NUMBER = 4 };
public:
MainPage();
private:
void Page_Loaded(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e);
void timerElapsed (Windows::System::Threading::ThreadPoolTimer^ Timer);
Dht11 dht11;
Windows::System::Threading::ThreadPoolTimer^ timer;
};
}