updated on Thu Jan 12 04:00:44 UTC 2012
[aur-mirror.git] / scanbuttond-cvs / scanbuttond_gt68xxPlustekBackend.patch
blob5c25a714d97737dc181cd1fe320f6e2e767d4c86
1 diff -ruN scanbuttond_cvs20090722/backends/gt68xx_plustek.c scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/gt68xx_plustek.c
2 --- scanbuttond_cvs20090722/backends/gt68xx_plustek.c 1970-01-01 01:00:00.000000000 +0100
3 +++ scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/gt68xx_plustek.c 2009-07-24 20:57:18.000000000 +0200
4 @@ -0,0 +1,267 @@
5 +// gt68xx_plustek.c: scanbuttond backend for Plustek OpticSlim scanners
6 +// This file is part of scanbuttond.
7 +// Copyleft )c( 2005-2006 by Bernhard Stiftner
8 +//
9 +// Built primarily from "artec_eplus48u" scanbuttond backend.
10 +//
11 +// This program is free software; you can redistribute it and/or
12 +// modify it under the terms of the GNU General Public License as
13 +// published by the Free Software Foundation; either version 2 of the
14 +// License, or (at your option) any later version.
15 +//
16 +// This program is distributed in the hope that it will be useful, but
17 +// WITHOUT ANY WARRANTY; without even the implied warranty of
18 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 +// General Public License for more details.
20 +//
21 +// You should have received a copy of the GNU General Public License
22 +// along with this program; if not, write to the Free Software
23 +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 +//
26 +#include <stdio.h>
27 +#include <stdlib.h>
28 +#include <string.h>
29 +#include <unistd.h>
30 +#include <errno.h>
31 +#include <syslog.h>
32 +#include "scanbuttond/scanbuttond.h"
33 +#include "scanbuttond/libusbi.h"
34 +#include "gt68xx_plustek.h"
36 +static char* backend_name = "gt68xx/Plustek USB";
38 +#define NUM_SUPPORTED_USB_DEVICES 2
40 +static int supported_usb_devices[NUM_SUPPORTED_USB_DEVICES][3] = {
41 + // vendor, product, num_buttons
42 + { 0x07b3, 0x0422, 5 },
43 + { 0x07b3, 0x0454, 5 }
44 +};
46 +static char* usb_device_descriptions[NUM_SUPPORTED_USB_DEVICES][2] = {
47 + { "Plustek", "OpticSlim 2400" },
48 + { "Plustek", "OpticSlim 2400+" }
49 +};
52 +static libusb_handle_t* libusb_handle;
53 +static scanner_t* gt68xx_plustek_scanners = NULL;
56 +// returns -1 if the scanner is unsupported, or the index of the
57 +// corresponding vendor-product pair in the supported_usb_devices array.
58 +int gt68xx_plustek_match_libusb_scanner(libusb_device_t* device)
60 + int index;
61 + for (index = 0; index < NUM_SUPPORTED_USB_DEVICES; index++) {
62 + if (supported_usb_devices[index][0] == device->vendorID &&
63 + supported_usb_devices[index][1] == device->productID) {
64 + break;
65 + }
66 + }
67 + if (index >= NUM_SUPPORTED_USB_DEVICES) return -1;
68 + return index;
72 +void gt68xx_plustek_attach_libusb_scanner(libusb_device_t* device)
74 + const char* descriptor_prefix = "gt68xx:libusb:";
75 + int index = gt68xx_plustek_match_libusb_scanner(device);
76 + if (index < 0) return; // unsupported
77 + scanner_t* scanner = (scanner_t*)malloc(sizeof(scanner_t));
78 + scanner->vendor = usb_device_descriptions[index][0];
79 + scanner->product = usb_device_descriptions[index][1];
80 + scanner->connection = CONNECTION_LIBUSB;
81 + scanner->internal_dev_ptr = (void*)device;
82 + scanner->lastbutton = 0;
83 + scanner->sane_device = (char*)malloc(strlen(device->location) +
84 + strlen(descriptor_prefix) + 1);
85 + strcpy(scanner->sane_device, descriptor_prefix);
86 + strcat(scanner->sane_device, device->location);
87 + scanner->num_buttons = supported_usb_devices[index][2];
88 + scanner->is_open = 0;
89 + scanner->next = gt68xx_plustek_scanners;
90 + gt68xx_plustek_scanners = scanner;
94 +void gt68xx_plustek_detach_scanners(void)
96 + scanner_t* next;
97 + while (gt68xx_plustek_scanners != NULL) {
98 + next = gt68xx_plustek_scanners->next;
99 + free(gt68xx_plustek_scanners->sane_device);
100 + free(gt68xx_plustek_scanners);
101 + gt68xx_plustek_scanners = next;
106 +void gt68xx_plustek_scan_devices(libusb_device_t* devices)
108 + int index;
109 + libusb_device_t* device = devices;
110 + while (device != NULL) {
111 + index = gt68xx_plustek_match_libusb_scanner(device);
112 + if (index >= 0)
113 + gt68xx_plustek_attach_libusb_scanner(device);
114 + device = device->next;
119 +int gt68xx_plustek_init_libusb(void)
121 + libusb_device_t* devices;
123 + libusb_handle = libusb_init();
124 + devices = libusb_get_devices(libusb_handle);
125 + gt68xx_plustek_scan_devices(devices);
126 + return 0;
129 +int gt68xx_plustek_control_msg(scanner_t* scanner, int requesttype, int request,
130 + int value, int index, void* buffer, int bytecount)
132 + switch (scanner->connection) {
133 + case CONNECTION_LIBUSB:
134 + return libusb_control_msg((libusb_device_t*)scanner->internal_dev_ptr,
135 + requesttype, request, value, index, buffer,
136 + bytecount);
137 + break;
139 + return -1;
143 +const char* scanbtnd_get_backend_name(void)
145 + return backend_name;
149 +int scanbtnd_init(void)
151 + gt68xx_plustek_scanners = NULL;
153 + syslog(LOG_INFO, "gt68xx_plustek-backend: init");
154 + return gt68xx_plustek_init_libusb();
158 +int scanbtnd_rescan(void)
160 + libusb_device_t *devices;
162 + gt68xx_plustek_detach_scanners();
163 + gt68xx_plustek_scanners = NULL;
164 + libusb_rescan(libusb_handle);
165 + devices = libusb_get_devices(libusb_handle);
166 + gt68xx_plustek_scan_devices(devices);
167 + return 0;
171 +const scanner_t* scanbtnd_get_supported_devices(void)
173 + return gt68xx_plustek_scanners;
177 +int scanbtnd_open(scanner_t* scanner)
179 + int result = -ENOSYS;
180 + if (scanner->is_open)
181 + return -EINVAL;
182 + switch (scanner->connection) {
183 + case CONNECTION_LIBUSB:
184 + // if devices have been added/removed, return -ENODEV to
185 + // make scanbuttond update its device list
186 + if (libusb_get_changed_device_count() != 0)
187 + return -ENODEV;
188 + result = libusb_open((libusb_device_t*)scanner->internal_dev_ptr);
189 + break;
191 + if (result == 0)
192 + scanner->is_open = 1;
193 + return result;
197 +int scanbtnd_close(scanner_t* scanner)
199 + int result = -ENOSYS;
200 + if (!scanner->is_open)
201 + return -EINVAL;
202 + switch (scanner->connection) {
203 + case CONNECTION_LIBUSB:
204 + result = libusb_close((libusb_device_t*)scanner->internal_dev_ptr);
205 + break;
207 + if (result == 0)
208 + scanner->is_open = 0;
209 + return result;
213 +int scanbtnd_get_button(scanner_t* scanner)
216 + unsigned char bytes[64];
217 + int num_bytes;
219 + const unsigned char request_packet[64] = {
220 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
221 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
222 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
223 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
224 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
225 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
226 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
227 + 0x74, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
228 + };
230 + if (!scanner->is_open)
231 + return -EINVAL;
233 + // Send request
234 + num_bytes = gt68xx_plustek_control_msg(scanner,
235 + 0x40, 0x01, 0x2012, 0x3f40, (void *)request_packet, 64);
236 + if (num_bytes < 0) return 0;
238 + // Get response
239 + num_bytes = gt68xx_plustek_control_msg(scanner,
240 + 0xc0, 0x01, 0x2013, 0x3f00, (void *)bytes, 64);
241 + if (num_bytes < 0) return 0;
243 + switch (bytes[2]) {
244 + case 0x02: // copy
245 + return 1;
246 + case 0x04: // ocr
247 + return 2;
248 + case 0x08: // email
249 + return 3;
250 + case 0x10: // custom
251 + return 4;
252 + case 0x01: // scan
253 + return 5;
255 + return 0;
258 +const char* scanbtnd_get_sane_device_descriptor(scanner_t* scanner)
260 + return scanner->sane_device;
264 +int scanbtnd_exit(void)
266 + syslog(LOG_INFO, "gt68xx_plustek-backend: exit");
267 + gt68xx_plustek_detach_scanners();
268 + libusb_exit(libusb_handle);
269 + return 0;
272 diff -ruN scanbuttond_cvs20090722/backends/gt68xx_plustek.h scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/gt68xx_plustek.h
273 --- scanbuttond_cvs20090722/backends/gt68xx_plustek.h 1970-01-01 01:00:00.000000000 +0100
274 +++ scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/gt68xx_plustek.h 2009-07-24 20:57:18.000000000 +0200
275 @@ -0,0 +1,24 @@
276 +// gt68xx_plustek.h: scanbuttond backend for Plustek OpticSlim scanners
277 +// This file is part of scanbuttond.
278 +// Copyleft )c( 2004-2005 by Bernhard Stiftner
280 +// This program is free software; you can redistribute it and/or
281 +// modify it under the terms of the GNU General Public License as
282 +// published by the Free Software Foundation; either version 2 of the
283 +// License, or (at your option) any later version.
285 +// This program is distributed in the hope that it will be useful, but
286 +// WITHOUT ANY WARRANTY; without even the implied warranty of
287 +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
288 +// General Public License for more details.
290 +// You should have received a copy of the GNU General Public License
291 +// along with this program; if not, write to the Free Software
292 +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
294 +#ifndef __GT68XX_PLUSTEK_H_INCLUDED
295 +#define __GT68XX_PLUSTEK_H_INCLUDED
297 +#include "scanbuttond/backend.h"
299 +#endif
300 diff -ruN scanbuttond_cvs20090722/backends/Makefile.am scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/Makefile.am
301 --- scanbuttond_cvs20090722/backends/Makefile.am 2009-05-26 14:19:21.000000000 +0200
302 +++ scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/Makefile.am 2009-07-24 20:57:18.000000000 +0200
303 @@ -10,7 +10,8 @@
304 libscanbtnd-backend_hp3500.la \
305 libscanbtnd-backend_hp3900.la \
306 libscanbtnd-backend_hp5590.la \
307 - libscanbtnd-backend_gt68xx.la
308 + libscanbtnd-backend_gt68xx.la \
309 + libscanbtnd-backend_gt68xx_plustek.la
312 libscanbtnd_backend_epson_la_SOURCES = epson.c epson.h
313 @@ -52,6 +53,9 @@
314 libscanbtnd_backend_gt68xx_la_SOURCES = gt68xx.c gt68xx.h
315 libscanbtnd_backend_gt68xx_la_LIBADD = ../interface/libscanbtnd-interface_usb.la
316 libscanbtnd_backend_gt68xx_la_LDFLAGS = -module -version-info 1:0:0
317 +libscanbtnd_backend_gt68xx_plustek_la_SOURCES = gt68xx_plustek.c gt68xx_plustek.h
318 +libscanbtnd_backend_gt68xx_plustek_la_LIBADD = ../interface/libscanbtnd-interface_usb.la
319 +libscanbtnd_backend_gt68xx_plustek_la_LDFLAGS = -module -version-info 1:0:0
321 pkgsysconfdir = $(sysconfdir)/$(PACKAGE)
322 pkgsysconf_DATA = meta.conf
323 diff -ruN scanbuttond_cvs20090722/backends/meta.conf scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/meta.conf
324 --- scanbuttond_cvs20090722/backends/meta.conf 2009-05-26 14:19:21.000000000 +0200
325 +++ scanbuttond_cvs20090722+gt68xxPlustekBackend/backends/meta.conf 2009-07-24 20:57:18.000000000 +0200
326 @@ -10,3 +10,4 @@
327 libscanbtnd-backend_plustek_umax
328 libscanbtnd-backend_snapscan
329 libscanbtnd-backend_gt68xx
330 +libscanbtnd-backend_gt68xx_plustek
331 diff -ruN scanbuttond_cvs20090722/README scanbuttond_cvs20090722+gt68xxPlustekBackend/README
332 --- scanbuttond_cvs20090722/README 2009-05-26 14:19:21.000000000 +0200
333 +++ scanbuttond_cvs20090722+gt68xxPlustekBackend/README 2009-07-24 22:01:09.000000000 +0200
334 @@ -148,6 +148,10 @@
335 Supported by the gt68xx backend (via libusb):
336 * Genius Colorpage Vivid4 (working, experimental)
338 +Supported by the gt68xx_plustek backend (via libusb):
339 +* Plustek OpticSlim 2400 (expected to work)
340 +* Plustek OpticSlim 2400+ (working, tested)
342 Note: the mustek, niash, plustek, plustek_umax, gt68xx and snapscan backends
343 were implemented using information gathered by "sniffing" the communication
344 between the Windows driver and the scanner, because there is no technical