summaryrefslogtreecommitdiff
path: root/src/sensors/huey/huey-enum.h
blob: 73175584d83394bb288d1173ac008652d285d662 (plain)
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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
 *
 * Copyright (C) 2013 Richard Hughes <richard@hughsie.com>
 *
 * Licensed under the GNU General Public License Version 2
 *
 * 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 2 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, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#ifndef __HUEY_ENUM_H
#define __HUEY_ENUM_H

#include <glib-object.h>

G_BEGIN_DECLS

/* external hueys */
#define CD_SENSOR_HUEY_VENDOR_ID		0x0971
#define CD_SENSOR_HUEY_PRODUCT_ID		0x2005

/* integrated and newer devices */
#define CD_SENSOR_HUEY_VENDOR_ID2		0x0765
#define CD_SENSOR_HUEY_PRODUCT_ID2		0x5001

/* Return values from the commands */
#define HUEY_RC_SUCCESS				0x00
#define HUEY_RC_LOCKED				0xc0
#define HUEY_RC_UNKNOWN_5A			0x5a /* seen in profiling */
#define HUEY_RC_ERROR				0x80
#define HUEY_RC_UNKNOWN_81			0x81 /* seen once in init */
#define HUEY_RC_RETRY				0x90

/*
 * Get the currect status of the device
 *
 *  input:   00 00 00 00 3f 00 00 00
 * returns: 00 00 43 69 72 30 30 31  (or)
 *     "Cir001" --^^^^^^^^^^^^^^^^^ (Pantone Huey)
 *          c0 00 xx xx xx xx xx xx
 *     "huL002" --^^^^^^^^^^^^^^^^^ (Lenovo Huey)
 *          c0 00 4c 6f 63 6b 65 64
 *     "locked" --^^^^^^^^^^^^^^^^^
 */
#define HUEY_CMD_GET_STATUS			0x00

/*
 * Read the green sample data
 *
 * input:   02 xx xx xx xx xx xx xx
 * returns: 00 02 00 00 0a 00 00 00 (or)
 *          00 02 00 0e c6 80 00 00
 *            data --^^^^^ ^-- only ever 00 or 80
 *                    |
 *                    \-- for RGB(00,00,00) is 09 f2
 *                            RGB(ff,ff,ff) is 00 00
 *                            RGB(ff,00,00) is 02 a5
 *                            RGB(00,ff,00) is 00 f1
 *                            RGB(00,00,ff) is 08 56
 *
 * This doesn't do a sensor read, it seems to be a simple accessor.
 * HUEY_CMD_SENSOR_MEASURE_RGB has to be used before this one.
 */
#define HUEY_CMD_READ_GREEN			0x02

/*
 * Read the blue sample data
 *
 * input:   03 xx xx xx xx xx xx xx
 * returns: 00 03 00 0f 18 00 00 00
 *            data --^^^^^ ^-- only ever 00 or 80
 *                    |
 *                    \-- for RGB(00,00,00) is 09 64
 *                            RGB(ff,ff,ff) is 08 80
 *                            RGB(ff,00,00) is 03 22
 *                            RGB(00,ff,00) is 00 58
 *                            RGB(00,00,ff) is 00 59
 *
 * This doesn't do a sensor read, it seems to be a simple accessor.
 * HUEY_CMD_SENSOR_MEASURE_RGB has to be used before this one.
 */
#define HUEY_CMD_READ_BLUE			0x03

/*
 * Sets a 32 bit integration time register.
 *
 * input:   05 ?? 11 12 13 14 xx xx
 * returns: 00 05 00 00 00 00 00 00
 *              ^--- always the same no matter the input
 *
 * This is not normally used during profiling
 */
#define HUEY_CMD_SET_INTEGRATION_TIME		0x05

/*
 * Get the value of the 32 bit integration time register.
 *
 * input:   06 xx xx xx xx xx xx xx
 * returns: 00 06 11 12 13 14 00 00
 *    4 bytes ----^^^^^^^^^^^ (from HUEY_CMD_SET_INTEGRATION_TIME)
 *
 * The default value at plug-in is 00 0f 42 40, although during
 * profiling it is set to 00 00 6f 00 and then 00 00 61 00.
 */
#define HUEY_CMD_GET_INTEGRATION_TIME		0x06

/*
 * Writes a register value.
 *
 * (sent at startup  after the unlock)
 * input:   07 0b ff xx xx xx xx xx
 *                ^^-- data value
 *             ^^-- register address
 * returns: 00 xx xx xx xx xx xx xx
 *
 * You can only write one byte at a time.
 */
#define HUEY_CMD_REGISTER_WRITE			0x07

/*
 * Reads a register value.
 *
 * (sent at startup  after the unlock)
 * input:   08 0b xx xx xx xx xx xx
 *             ^^-- register address
 * returns: 00 08 0b b8 00 00 00 00
 *      address --^^ ^^-- value
 *
 * You can only read one byte at a time.
 */
#define HUEY_CMD_REGISTER_READ			0x08

/*
 * Unlock a locked sensor.
 *
 * input:   0e 47 72 4d 62 6b 65 64 (Pantone Huey)
 *  "GrMb"--^^^^^^^^^^^
 *          0e 47 72 4d 62 6b 65 64 (Lenovo Huey)
 *  "huyL"--^^^^^^^^^^^
 * returns: 00 0e 00 00 00 00 00 00
 *
 * Only GrMbk or huyL is needed to unlock, the rest is just junk data.
 * We still don't know how to 'lock' a device, it just kinda happens.
 */
#define HUEY_CMD_UNLOCK				0x0e

/*
 * Unknown command
 *
 * returns: all NULL all of the time */
#define HUEY_CMD_UNKNOWN_0F			0x0f

/*
 * Unknown command
 *
 * Something to do with sampling */
#define HUEY_CMD_UNKNOWN_10			0x10

/*
 * Unknown command
 *
 * Something to do with sampling (that needs a retry with code 5a)
 */
#define HUEY_CMD_UNKNOWN_11			0x11

/*
 * Unknown command
 *
 * something to do with sampling
 */
#define HUEY_CMD_UNKNOWN_12			0x12

/*
 * Measures RGB value, and return the red value (only used in CRT mode).
 *
 * Seems to have to retry, every single time.
 *
 *                   Gain?
 *              _______|_______
 *             /---\ /---\ /---\
 * input:   13 02 41 00 54 00 49 00
 * returns: 00 13 00 00 01 99 02 00
 *                   ^^^^^ - would match HUEY_CMD_SENSOR_MEASURE_RGB
 *
 * The gain seems not to change for different measurements with different
 * colors. This seems to be a less precise profile too.
 */
#define HUEY_CMD_SENSOR_MEASURE_RGB_CRT		0x13

/*
 * Unknown command
 *
 * returns: seems to be sent, but not requested
 */
#define HUEY_CMD_UNKNOWN_15			0x15

/*
 * Sample a color and return the red component
 *
 * input:   16 00 01 00 01 00 01 00
 * returns: 00 16 00 00 00 00 00 00
 *
 * or:
 *             ,,-,,-,,-,,-,,-,,-- 'gain control'
 *             || || || || || ||
 * input:   16 00 35 00 48 00 1d 03
 * returns: 00 16 00 0b d0 00 00 00
 *            data --^^^^^ ^^-- only ever 00 or 80
 *
 * This is used when profiling, and all commands are followed by
 * HUEY_CMD_READ_GREEN and HUEY_COMMAND_READ_BLUE.
 *
 * The returned values are some kind of 16 bit register count that
 * indicate how much light fell on a sensor. If the sensors are
 * converting light to pulses, then the 'gain' control tells the sensor
 * how long to read. It's therefore quicker to read white than black.
 *
 * Given there exists only GREEN and BLUE accessors, and that RED comes
 * first in a RGB sequence, I think it's safe to assume that this command
 * does the measurement, and the others just return cached data.
 *
 * argyll does (for #ff0000)
 *
 * -> 16 00 01 00 01 00 01 00
 * <-       00 00 0b 00 00 00
 * -> 02 xx xx xx xx xx xx xx
 * <-       00 00 12 00 00 00
 * -> 03 xx xx xx xx xx xx xx
 * <-       00 03 41 00 00 00
 *
 * then does:
 *
 * -> 16 01 63 00 d9 00 04 00
 * <-       00 0f ce 80 00 00
 * -> 02 xx xx xx xx xx xx xx
 * <-       00 0e d0 80 00 00
 * -> 03 xx xx xx xx xx xx xx
 * <-       00 0d 3c 00 00 00
 *
 * then returns XYZ=87.239169 45.548708 1.952249
 */
#define HUEY_CMD_SENSOR_MEASURE_RGB		0x16

/*
 * Unknown command (some sort of poll?)
 *
 * input:   21 09 00 02 00 00 08 00 (or)
 * returns: [never seems to return a value]
 *
 * Only when profiling, and over and over.
 */
#define HUEY_CMD_UNKNOWN_21			0x21

/*
 * Get the level of ambient light from the sensor
 *
 *                 ,,--- The output-type, where 00 is LCD and 02 is CRT
 *  input:   17 03 00 xx xx xx xx xx
 * returns: 90 17 03 00 00 00 00 00  then on second read:
 * 	    00 17 03 00 00 62 57 00 in light (or)
 * 	    00 17 03 00 00 00 08 00 in dark
 * 	no idea	--^^       ^---^ = 16bits data
 */
#define HUEY_CMD_GET_AMBIENT			0x17

/*
 * Set the LEDs on the sensor
 *
 * input:   18 00 f0 xx xx xx xx xx
 * returns: 00 18 f0 00 00 00 00 00
 *   led mask ----^^
 */
#define HUEY_CMD_SET_LEDS			0x18

/*
 * Unknown command
 *
 * returns: all NULL for NULL input: times out for f1 f2 f3 f4 f5 f6 f7 f8 */
#define HUEY_CMD_SENSOR_MEASURE_RGB_ALT		0x19

/*
 * Register map:
 *     x0  x1  x2  x3  x4  x5  x6  x7  x8  x9  xA  xB  xC  xD  xE  xF
 * 0x [serial-number.][matrix-lcd....................................|
 * 1x ...............................................................|
 * 2x .......]                                                       |
 * 3x         [calib-lcd-time][matrix-crt............................|
 * 4x ...............................................................|
 * 5x .......................................][calib-crt-time]       |
 * 6x                             [calib_vector......................|
 * 7x ...........]                            [unlock-string.....]   |
 * 8x                                                                |
 * 9x                 [calib_value...]                               |
 */
#define HUEY_EEPROM_ADDR_SERIAL				0x00 /* 4 bytes */
#define HUEY_EEPROM_ADDR_CALIBRATION_DATA_LCD		0x04 /* 36 bytes */
#define HUEY_EEPROM_ADDR_CALIBRATION_TIME_LCD		0x32 /* 4 bytes */
#define HUEY_EEPROM_ADDR_CALIBRATION_DATA_CRT		0x36 /* 36 bytes */
#define HUEY_EEPROM_ADDR_CALIBRATION_TIME_CRT		0x5a /* 4 bytes */
#define HUEY_EEPROM_ADDR_DARK_OFFSET			0x67 /* 12 bytes */
#define HUEY_EEPROM_ADDR_UNLOCK				0x7a /* 5 bytes */
#define HUEY_EEPROM_ADDR_AMBIENT_CALIB_VALUE		0x94 /* 4 bytes */

const gchar	*huey_rc_to_string		(guchar	 value);
const gchar	*huey_cmd_code_to_string	(guchar	 value);

G_END_DECLS

#endif /* __HUEY_ENUM_H */