1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*-
2  *
3  * Copyright (C) 2012-2013 Richard Hughes <richard@hughsie.com>
4  *
5  * Licensed under the GNU General Public License Version 2
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 
22 #if !defined (__COLORHUG_H_INSIDE__) && !defined (CH_COMPILATION)
23 #error "Only <colorhug.h> can be included directly."
24 #endif
25 
26 #ifndef __CH_DEVICE_QUEUE_H
27 #define __CH_DEVICE_QUEUE_H
28 
29 #include <glib-object.h>
30 #include <gusb.h>
31 #include <colord-private.h>
32 
33 #include "ch-common.h"
34 #include "ch-hash.h"
35 
36 G_BEGIN_DECLS
37 
38 #define CH_TYPE_DEVICE_QUEUE (ch_device_queue_get_type ())
39 G_DECLARE_DERIVABLE_TYPE (ChDeviceQueue, ch_device_queue, CH, DEVICE_QUEUE, GObject)
40 
41 struct _ChDeviceQueueClass
42 {
43 	GObjectClass		 parent_class;
44 
45 	/* signals */
46 	void		(* device_failed)	(ChDeviceQueue	*device_queue,
47 						 GUsbDevice	*device,
48 						 const gchar	*error_message);
49 	void		(* progress_changed)	(ChDeviceQueue	*device_queue,
50 						 guint		 percentage);
51 
52 	/* padding for future expansion */
53 	void (*_ch_reserved1) (void);
54 	void (*_ch_reserved2) (void);
55 	void (*_ch_reserved3) (void);
56 	void (*_ch_reserved4) (void);
57 	void (*_ch_reserved5) (void);
58 };
59 
60 /**
61  * ChDeviceQueueProcessFlags:
62  *
63  * CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE:
64  * 	Normal operation, where a single device command failure makes
65  *	the return value of the process %FALSE, but the queue contibues
66  *	to run for other devices.
67  *
68  * CH_DEVICE_QUEUE_PROCESS_FLAGS_CONTINUE_ERRORS:
69  * 	Continue to submit commands to a device that has failed a
70  *	command, for example where one command might not be supported
71  *	in the middle of a queue of commands.
72  *
73  * CH_DEVICE_QUEUE_PROCESS_FLAGS_NONFATAL_ERRORS:
74  * 	Do not consider a device error to be fatal, but instead emit
75  *	a signal and continue with the rest of the queue. If the flag
76  *	%CH_DEVICE_QUEUE_PROCESS_FLAGS_CONTINUE_ERRORS is not used then
77  *	other commands to the same device will not be submitted.
78  *
79  * Flags for controlling processing options
80  **/
81 typedef enum {
82 	CH_DEVICE_QUEUE_PROCESS_FLAGS_NONE		= 0,
83 	CH_DEVICE_QUEUE_PROCESS_FLAGS_CONTINUE_ERRORS	= 1 << 0,
84 	CH_DEVICE_QUEUE_PROCESS_FLAGS_NONFATAL_ERRORS	= 1 << 1
85 } ChDeviceQueueProcessFlags;
86 
87 ChDeviceQueue	*ch_device_queue_new		(void);
88 
89 void		 ch_device_queue_add		(ChDeviceQueue	*device_queue,
90 						 GUsbDevice	*device,
91 						 guint8		 cmd,
92 						 const guint8	*buffer_in,
93 						 gsize		 buffer_in_len,
94 						 guint8		*buffer_out,
95 						 gsize		 buffer_out_len);
96 
97 void		 ch_device_queue_process_async	(ChDeviceQueue	*device_queue,
98 						 ChDeviceQueueProcessFlags process_flags,
99 						 GCancellable	*cancellable,
100 						 GAsyncReadyCallback callback,
101 						 gpointer	 user_data);
102 gboolean	 ch_device_queue_process_finish	(ChDeviceQueue	*device_queue,
103 						 GAsyncResult	*res,
104 						 GError		**error)
105 						 G_GNUC_WARN_UNUSED_RESULT;
106 gboolean	 ch_device_queue_process	(ChDeviceQueue	*device_queue,
107 						 ChDeviceQueueProcessFlags process_flags,
108 						 GCancellable	*cancellable,
109 						 GError		**error)
110 						 G_GNUC_WARN_UNUSED_RESULT;
111 
112 /* command submitting functions */
113 void		 ch_device_queue_get_color_select	(ChDeviceQueue	*device_queue,
114 							 GUsbDevice	*device,
115 							 ChColorSelect	*color_select);
116 void		 ch_device_queue_get_hardware_version	(ChDeviceQueue	*device_queue,
117 							 GUsbDevice	*device,
118 							 guint8		*hw_version);
119 void		 ch_device_queue_set_color_select	(ChDeviceQueue	*device_queue,
120 							 GUsbDevice	*device,
121 							 ChColorSelect	 color_select);
122 void		 ch_device_queue_get_multiplier		(ChDeviceQueue	*device_queue,
123 							 GUsbDevice	*device,
124 							 ChFreqScale	*multiplier);
125 void		 ch_device_queue_set_multiplier		(ChDeviceQueue	*device_queue,
126 							 GUsbDevice	*device,
127 							 ChFreqScale	 multiplier);
128 void		 ch_device_queue_get_integral_time	(ChDeviceQueue	*device_queue,
129 							 GUsbDevice	*device,
130 							 guint16	*integral_time);
131 void		 ch_device_queue_set_integral_time	(ChDeviceQueue	*device_queue,
132 							 GUsbDevice	*device,
133 							 guint16	 integral_time);
134 void		 ch_device_queue_get_calibration_map	(ChDeviceQueue	*device_queue,
135 							 GUsbDevice	*device,
136 							 guint16	*calibration_map);
137 void		 ch_device_queue_set_calibration_map	(ChDeviceQueue	*device_queue,
138 							 GUsbDevice	*device,
139 							 const guint16	*calibration_map);
140 void		 ch_device_queue_get_firmware_ver	(ChDeviceQueue	*device_queue,
141 							 GUsbDevice	*device,
142 							 guint16	*major,
143 							 guint16	*minor,
144 							 guint16	*micro);
145 void		 ch_device_queue_get_calibration	(ChDeviceQueue	*device_queue,
146 							 GUsbDevice	*device,
147 							 guint16	 calibration_index,
148 							 CdMat3x3	*calibration,
149 							 guint8		*types,
150 							 gchar		*description);
151 void		 ch_device_queue_set_calibration	(ChDeviceQueue	*device_queue,
152 							 GUsbDevice	*device,
153 							 guint16	 calibration_index,
154 							 const CdMat3x3	*calibration,
155 							 guint8		 types,
156 							 const gchar	*description);
157 void		 ch_device_queue_clear_calibration	(ChDeviceQueue	*device_queue,
158 							 GUsbDevice	*device,
159 							 guint16	 calibration_index);
160 void		 ch_device_queue_get_pre_scale		(ChDeviceQueue	*device_queue,
161 							 GUsbDevice	*device,
162 							 gdouble	*pre_scale);
163 void		 ch_device_queue_set_pre_scale		(ChDeviceQueue	*device_queue,
164 							 GUsbDevice	*device,
165 							 gdouble	 pre_scale);
166 void		 ch_device_queue_get_post_scale		(ChDeviceQueue	*device_queue,
167 							 GUsbDevice	*device,
168 							 gdouble	*post_scale);
169 void		 ch_device_queue_set_post_scale		(ChDeviceQueue	*device_queue,
170 							 GUsbDevice	*device,
171 							 gdouble	 post_scale);
172 void		 ch_device_queue_get_serial_number	(ChDeviceQueue	*device_queue,
173 							 GUsbDevice	*device,
174 							 guint32	*serial_number);
175 void		 ch_device_queue_set_serial_number	(ChDeviceQueue	*device_queue,
176 							 GUsbDevice	*device,
177 							 guint32	 serial_number);
178 void		 ch_device_queue_get_leds		(ChDeviceQueue	*device_queue,
179 							 GUsbDevice	*device,
180 							 guint8		*leds);
181 void		 ch_device_queue_set_leds		(ChDeviceQueue	*device_queue,
182 							 GUsbDevice	*device,
183 							 guint8		 leds,
184 							 guint8		 repeat,
185 							 guint8		 on_time,
186 							 guint8		 off_time);
187 void		 ch_device_queue_get_pcb_errata		(ChDeviceQueue	*device_queue,
188 							 GUsbDevice	*device,
189 							 guint16	*pcb_errata);
190 void		 ch_device_queue_set_pcb_errata		(ChDeviceQueue	*device_queue,
191 							 GUsbDevice	*device,
192 							 guint16	 pcb_errata);
193 void		 ch_device_queue_get_remote_hash	(ChDeviceQueue	*device_queue,
194 							 GUsbDevice	*device,
195 							 ChSha1		*remote_hash);
196 void		 ch_device_queue_set_remote_hash	(ChDeviceQueue	*device_queue,
197 							 GUsbDevice	*device,
198 							 ChSha1		*remote_hash);
199 void		 ch_device_queue_get_dark_offsets	(ChDeviceQueue	*device_queue,
200 							 GUsbDevice	*device,
201 							 CdColorRGB	*value);
202 void		 ch_device_queue_set_dark_offsets	(ChDeviceQueue	*device_queue,
203 							 GUsbDevice	*device,
204 							 CdColorRGB	*value);
205 void		 ch_device_queue_write_eeprom		(ChDeviceQueue	*device_queue,
206 							 GUsbDevice	*device,
207 							 const gchar	*magic);
208 void		 ch_device_queue_take_reading_raw	(ChDeviceQueue	*device_queue,
209 							 GUsbDevice	*device,
210 							 guint32	*take_reading);
211 void		 ch_device_queue_take_readings		(ChDeviceQueue	*device_queue,
212 							 GUsbDevice	*device,
213 							 CdColorRGB	*value);
214 void		 ch_device_queue_take_readings_xyz	(ChDeviceQueue	*device_queue,
215 							 GUsbDevice	*device,
216 							 guint16	 calibration_index,
217 							 CdColorXYZ	*value);
218 void		 ch_device_queue_reset			(ChDeviceQueue	*device_queue,
219 							 GUsbDevice	*device);
220 void		 ch_device_queue_boot_flash		(ChDeviceQueue	*device_queue,
221 							 GUsbDevice	*device);
222 void		 ch_device_queue_self_test		(ChDeviceQueue	*device_queue,
223 							 GUsbDevice	*device);
224 void		 ch_device_queue_set_flash_success	(ChDeviceQueue	*device_queue,
225 							 GUsbDevice	*device,
226 							 guint8		 value);
227 void		 ch_device_queue_write_flash		(ChDeviceQueue	*device_queue,
228 							 GUsbDevice	*device,
229 							 guint16	 address,
230 							 const guint8	*data,
231 							 gsize		 len);
232 void		 ch_device_queue_read_flash		(ChDeviceQueue	*device_queue,
233 							 GUsbDevice	*device,
234 							 guint16	 address,
235 							 guint8		*data,
236 							 gsize		 len);
237 void		 ch_device_queue_verify_flash		(ChDeviceQueue	*device_queue,
238 							 GUsbDevice	*device,
239 							 guint16	 address,
240 							 const guint8	*data,
241 							 gsize		 len);
242 void		 ch_device_queue_erase_flash		(ChDeviceQueue	*device_queue,
243 							 GUsbDevice	*device,
244 							 guint16	 address,
245 							 gsize		 len);
246 void		 ch_device_queue_set_owner_name		(ChDeviceQueue	*device_queue,
247 							 GUsbDevice	*device,
248 							 const gchar	*name);
249 void		 ch_device_queue_get_owner_name		(ChDeviceQueue	*device_queue,
250 							 GUsbDevice	*device,
251 							 gchar		*name);
252 void		 ch_device_queue_set_owner_email	(ChDeviceQueue	*device_queue,
253 							 GUsbDevice	*device,
254 							 const gchar	*email);
255 void		 ch_device_queue_get_owner_email	(ChDeviceQueue	*device_queue,
256 							 GUsbDevice	*device,
257 							 gchar		*email);
258 void		 ch_device_queue_take_reading_array	(ChDeviceQueue	*device_queue,
259 							 GUsbDevice	*device,
260 							 guint8		*reading_array);
261 void		 ch_device_queue_get_measure_mode	(ChDeviceQueue	*device_queue,
262 							 GUsbDevice	*device,
263 							 ChMeasureMode	*measure_mode);
264 void		 ch_device_queue_set_measure_mode	(ChDeviceQueue	*device_queue,
265 							 GUsbDevice	*device,
266 							 ChMeasureMode	 measure_mode);
267 void		 ch_device_queue_write_sram		(ChDeviceQueue	*device_queue,
268 							 GUsbDevice	*device,
269 							 guint16	 address,
270 							 const guint8	*data,
271 							 gsize		 len);
272 void		 ch_device_queue_read_sram		(ChDeviceQueue	*device_queue,
273 							 GUsbDevice	*device,
274 							 guint16	 address,
275 							 guint8		*data,
276 							 gsize		 len);
277 void		 ch_device_queue_get_temperature	(ChDeviceQueue	*device_queue,
278 							 GUsbDevice	*device,
279 							 gdouble	*temperature);
280 void		 ch_device_queue_set_dac_value		(ChDeviceQueue	*device_queue,
281 							 GUsbDevice	*device,
282 							 gdouble	 dac_value);
283 void		 ch_device_queue_get_dac_value		(ChDeviceQueue	*device_queue,
284 							 GUsbDevice	*device,
285 							 gdouble	*dac_value);
286 void		 ch_device_queue_get_adc_vref_pos	(ChDeviceQueue	*device_queue,
287 							 GUsbDevice	*device,
288 							 gdouble	*vref);
289 void		 ch_device_queue_get_adc_vref_neg	(ChDeviceQueue	*device_queue,
290 							 GUsbDevice	*device,
291 							 gdouble	*vref);
292 void		 ch_device_queue_take_reading_spectral	(ChDeviceQueue	*device_queue,
293 							 GUsbDevice	*device,
294 							 guint16	*sram_addr);
295 void		 ch_device_queue_get_ccd_calibration	(ChDeviceQueue	*device_queue,
296 							 GUsbDevice	*device,
297 							 guint16	*indexes);
298 void		 ch_device_queue_set_ccd_calibration	(ChDeviceQueue	*device_queue,
299 							 GUsbDevice	*device,
300 							 const guint16	*indexes);
301 
302 /* command utility functions */
303 gboolean	 ch_device_queue_set_calibration_ccmx	(ChDeviceQueue	*device_queue,
304 							 GUsbDevice	*device,
305 							 guint16	 calibration_index,
306 							 CdIt8		*ccmx,
307 							 GError		**error)
308 							 G_GNUC_WARN_UNUSED_RESULT;
309 void		 ch_device_queue_write_firmware		(ChDeviceQueue	*device_queue,
310 							 GUsbDevice	*device,
311 							 const guint8	*data,
312 							 gsize		 len);
313 void		 ch_device_queue_verify_firmware	(ChDeviceQueue	*device_queue,
314 							 GUsbDevice	*device,
315 							 const guint8	*data,
316 							 gsize		 len);
317 void		 ch_device_queue_read_firmware		(ChDeviceQueue	*device_queue,
318 							 GUsbDevice	*device,
319 							 guint8		**data,
320 							 gsize		*len);
321 
322 G_END_DECLS
323 
324 #endif /* __CH_DEVICE_QUEUE_H */
325