Package: scanbuttond
Version: 0.2.3.cvs20090713-8
Severity: normal
An earlier patch (bug #614312) has been disabled because it breaks the snapscan
backend. The new patch attached hereto incorporates the USB protocol obtained
by Mr Schemenauer in a new backend which does not affect existing backends in
any way. Tested on Wheezy with my own ScanSnap S1500 today.
Mike Thomas
diff -Nur scanbuttond-0.2.3.cvs20090713/backends/fujitsu.c
scanbuttond-0.2.3.cvs20090713-new/backends/fujitsu.c
--- scanbuttond-0.2.3.cvs20090713/backends/fujitsu.c 1970-01-01
01:00:00.000000000 +0100
+++ scanbuttond-0.2.3.cvs20090713-new/backends/fujitsu.c 2012-09-26
12:35:18.175103028 +0100
@@ -0,0 +1,291 @@
+// fujitsu.c: Fujitsu device backend
+// This file is part of scanbuttond.
+// Copyleft )c( 2005-2006 by Bernhard Stiftner
+// Thanks to J. Javier Maestro for sniffing the button codes ;-)
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <syslog.h>
+#include "scanbuttond/scanbuttond.h"
+#include "scanbuttond/libusbi.h"
+#include "fujitsu.h"
+
+static char* backend_name = "Fujitsu USB";
+
+#define NUM_SUPPORTED_USB_DEVICES 1
+
+static int supported_usb_devices[NUM_SUPPORTED_USB_DEVICES][3] = {
+ { 0x04c5, 0x11a2, 1 } // Fujitsu ScanSnap S1500
+};
+
+// TODO: check if this backend really works on the Epson 2580 too...
+static char* usb_device_descriptions[NUM_SUPPORTED_USB_DEVICES][2] = {
+ { "Fujitsu", "ScanSnap S1500" }
+};
+
+
+static libusb_handle_t* libusb_handle;
+static scanner_t* fujitsu_scanners = NULL;
+
+
+// returns -1 if the scanner is unsupported, or the index of the
+// corresponding vendor-product pair in the supported_usb_devices array.
+int fujitsu_match_libusb_scanner(libusb_device_t* device)
+{
+ int index;
+ for (index = 0; index < NUM_SUPPORTED_USB_DEVICES; index++) {
+ if (supported_usb_devices[index][0] == device->vendorID &&
+ supported_usb_devices[index][1] ==
device->productID) {
+ break;
+ }
+ }
+ if (index >= NUM_SUPPORTED_USB_DEVICES) return -1;
+ return index;
+}
+
+
+void fujitsu_attach_libusb_scanner(libusb_device_t* device)
+{
+ const char* descriptor_prefix = "fujitsu:libusb:";
+ int index = fujitsu_match_libusb_scanner(device);
+ if (index < 0) return; // unsupported
+ scanner_t* scanner = (scanner_t*)malloc(sizeof(scanner_t));
+ scanner->vendor = usb_device_descriptions[index][0];
+ scanner->product = usb_device_descriptions[index][1];
+ scanner->connection = CONNECTION_LIBUSB;
+ scanner->internal_dev_ptr = (void*)device;
+ scanner->lastbutton = 0;
+ scanner->sane_device = (char*)malloc(strlen(device->location) +
+ strlen(descriptor_prefix) + 1);
+ strcpy(scanner->sane_device, descriptor_prefix);
+ strcat(scanner->sane_device, device->location);
+ scanner->num_buttons = supported_usb_devices[index][2];
+ scanner->is_open = 0;
+ scanner->next = fujitsu_scanners;
+ fujitsu_scanners = scanner;
+}
+
+
+void fujitsu_detach_scanners(void)
+{
+ scanner_t* next;
+ while (fujitsu_scanners != NULL) {
+ next = fujitsu_scanners->next;
+ free(fujitsu_scanners->sane_device);
+ free(fujitsu_scanners);
+ fujitsu_scanners = next;
+ }
+}
+
+
+void fujitsu_scan_devices(libusb_device_t* devices)
+{
+ int index;
+ libusb_device_t* device = devices;
+ while (device != NULL) {
+ index = fujitsu_match_libusb_scanner(device);
+ if (index >= 0)
+ fujitsu_attach_libusb_scanner(device);
+ device = device->next;
+ }
+}
+
+
+int fujitsu_init_libusb(void)
+{
+ libusb_device_t* devices;
+
+ libusb_handle = libusb_init();
+ devices = libusb_get_devices(libusb_handle);
+ fujitsu_scan_devices(devices);
+ return 0;
+}
+
+
+const char* scanbtnd_get_backend_name(void)
+{
+ return backend_name;
+}
+
+
+int scanbtnd_init(void)
+{
+ fujitsu_scanners = NULL;
+
+ syslog(LOG_INFO, "fujitsu-backend: init");
+ return fujitsu_init_libusb();
+}
+
+
+int scanbtnd_rescan(void)
+{
+ libusb_device_t* devices;
+
+ fujitsu_detach_scanners();
+ fujitsu_scanners = NULL;
+ libusb_rescan(libusb_handle);
+ devices = libusb_get_devices(libusb_handle);
+ fujitsu_scan_devices(devices);
+ return 0;
+}
+
+
+const scanner_t* scanbtnd_get_supported_devices(void)
+{
+ return fujitsu_scanners;
+}
+
+
+int scanbtnd_open(scanner_t* scanner)
+{
+ int result = -ENOSYS;
+ if (scanner->is_open)
+ return -EINVAL;
+ switch (scanner->connection) {
+ case CONNECTION_LIBUSB:
+ // if devices have been added/removed, return -ENODEV to
+ // make scanbuttond update its device list
+ if (libusb_get_changed_device_count() != 0)
+ return -ENODEV;
+ result =
libusb_open((libusb_device_t*)scanner->internal_dev_ptr);
+ break;
+ }
+ if (result == 0)
+ scanner->is_open = 1;
+ return result;
+}
+
+
+int scanbtnd_close(scanner_t* scanner)
+{
+ int result = -ENOSYS;
+ if (!scanner->is_open)
+ return -EINVAL;
+ switch (scanner->connection) {
+ case CONNECTION_LIBUSB:
+ result =
libusb_close((libusb_device_t*)scanner->internal_dev_ptr);
+ break;
+ }
+ if (result == 0)
+ scanner->is_open = 0;
+ return result;
+}
+
+
+int fujitsu_read(scanner_t* scanner, void* buffer, int bytecount)
+{
+ switch (scanner->connection) {
+ case CONNECTION_LIBUSB:
+ return
libusb_read((libusb_device_t*)scanner->internal_dev_ptr,
+ buffer, bytecount);
+ break;
+ }
+ return -1;
+}
+
+
+int fujitsu_write(scanner_t* scanner, void* buffer, int bytecount)
+{
+ switch (scanner->connection) {
+ case CONNECTION_LIBUSB:
+ return
libusb_write((libusb_device_t*)scanner->internal_dev_ptr,
+ buffer, bytecount);
+ break;
+ }
+ return -1;
+}
+
+void fujitsu_flush(scanner_t* scanner)
+{
+ switch (scanner->connection) {
+ case CONNECTION_LIBUSB:
+
libusb_flush((libusb_device_t*)scanner->internal_dev_ptr);
+ break;
+ }
+}
+
+static unsigned char CMD[] = {
+ 0x43, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0xc2,
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x0a,
+ 0x00, 0x00, 0x00,
+ };
+
+int scanbtnd_get_button(scanner_t* scanner)
+{
+ unsigned char bytes[20];
+ int num_bytes;
+ int button = 0;
+
+ if (!scanner->is_open)
+ return -EINVAL;
+
+ num_bytes = fujitsu_write(scanner, (void*)CMD, sizeof CMD );
+ if (num_bytes != (sizeof CMD)) {
+ syslog(LOG_WARNING, "fujitsu-backend: communication error: "
+ "write length:%d (expected:%d)", num_bytes, sizeof CMD);
+ fujitsu_flush(scanner);
+ return 0;
+ }
+
+ num_bytes = fujitsu_read(scanner, (void*)bytes, 10);
+ if (num_bytes != 10) {
+ syslog(LOG_WARNING, "fujitsu-backend: communication error: "
+ "read length:%d (expected:%d)",
+ num_bytes, 10);
+ fujitsu_flush(scanner);
+ return 0;
+ }
+
+ if (bytes[4] == 0x01) {
+ button = 1;
+ }
+
+ num_bytes = fujitsu_read(scanner, (void*)bytes, 13);
+ if (num_bytes != 13) {
+ syslog(LOG_WARNING, "fujitsu-backend: communication error: "
+ "read length:%d (expected:%d)",
+ num_bytes, 13);
+ fujitsu_flush(scanner);
+ return 0;
+ }
+
+ return button;
+}
+
+
+const char* scanbtnd_get_sane_device_descriptor(scanner_t* scanner)
+{
+ return scanner->sane_device;
+}
+
+
+int scanbtnd_exit(void)
+{
+ syslog(LOG_INFO, "fujitsu-backend: exit");
+ fujitsu_detach_scanners();
+ libusb_exit(libusb_handle);
+ return 0;
+}
+
diff -Nur scanbuttond-0.2.3.cvs20090713/backends/fujitsu.h
scanbuttond-0.2.3.cvs20090713-new/backends/fujitsu.h
--- scanbuttond-0.2.3.cvs20090713/backends/fujitsu.h 1970-01-01
01:00:00.000000000 +0100
+++ scanbuttond-0.2.3.cvs20090713-new/backends/fujitsu.h 2012-09-25
13:08:58.352413883 +0100
@@ -0,0 +1,25 @@
+// fujitsu.h: Fujitsu device backend
+// This file is part of scanbuttond.
+// Copyleft )c( 2005 by Bernhard Stiftner
+// Thanks to J. Javier Maestro for sniffing the button codes ;-)
+//
+// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+#ifndef __FUJITSU_H_INCLUDED
+#define __FUJITSU_H_INCLUDED
+
+#include "scanbuttond/backend.h"
+
+#endif
diff -Nur scanbuttond-0.2.3.cvs20090713/backends/Makefile.am
scanbuttond-0.2.3.cvs20090713-new/backends/Makefile.am
--- scanbuttond-0.2.3.cvs20090713/backends/Makefile.am 2009-05-26
13:19:21.000000000 +0100
+++ scanbuttond-0.2.3.cvs20090713-new/backends/Makefile.am 2012-09-25
13:04:35.390856823 +0100
@@ -7,6 +7,7 @@
libscanbtnd-backend_plustek.la \
libscanbtnd-backend_plustek_umax.la \
libscanbtnd-backend_snapscan.la \
+ libscanbtnd-backend_fujitsu.la \
libscanbtnd-backend_hp3500.la \
libscanbtnd-backend_hp3900.la \
libscanbtnd-backend_hp5590.la \
@@ -34,6 +35,9 @@
libscanbtnd_backend_snapscan_la_SOURCES = snapscan.c snapscan.h
libscanbtnd_backend_snapscan_la_LIBADD =
../interface/libscanbtnd-interface_usb.la
libscanbtnd_backend_snapscan_la_LDFLAGS = -module -version-info 1:0:0
+libscanbtnd_backend_fujitsu_la_SOURCES = fujitsu.c fujitsu.h
+libscanbtnd_backend_fujitsu_la_LIBADD =
../interface/libscanbtnd-interface_usb.la
+libscanbtnd_backend_fujitsu_la_LDFLAGS = -module -version-info 1:0:0
libscanbtnd_backend_artec_eplus48u_la_SOURCES = artec_eplus48u.c
artec_eplus48u.h
libscanbtnd_backend_artec_eplus48u_la_LIBADD =
../interface/libscanbtnd-interface_usb.la
libscanbtnd_backend_artec_eplus48u_la_LDFLAGS = -module -version-info 1:0:0
diff -Nur scanbuttond-0.2.3.cvs20090713/backends/meta.conf
scanbuttond-0.2.3.cvs20090713-new/backends/meta.conf
--- scanbuttond-0.2.3.cvs20090713/backends/meta.conf 2009-05-26
13:19:21.000000000 +0100
+++ scanbuttond-0.2.3.cvs20090713-new/backends/meta.conf 2012-09-25
13:10:24.432413785 +0100
@@ -9,4 +9,5 @@
libscanbtnd-backend_plustek
libscanbtnd-backend_plustek_umax
libscanbtnd-backend_snapscan
+libscanbtnd-backend_fujitsu
libscanbtnd-backend_gt68xx
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]