1 /*
2  *    This file is part of g15tools.
3  *
4  *    g15tools is free software; you can redistribute it and/or modify
5  *    it under the terms of the GNU General Public License as published by
6  *    the Free Software Foundation; either version 2 of the License, or
7  *    (at your option) any later version.
8  *
9  *    g15tools is distributed in the hope that it will be useful,
10  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *    GNU General Public License for more details.
13  *
14  *    You should have received a copy of the GNU General Public License
15  *    along with g15lcd; if not, write to the Free Software
16  *    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  *
18  *    (c) 2006 - 2007 The G15tools Project - g15tools.sf.net
19  *
20  *    $Revision: 292 $ -  $Date: 2008-11-11 08:51:25 -0500 (Tue, 11 Nov 2008) $ $Author: aneurysm9 $
21  */
22 
23 #ifndef _LIBG15_H_
24 #define _LIBG15_H_
25 #ifdef __cplusplus
26 	extern "C"
27 {
28 #endif
29 
30 #define G15_LCD 1
31 #define G15_KEYS 2
32 #define G15_DEVICE_IS_SHARED 4
33 #define G15_DEVICE_5BYTE_RETURN 8
34 #define G15_DEVICE_G510 16
35 #define G15_KEY_READ_LENGTH 9
36 #define G510_STANDARD_KEYBOARD_INTERFACE 0x0
37 
38 	typedef struct libg15_devices_t libg15_devices_t;
39 	struct libg15_devices_t {
40 		const char *name; // name - can be anything, only used for informational purposes
41 		unsigned int vendorid;
42 		unsigned int productid;
43 		unsigned int caps; // capability bitfield - G15_LCD|G15_KEYS;
44 	};
45 
46 	#define DEVICE(name, vendorid, productid, caps) { \
47 	name, \
48 	vendorid, \
49 	productid, \
50 	caps \
51 	}
52 
53 	/* allow for api changes */
54 	#define LIBG15_VERSION 1201
55 
56 	enum {
57 		G15_LOG_INFO = 1,
58 		G15_LOG_WARN
59 	};
60 
61 	enum {
62 		G15_NO_ERROR = 0,
63 		G15_ERROR_OPENING_USB_DEVICE,
64 		G15_ERROR_WRITING_PIXMAP,
65 		G15_ERROR_TIMEOUT,
66 		G15_ERROR_READING_USB_DEVICE,
67 		G15_ERROR_TRY_AGAIN,
68 		G15_ERROR_WRITING_BUFFER,
69 		G15_ERROR_UNSUPPORTED
70 	};
71 
72 	enum {
73 		G15_LCD_OFFSET = 32,
74 		G15_LCD_HEIGHT = 43,
75 		G15_LCD_WIDTH = 160
76 	};
77 
78 	enum {
79 		G15_BUFFER_LEN = 0x03e0
80 	};
81 
82 	enum {
83 		G15_LED_M1=1<<0,
84 		G15_LED_M2=1<<1,
85 		G15_LED_M3=1<<2,
86 		G15_LED_MR=1<<3
87 	};
88 
89 	enum {
90 		G15_CONTRAST_LOW=0,
91 		G15_CONTRAST_MEDIUM,
92 		G15_CONTRAST_HIGH
93 	};
94 
95 	enum {
96 		G15_BRIGHTNESS_DARK=0,
97 		G15_BRIGHTNESS_MEDIUM,
98 		G15_BRIGHTNESS_BRIGHT
99 	};
100 
101 	enum {
102 		G15_KEY_G1  = 1<<0,
103 		G15_KEY_G2  = 1<<1,
104 		G15_KEY_G3  = 1<<2,
105 		G15_KEY_G4  = 1<<3,
106 		G15_KEY_G5  = 1<<4,
107 		G15_KEY_G6  = 1<<5,
108 		G15_KEY_G7  = 1<<6,
109 		G15_KEY_G8  = 1<<7,
110 		G15_KEY_G9  = 1<<8,
111 		G15_KEY_G10 = 1<<9,
112 		G15_KEY_G11 = 1<<10,
113 		G15_KEY_G12 = 1<<11,
114 		G15_KEY_G13 = 1<<12,
115 		G15_KEY_G14 = 1<<13,
116 		G15_KEY_G15 = 1<<14,
117 		G15_KEY_G16 = 1<<15,
118 		G15_KEY_G17 = 1<<16,
119 		G15_KEY_G18 = 1<<17,
120 		G15_KEY_G19 = 1<<28,
121 		G15_KEY_G20 = 1<<29,
122 		G15_KEY_G21 = 1<<30,
123 		G15_KEY_G22 = 1<<31,
124 		G15_KEY_M1  = 1<<18,
125 		G15_KEY_M2  = 1<<19,
126 		G15_KEY_M3  = 1<<20,
127 		G15_KEY_MR  = 1<<21,
128 		G15_KEY_L1  = 1<<22,
129 		G15_KEY_L2  = 1<<23,
130 		G15_KEY_L3  = 1<<24,
131 		G15_KEY_L4  = 1<<25,
132 		G15_KEY_L5  = 1<<26,
133 		G15_KEY_LIGHT = 1<<27
134 	//need to add them to the enum but not enough positions left
135 	// G15_KEY_JOYBL = 1<<32,
136 	// G15_KEY_JOYBD = 1<<33,
137 	// G15_KEY_JOYBS = 1<<34
138 
139 	};
140 	/* this one return G15_NO_ERROR on success, something
141 	 * else otherwise (for instance G15_ERROR_OPENING_USB_DEVICE */
142 	int initLibG15();
143 
144 	/* re-initialise a previously unplugged keyboard ie ENODEV was returned at some point */
145 	int re_initLibG15();
146 	int exitLibG15();
147 
148 	/* enable or disable debugging */
149 	void libg15Debug(int option);
150 	int writePixmapToLCD(unsigned char const *data);
151 	int setLCDContrast(unsigned int level);
152 	int setLEDs(unsigned int leds);
153 	int setLCDBrightness(unsigned int level);
154 	int setKBBrightness(unsigned int level);
155 
156 	/* Please be warned
157 	 * the g15 sends two different usb msgs for each key press
158 	 * but only one of these two is used here. Since we do not want to wait
159 	 * longer than timeout we will return on any msg recieved. in the good
160 	 * case you will get G15_NO_ERROR and ORd keys in pressed_keys
161 	 * in the bad case you will get G15_ERROR_TRY_AGAIN -> try again
162 	 */
163 	int getPressedKeys(unsigned int *pressed_keys, unsigned int timeout);
164 	int setG510LEDColor(unsigned char r, unsigned char g, unsigned char b);
165 
166 	#ifdef __cplusplus
167 }
168 #endif
169 
170 #endif
171