forked from vividnightmare/libg15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
libg15.h
221 lines (182 loc) · 5.2 KB
/
libg15.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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/*
This file is part of g15tools.
g15tools 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 2 of the License, or
(at your option) any later version.
g15tools 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 g15lcd; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
(c) 2006 - 2007 The G15tools Project - g15tools.sf.net
$Revision: 324 $ - $Date: 2011-02-24 00:13:57 +0000 (Thu, 24 Feb 2011) $ $Author: SteelSide $
*/
#ifndef _LIBG15_H_
#define _LIBG15_H_
#ifdef __cplusplus
extern "C"
{
#endif
#define G15_LCD 1
#define G15_KEYS 2
#define G15_DEVICE_IS_SHARED 4
#define G15_DEVICE_5BYTE_RETURN 8
#define G15_DEVICE_G13 16
#define G15_DEVICE_G510 32
#define G15_DEVICE_G110 64
#define G15_DEVICE_COLOUR 128
#define G15_STORAGE 256
#define G15_KEY_READ_LENGTH 9
#define G13_KEY_READ_LENGTH 8
#define G510_STANDARD_KEYBOARD_INTERFACE 0x0
typedef struct libg15_devices_t libg15_devices_t;
struct libg15_devices_t {
const char *name; // name - can be anything, only used for informational purposes
unsigned int vendorid;
unsigned int productid;
unsigned int caps; // capability bitfield - G15_LCD|G15_KEYS;
};
#define DEVICE(name, vendorid, productid, caps) { \
name, \
vendorid, \
productid, \
caps \
}
/* allow for api changes */
#define LIBG15_VERSION 1201
enum
{
G15_LOG_INFO = 1,
G15_LOG_WARN
};
enum
{
G15_NO_ERROR = 0,
G15_ERROR_OPENING_USB_DEVICE,
G15_ERROR_WRITING_PIXMAP,
G15_ERROR_TIMEOUT,
G15_ERROR_READING_USB_DEVICE,
G15_ERROR_TRY_AGAIN,
G15_ERROR_WRITING_BUFFER,
G15_ERROR_UNSUPPORTED,
G15_ERROR_WRITING_PROFILE,
};
enum
{
G15_LCD_OFFSET = 32,
G15_LCD_HEIGHT = 43,
G15_LCD_WIDTH = 160
};
enum
{
G15_BUFFER_LEN = 0x03e0
};
enum
{
G15_PROFILE_LEN = 992
};
enum
{
G15_LED_M1=1<<0,
G15_LED_M2=1<<1,
G15_LED_M3=1<<2,
G15_LED_MR=1<<3
};
enum
{
G15_CONTRAST_LOW=0,
G15_CONTRAST_MEDIUM,
G15_CONTRAST_HIGH
};
enum
{
G15_BRIGHTNESS_DARK=0,
G15_BRIGHTNESS_MEDIUM,
G15_BRIGHTNESS_BRIGHT
};
enum
{
G15_KEY_G1 = 1<<0,
G15_KEY_G2 = 1<<1,
G15_KEY_G3 = 1<<2,
G15_KEY_G4 = 1<<3,
G15_KEY_G5 = 1<<4,
G15_KEY_G6 = 1<<5,
G15_KEY_G7 = 1<<6,
G15_KEY_G8 = 1<<7,
G15_KEY_G9 = 1<<8,
G15_KEY_G10 = 1<<9,
G15_KEY_G11 = 1<<10,
G15_KEY_G12 = 1<<11,
G15_KEY_G13 = 1<<12,
G15_KEY_G14 = 1<<13,
G15_KEY_G15 = 1<<14,
G15_KEY_G16 = 1<<15,
G15_KEY_G17 = 1<<16,
G15_KEY_G18 = 1<<17,
G15_KEY_M1 = 1<<18,
G15_KEY_M2 = 1<<19,
G15_KEY_M3 = 1<<20,
G15_KEY_MR = 1<<21,
G15_KEY_L1 = 1<<22,
G15_KEY_L2 = 1<<23,
G15_KEY_L3 = 1<<24,
G15_KEY_L4 = 1<<25,
G15_KEY_L5 = 1<<26,
G15_KEY_LIGHT = 1<<27,
G15_EXTENDED_KEY = 1<<28,
/* G13 extended keys */
G15_KEY_G19 = 1<<0,
G15_KEY_G20 = 1<<1,
G15_KEY_G21 = 1<<2,
G15_KEY_G22 = 1<<3,
G15_KEY_JOYBL = 1<<4,
G15_KEY_JOYBD = 1<<5,
G15_KEY_JOYBS = 1<<6,
G15_JOY = 1<<7,
/* G510 multimedia keys */
G15_KEY_PLAY = 1 << 0,
G15_KEY_STOP= 1 << 1,
G15_KEY_PREV = 1 << 2,
G15_KEY_NEXT = 1 << 3,
G15_KEY_MUTE = 1 << 4,
G15_KEY_RAISE_VOLUME = 1 << 5,
G15_KEY_LOWER_VOLUME = 1 << 6,
G15_KEY_MUTE_OUTPUT = 1 << 7,
G15_KEY_MUTE_INPUT = 1 << 8,
};
/* this one return G15_NO_ERROR on success, something
* else otherwise (for instance G15_ERROR_OPENING_USB_DEVICE */
int initLibG15();
/* initialise with or without initialising libusb. use this if something else has already
used libusb and read devices / busses or if you want a particular device*/
int setupLibG15(unsigned int vendorId, unsigned int productId, unsigned int init_usb);
/* re-initialise a previously unplugged keyboard ie ENODEV was returned at some point */
int re_initLibG15();
int exitLibG15();
/* enable or disable debugging */
void libg15Debug(int option);
int writePixmapToLCD(unsigned char const *data);
int getJoystickX();
int getJoystickY();
int getBacklightState();
int setLCDContrast(unsigned int level);
int setLEDs(unsigned int leds);
int setLCDBrightness(unsigned int level);
int setKBBrightness(unsigned int level);
int setG510LEDColor(unsigned char r, unsigned char g, unsigned char b);
/* Please be warned
* the g15 sends two different usb msgs for each key press
* but only one of these two is used here. Since we do not want to wait
* longer than timeout we will return on any msg recieved. in the good
* case you will get G15_NO_ERROR and ORd keys in pressed_keys
* in the bad case you will get G15_ERROR_TRY_AGAIN -> try again
*/
int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout);
#ifdef __cplusplus
}
#endif
#endif