Oregon_TM.h
5.7 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <Arduino.h>
#ifndef Oregon_TM_h
#define Oregon_TM_h
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// This Arduino code is for receive and transmit data using Oregon Scientific RF protocol version 2.1 and 3.0.
//
// Last updated: 14 October 2019
//
// The folowed sensors data format are supported.
//
// Receive and transmit:
// THGN132N (THGR122N, THGN123N),
// RTGN318,
// THGR810.
// Receive only:
// THN132N,
// WGR800,
// UVN800.
//
// Aslo supported self-developed sensors. Please contact author for additional infromation.
//
// This file is part of the Arduino OREGON_NR library.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// The MIT License (MIT)
//
// Copyright (c) 2019 Sergey Zawislak
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Oregon Scientific v2.1 v3.0
//
// 14 2019
//
//
//
// :
// THGN132N (THGR122N, THGN123N),
// RTGN318,
// THGR810.
// :
// THN132N,
// WGR800,
// UVN800.
//
// ( )
//
// - OREGON_NR
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2019
//
// ,
// ( ), ,
// , , , , , ,
// / , , , :
//
// .
//
// ܻ, - , ,
// , , .
// - , , , , ,
// - .
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define TR_TIME 488
#define TWOTR_TIME 976
#define PULSE_SHORTEN_2 80
#define PULSE_SHORTEN_3 120
#define THGN132 0x1D20
#define THGR810 0xF824
#define RTGN318 0xDCC3
#define THP 0x5500
static byte TX_PIN = 4;
static const int buffersize = 10;
class Oregon_TM
{
public:
byte SendBuffer[buffersize];
byte protocol = 2;
word sens_type = 0x0000;
int timing_corrector2 = 4;
int timing_corrector3 = 2;
Oregon_TM(byte);
Oregon_TM();
void setType(word);
void setChannel( byte);
void setId(byte);
void setBatteryFlag(bool);
void setStartCount(byte);
void setTemperature(float);
void setHumidity(byte);
void setComfort(float, byte);
bool transmit();
void SendPacket();
void setErrorTHP();
void setPressureTHP(float);
void setTemperatureTHP(float);
void setBatteryTHP(word);
void setChannelTHP(byte);
void setHumidityTHP(float);
private:
void sendZero(void);
void sendOne(void);
void sendMSB(const byte);
void sendLSB(const byte);
void sendData();
void sendOregon();
void sendPreamble();
void calculateAndSetChecksum132();
void calculateAndSetChecksum318();
void calculateAndSetChecksum810();
void calculateAndSetChecksumTHP();
unsigned long time_marker = 0;
unsigned long time_marker_send = 0;
unsigned long send_time = 0;
bool prevbit = 1;
bool prevstate = 1;
};
#endif