-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathSDI12.h
131 lines (121 loc) · 3.9 KB
/
SDI12.h
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
/*
||
|| @file SDI12.h
|| @version 3.0.1
|| @author Colin Duffy
|| @contact https://github.com/duff2013/SDI12_T3
||
|| @description
|| | SDI12 library for Teensy 3.0/3.1.
|| #
||
|| @license
|| | Copyright (c) 2015 Colin Duffy
|| | This library is free software; you can redistribute it and/or
|| | modify it under the terms of the GNU Lesser General Public
|| | License as published by the Free Software Foundation; version
|| | 2.1 of the License.
|| |
|| | This library is distributed in the hope that it will be useful,
|| | but WITHOUT ANY WARRANTY; without even the implied warranty of
|| | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|| | Lesser General Public License for more details.
|| |
|| | You should have received a copy of the GNU Lesser General Public
|| | License along with this library; if not, write to the Free Software
|| | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|| #
||
*/
#ifndef SDI12_h
#define SDI12_h
#ifdef __cplusplus
#include "Arduino.h"
class SDI12;
//-------------------------------------------UART----------------------------------------------
class UART {
public:
UART( void ) :
REG( nullptr ),
TX_PIN( nullptr ),
RX_PIN( nullptr ),
SET( nullptr ),
CLEAR( nullptr ),
STATUS_REG( nullptr ),
PIN_NUM_RX( 0 ),
PIN_NUM_TX( 0 )
{
}
private:
int peek ( void );
int read ( void );
int available ( void );
int end ( void );
void clear ( void );
void flush ( void );
friend class SDI12;
KINETISK_UART_t *REG;
volatile uint32_t *TX_PIN;
volatile uint32_t *RX_PIN;
volatile uint8_t SCGC4;
volatile uint32_t *SET;
volatile uint32_t *CLEAR;
volatile uint8_t *STATUS_REG;
volatile uint32_t BITMASK;
uint8_t PIN_NUM_RX;
uint8_t PIN_NUM_TX;
};
//------------------------------------------SDI12-----------------------------------------------
class SDI12 : public UART {
private:
typedef struct {
Stream *uart;
uint8_t address;
bool crc;
} sensor_block_t;
public:
SDI12( Stream *port, const uint8_t address, bool crc = false ) {
sensor.uart = port;
sensor.address = address;
sensor.crc = crc;
init( );
allocateVector( );
}
SDI12( Stream *port ) {
sensor.uart = port;
init( );
allocateVector( );
}
SDI12 & operator = ( const SDI12 &rhs ) {
if ( this != &rhs ) {
sensor.uart = rhs.sensor.uart;
sensor.address = rhs.sensor.address;
sensor.crc = rhs.sensor.crc;
}
return *this;
};
~SDI12 ( void ) { releaseVector( ); }
int isActive ( int address = -1 );
int identification ( volatile void *src );
int queryAddress ( void );
int changeAddress ( const uint8_t new_address );
int verification ( volatile void *src );
int measurement ( int num = -1 ) { uint8_t src[10]; return measurement( src, num ); }
int measurement ( volatile void *src, int num = -1 );
int continuous ( volatile void *src, int num = -1 );
int returnMeasurement ( volatile void *src, int num = -1 );
int concurrent ( volatile void *src, int num = -1 );
int transparent ( const void *command, volatile void *src );
private:
void init ( void );
void allocateVector ( void );
void releaseVector ( void );
void conncurrent_handler( void );
void wake_io ( void );
int send_command ( const void *cmd, uint8_t count, uint8_t type );
sensor_block_t sensor;
volatile uint8_t retry;
};
//-----------------------------------------------------------------------------------------------
#endif// end __cplusplus
#endif