forked from lucasvdp/dgtpi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdgtpicom_dgt3000.h
More file actions
139 lines (119 loc) · 4.04 KB
/
Copy pathdgtpicom_dgt3000.h
File metadata and controls
139 lines (119 loc) · 4.04 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
/* functions to communicate to a DGT3000 using I2C
* version 0.8
*
* Copyright (C) 2015 DGT
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef DGTPICOM_DGT3000_H
#define DGTPICOM_DGT3000_H
#include <pthread.h>
#include <stdint.h>
/* return codes:
* -10= no direct access to memory, run as root
* -9 = receive failed, software buffer overrun, should not happen
* -8 = receive failed, Hardware buffer overrun, load to hi
* -7 = receive failed, CRC error, probably noise
* -6 = sending failed, hardware timeout, probably hardware fault
* -5 = sending failed, lines low, probably collision
* -4 = sending failed, clock stretch timeout, probably collision
* -3 = sending failed, no response, probably clock off
* -2 = no ack received
* -1 = negative ack received,
* 0 = succes!
*/
#define ERROR_MEM -10
#define ERROR_SWB_FULL -9
#define ERROR_HWB_FULL -8
#define ERROR_CRC -7
#define ERROR_TIMEOUT -6
#define ERROR_LINES -5
#define ERROR_CST -4
#define ERROR_SILENT -3
#define ERROR_NOACK -2
#define ERROR_NACK -1
#define ERROR_OK 0
// receive buffer length, longest package is program 51,
#define RECEIVE_BUFFER_LENGTH 256
//*** helping functions ***//
/* calculate checksum and put it in the last byte
*buffer = pointer to buffer */
char crc_calc(char *buffer);
/* print hex values
bytes = array of bytes
length is number of bytes to print */
void hexPrint(char bytes[], int length);
//*** Low level I2C communication ***//
/* send message using I2CMaster
message[] = the message to send
returns:
-7 = message not Acked, probably clock off
-3 = message not Acked, probably collision
-2 = I2C Error
0 = Succes */
int i2cSend(char message[], char ackAdr);
//*** dgt3000 commands ***//
/* send a wake command to the dgt3000
returns:
-3 = wake ack error
-1 = no hello message received
0 = succes */
int dgt3000Wake();
/* send set central controll command to dgt3000
returns:
-3 = sending failed, clock off (or collision)
-2 = sending failed, I2C error
-1 = no (positive)ack received, not in CC
0 = succes */
int dgt3000SetCC();
/* send set mode 25 to dgt3000
returns:
-3 = sending failed, clock off (or collision)
-2 = sending failed, I2C error
-1 = no (positive)ack received, not in CC
0 = succes */
int dgt3000Mode25();
/* send set and run command to dgt3000
*/
int dgt3000SetNRun(char srm[]);
/* send end display to dgt3000 to clear te display
returns:
-3 = sending failed, clock off (or collision)
-2 = sending failed, I2C error
-1 = no (positive)ack received, not in CC
0 = succes */
int dgt3000EndDisplay();
/* send set display command to dgt3000
dm = display message to send
returns:
-3 = sending failed, clock off (or collision)
-2 = sending failed, I2C error
-1 = no (positive)ack received, not in CC
0 = succes */
int dgt3000Display(char dm[]);
/* check for messages from dgt3000
returns:
0 = nothing is received
1 = something is received
2 = off button message is received */
void *dgt3000Receive(void *);
/* wait for an Ack message
adr = adress to listen for ack
cmd = command to ack
timeOut = time to wait for ack
returns:
-3 = no Ack
0 = Ack */
int dgt3000GetAck(char adr, char cmd, uint64_t timeOut);
#endif