forked from jromang/dgtpi
-
Notifications
You must be signed in to change notification settings - Fork 6
/
dgtpicom.h
135 lines (117 loc) · 4.05 KB
/
dgtpicom.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
132
133
134
135
/* 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/>.
*/
/* configuration values
*/
#define DGTPICOM_KEY_DELAY 800000
#define DGTPICOM_KEY_REPEAT 400000
/* Return codes for all funcitons are at the bottom of this doccument.
* All functions try three times, the error is the reason why the third
* try failed.
*/
/* Get direct access to BCM2708/9 chip.
* Run this first and only once (or again after a dgtpicom_stop())
*/
int dgtpicom_init(void);
/* Configure the dgt3000: turn it on, set central control and set
* mode 25. If neccesary reset the I2C hardware.
* Run this before any command and if commands fail
*/
int dgtpicom_configure();
/* Send set and run command to the dgt3000.
* lr/rr = left/right run mode, 0=stop, 1=count down, 2=count up
* lh/rh = left/right hours
* lm/rm = left/right minutes
* ls/rs = left/right seconds
*/
int dgtpicom_set_and_run(char lr, char lh, char lm, char ls,
char rr, char rh, char rm, char rs);
/* Send set and run command to the dgt3000 with current clock values.
* lr/rr = left/right run mode, 0=stop, 1=count down, 2=count up
*/
int dgtpicom_run(char lr, char rr);
/* Set a text message on the dgt3000.
* text = message to display
* beep = beep length (/62.5ms) max 48 (3s)
* ld/rd = left/right icons and dots:
* 1=flag,
* 2=white king,
* 4=black king,
* 8=colon,
* 16=dot,
* 32=extra dot (left only)
*/
int dgtpicom_set_text(char text[], char beep, char ld, char rd);
/* End a text message on the dgt3000 and return to clock mode.
*/
int dgtpicom_end_text();
/* Put the last received time message in time[].
* time[] = 6 byte time descriptor
*/
void dgtpicom_get_time(char time[]);
/* Get a button message from the buffer and put it in buttons and time
* returns number of messages in the buffer or an error code if a
* receive error has occurd since you last check.
* buttons = buttons pressed:
* binary:
* 0x01 < back
* 0x02 - minus
* 0x04 p play/pause
* 0x08 + plus
* 0x10 > forward
* special:
* 0x20 o off
* 0xa0 o on
* 0x40 \ Lever changed, right side down
* 0xc0 / Lever changed, left side down
* time = time the buttons were pressed in 100ms
*/
int dgtpicom_get_button_message(char *buttons, char *time);
/* Return current button state.
* returns:
* binary:
* 0x01 < back
* 0x02 - minus
* 0x04 p play/pause
* 0x08 + plus
* 0x10 > forward
* 0x20 o on/off button
* 0x40 \ Lever position, (right side down = 0x40)
*/
int dgtpicom_get_button_state();
/* Turn off the dgt3000.
* returnMode = timing method the clock will start in when turned on
*/
int dgtpicom_off(char returnMode);
/* Disable the I2C hardware.
* run this before you end the program
*/
void dgtpicom_stop();
/* return codes:
* -10= no direct access to memory, run as root
* -9 = receive failed, software buffer overrun, should not happen
* -8 = receive failed, packet to small, hardware buffer overrun
* -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!
*/