Hi Ilia et all
attached to this message is the patch (hope mailman engine does not
strip it out :))
Basically exports all missing options as buttons and fix a small problem
I've found interacting with scanbd.
I've tested during the weekend and last days (as real user , I missed
this feature for two months after debian upgrade)
and it seems to work.
Sometime the buttons are less responsive (it depends from scheduled
calls to options made by scanbd)
Probably a better approach could be a separate polling thread (maybe a
next version :))
but for now is quite usable.
I've tested with normal sane application too and with scanbm (for
network scanning and desktop shared scanner)
and no problems at all
Sorry for some erratic indentation.. I've used a
"week-end-found-bad-editor" that mixed up tab and blank spaces

Let me know
Happy PI Day ;)

Damiano

On 13/03/2018 20:56, Ilia Sotnikov wrote:
> Excellent, thanks Damiano! As a quick step you could send the patch over to 
> the DL and I’ll adapt it if needed. Or you could create a merge request, 
> which would be more elegant though require additional steps.
> ---
>  Ilia Sotnikov
>
>> On Mar 13, 2018, at 21:29, Cesello <cese...@daimonlab.it> wrote:
>>
>> Hi Ilia and Jared
>> I'm just registered to this ML to propose my patch to this back end
>> driver made in the past weekend.
>> And I see someone have my same problem :)
>> I've used hp5590 scanner with scanbuttond for years. Some week ago I've
>> upgraded my system to debian 9 and
>> discovered that scanbd does not works anymore with my scanner. I really
>> need this functionality so I've made
>> modifications to hp5590.c code to export the options .
>> Is a first attempt and the backend called by scanbd threads makes
>> buttons quite  responsive
>> without using a self polling thread.
>> I've made a patch file for debian 9  stable version package (yes but the
>> real patch is for hp5590.c only)
>> If you are interested I can send it (or tell me if I have to release
>> into the repo directly I'm new user here :))
>>
>> Damiano
>>
>>> On 07/03/2018 14:01, hostcc at gmail.com (Ilia Sotnikov) wrote:
>>> Hi,
>>> backend author here - it shouldn't be too much of effort to expose
>>> button status so scanbd can use it. Though haven't gone thru its
>>> documentation to understand requirements. As a technical insight -
>>> there is hp5590_read_buttons() function in hp5590_cmds.c that reads
>>> button status.
>>> However, I'll seek for a volunteer to test a change as I don't have
>>> access to HW currently.
>>>
>>> On Wed, Mar 7, 2018 at 12:40 AM, Wilhelm Meier
>>> <wilhelm.wm.meier at googlemail.com> wrote:
>>>> Please try the old scanbuttond-backend for this type of scanner - it
>>>> should work. The HP sane backend sadly doesn't support the buttons on
>>>> this scanner.
>>>>
>>>> Am 06.03.2018 um 15:46 schrieb Jared Hedegaard:
>>>>>> Main question: does the HP 5590 support button presses or am I just 
>>>>>> setting this up incorrectly?
>>>>>>
>>>>>> I'm been successful using scanbd with SANE backends to get scanning 
>>>>>> working over my network and locally on the host machine, but I can't 
>>>>>> seem to get it to recognize button presses, either running scanbd in 
>>>>>> foreground or background.
>>>>>>
>>>>>> For past testing, it seems that actions defined in scanbd.conf are used 
>>>>>> to tie to the backend options? From searching /var/log/syslog, I 
>>>>>> expected to track button presses or get some sort of trigger feedback, 
>>>>>> and I didn't think I needed an action set up for it.
>>>>>>
>>>>>> Any help on this one would be much appreciated. Thanks.
>>>>>>
>>>>>> Jared H
>>>>>>
>>>>> After a bit more research, it looks like doing this with the SANE backend 
>>>>> for HP 5590 is not possible. scanbd is used to tie custom actions to the 
>>>>> options available on the scanner. In this case, none of the 10 options 
>>>>> seem to return values. They all look to be ones that I designate from 
>>>>> some client software.
>>>>>
>>>>> scanbd: found active option[1] tl-x (type: 2) for device 
>>>>> hp5590:libusb:001:008
>>>>> scanbd: found active option[2] tl-y (type: 2) for device 
>>>>> hp5590:libusb:001:008
>>>>> scanbd: found active option[3] br-x (type: 2) for device 
>>>>> hp5590:libusb:001:008
>>>>> scanbd: found active option[4] br-y (type: 2) for device 
>>>>> hp5590:libusb:001:008
>>>>> scanbd: found active option[5] mode (type: 3) for device 
>>>>> hp5590:libusb:001:008
>>>>> scanbd: found active option[6] source (type: 3) for device 
>>>>> hp5590:libusb:001:008
>>>>> scanbd: found active option[7] resolution (type: 1) for device 
>>>>> hp5590:libusb:001:008 scanbd: found active option[8] extend-lamp-timeout 
>>>>> (type: 0) for device hp5590:libusb:001:008
>>>>> scanbd: found active option[9] wait-for-button (type: 0) for device 
>>>>> hp5590:libusb:001:008
>>>>> scanbd: found active option[10] preview (type: 0) for device 
>>>>> hp5590:libusb:001:008
>>>>>
>>>>> In this case, it looks like I will have to try the old scanbuttond 
>>>>> backends for this, or see if there are optional enhancements for the SANE 
>>>>> hp5590 backend.
>>>>>
>>>>> Jared
>>>>>
>>>> --
>>>> sane-devel mailing list: sane-devel at lists.alioth.debian.org
>>>> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
>>>> Unsubscribe: Send mail with subject "unsubscribe your_password"
>>>>             to sane-devel-request at lists.alioth.debian.org
>>>
>>
>> -- 
>> sane-devel mailing list: sane-devel@lists.alioth.debian.org
>> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
>> Unsubscribe: Send mail with subject "unsubscribe your_password"
>>             to sane-devel-requ...@lists.alioth.debian.org


Description: Adding the necessary logic to export,as options,the scanner buttons
Author: Damiano Scaramuzza <cese...@daimonlab.it>
Last-Update: 2018-03-14 
================================================================================
--- a/backend/hp5590.c
+++ b/backend/hp5590.c
@@ -49,6 +49,7 @@
 #include <string.h>
 #include <unistd.h>
 
+
 #include "../include/sane/sane.h"
 #define BACKEND_NAME hp5590
 #include "../include/sane/sanei_backend.h"
@@ -95,6 +96,26 @@
 #define SANE_TITLE_WAIT_FOR_BUTTON 		SANE_I18N("Wait for button")
 #define SANE_DESC_WAIT_FOR_BUTTON 		SANE_I18N("Waits for button before scanning")
 
+#define SANE_NAME_COLLECT                       "collect"
+#define SANE_TITLE_COLLECT                      SANE_I18N("collect button")
+#define SANE_DESC_COLLECT                       SANE_I18N("Status of collect button")
+
+#define SANE_NAME_POWER                         "power"
+#define SANE_TITLE_POWER                        SANE_I18N("power button")
+#define SANE_DESC_POWER                         SANE_I18N("Status of power button")
+
+#define SANE_NAME_UP                            "up"
+#define SANE_TITLE_UP                           SANE_I18N("up button")
+#define SANE_DESC_UP                            SANE_I18N("Status of up button")
+
+#define SANE_NAME_DOWN                          "down"
+#define SANE_TITLE_DOWN                         SANE_I18N("down button")
+#define SANE_DESC_DOWN                          SANE_I18N("Status of down button")
+
+#define SANE_NAME_MODECHANGE                    "mdechange"
+#define SANE_TITLE_MODECHANGE                   SANE_I18N("mode change button")
+#define SANE_DESC_MODECHANGE                    SANE_I18N("Status of mode change button")
+
 #define MAX_SCAN_SOURCE_VALUE_LEN 	24
 #define MAX_SCAN_MODE_VALUE_LEN		24
 
@@ -124,10 +145,21 @@
   HP5590_OPT_LAMP_TIMEOUT,
   HP5590_OPT_WAIT_FOR_BUTTON,
   HP5590_OPT_PREVIEW,
+  HP5590_OPT_BUTTON_CANCEL,
+  HP5590_OPT_BUTTON_COLLECT,
+  HP5590_OPT_BUTTON_SCAN,
+  HP5590_OPT_BUTTON_POWER,
+  HP5590_OPT_BUTTON_FILE,
+  HP5590_OPT_BUTTON_UP,
+  HP5590_OPT_BUTTON_MODE,
+  HP5590_OPT_BUTTON_DOWN,
+  HP5590_OPT_BUTTON_COPY,
+  HP5590_OPT_BUTTON_EMAIL,
   HP5590_OPT_LAST
 };
 
 struct hp5590_scanner {
+
   struct scanner_info 		*info;
   enum proto_flags		proto_flags;
   SANE_Device 			sane;
@@ -138,6 +170,7 @@
   enum scan_sources	 	source;
   SANE_Bool 			extend_lamp_timeout;
   SANE_Bool 			wait_for_button;
+  enum button_status	        button_status;
   SANE_Bool 			preview;
   unsigned int 			quality;
   SANE_Option_Descriptor 	*opts;
@@ -151,6 +184,7 @@
 static
 struct hp5590_scanner *scanners_list;
 
+
 /******************************************************************************/
 static SANE_Status
 calc_image_params (struct hp5590_scanner *scanner,
@@ -383,13 +417,15 @@
 
   DBG (DBG_proc, "%s\n", __FUNCTION__);
 
+
   for (ptr = scanners_list; ptr; ptr = pnext)
-    {
-      if (ptr->opts != NULL)
-	free (ptr->opts);
-      pnext = ptr->next;
-      free (ptr);
-    }
+  {
+    if (ptr->opts != NULL)
+        free (ptr->opts);
+
+     pnext = ptr->next;
+     free (ptr);
+  }
 }
 
 /******************************************************************************/
@@ -433,6 +469,8 @@
 
   DBG (DBG_proc, "%s: device name: %s\n", __FUNCTION__, devicename);
 
+
+
   if (!handle)
     return SANE_STATUS_INVAL;
 
@@ -448,6 +486,19 @@
   if (!ptr)
     return SANE_STATUS_INVAL;
 
+  /* DS: Following lines was necessary. Without this after the first scan (and sane close)
+     was impossible to use again the read_buttons usb routine.
+     I dunno , it could be an old bug maybe.  sane_close put dn=-1 but sane_open do nor re-open
+     the usb comunication and do not change the dn that stay equal -1. This if statement fix it .
+  */
+  if (ptr->dn==-1)
+  {
+    DBG (DBG_proc, "%s: Opening USB device\n", __FUNCTION__);
+    if (sanei_usb_open (ptr->sane.name, &ptr->dn) != SANE_STATUS_GOOD)
+        return SANE_STATUS_IO_ERROR;
+    DBG (DBG_proc, "%s: USB device opened\n", __FUNCTION__);
+  }
+
   ptr->tl_x = 0;
   ptr->tl_y = 0;
   ptr->br_x = ptr->info->max_size_x;
@@ -461,6 +512,7 @@
   ptr->quality = 4;
   ptr->image_size = 0;
   ptr->scanning = SANE_FALSE;
+  ptr->button_status= BUTTON_NONE;
 
   *handle = ptr;
 
@@ -612,6 +664,106 @@
   opts[HP5590_OPT_PREVIEW].constraint_type = SANE_CONSTRAINT_NONE;
   opts[HP5590_OPT_PREVIEW].constraint.string_list = NULL;
 
+  opts[HP5590_OPT_BUTTON_CANCEL].name = SANE_NAME_CANCEL;
+  opts[HP5590_OPT_BUTTON_CANCEL].title = SANE_TITLE_CANCEL;
+  opts[HP5590_OPT_BUTTON_CANCEL].desc = SANE_DESC_CANCEL;
+  opts[HP5590_OPT_BUTTON_CANCEL].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_CANCEL].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_CANCEL].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_CANCEL].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_CANCEL].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_CANCEL].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_COLLECT].name = SANE_NAME_COLLECT;
+  opts[HP5590_OPT_BUTTON_COLLECT].title = SANE_TITLE_COLLECT;
+  opts[HP5590_OPT_BUTTON_COLLECT].desc = SANE_DESC_COLLECT;
+  opts[HP5590_OPT_BUTTON_COLLECT].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_COLLECT].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_COLLECT].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_COLLECT].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_COLLECT].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_COLLECT].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_SCAN].name = SANE_NAME_SCAN;
+  opts[HP5590_OPT_BUTTON_SCAN].title = SANE_TITLE_SCAN;
+  opts[HP5590_OPT_BUTTON_SCAN].desc = SANE_DESC_SCAN;
+  opts[HP5590_OPT_BUTTON_SCAN].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_SCAN].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_SCAN].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_SCAN].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_SCAN].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_SCAN].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_POWER].name = SANE_NAME_POWER;
+  opts[HP5590_OPT_BUTTON_POWER].title = SANE_TITLE_POWER;
+  opts[HP5590_OPT_BUTTON_POWER].desc = SANE_DESC_POWER;
+  opts[HP5590_OPT_BUTTON_POWER].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_POWER].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_POWER].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_POWER].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_POWER].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_POWER].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_FILE].name = SANE_NAME_FILE;
+  opts[HP5590_OPT_BUTTON_FILE].title = SANE_TITLE_FILE;
+  opts[HP5590_OPT_BUTTON_FILE].desc = SANE_DESC_FILE;
+  opts[HP5590_OPT_BUTTON_FILE].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_FILE].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_FILE].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_FILE].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_FILE].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_FILE].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_UP].name = SANE_NAME_UP;
+  opts[HP5590_OPT_BUTTON_UP].title = SANE_TITLE_UP;
+  opts[HP5590_OPT_BUTTON_UP].desc = SANE_DESC_UP;
+  opts[HP5590_OPT_BUTTON_UP].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_UP].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_UP].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_UP].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_UP].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_UP].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_MODE].name = SANE_NAME_MODECHANGE;
+  opts[HP5590_OPT_BUTTON_MODE].title = SANE_TITLE_MODECHANGE;
+  opts[HP5590_OPT_BUTTON_MODE].desc = SANE_DESC_MODECHANGE;
+  opts[HP5590_OPT_BUTTON_MODE].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_MODE].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_MODE].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_MODE].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_MODE].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_MODE].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_DOWN].name = SANE_NAME_DOWN;
+  opts[HP5590_OPT_BUTTON_DOWN].title = SANE_TITLE_DOWN;
+  opts[HP5590_OPT_BUTTON_DOWN].desc = SANE_DESC_DOWN;
+  opts[HP5590_OPT_BUTTON_DOWN].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_DOWN].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_DOWN].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_DOWN].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_DOWN].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_DOWN].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_COPY].name = SANE_NAME_COPY;
+  opts[HP5590_OPT_BUTTON_COPY].title = SANE_TITLE_COPY;
+  opts[HP5590_OPT_BUTTON_COPY].desc = SANE_DESC_COPY;
+  opts[HP5590_OPT_BUTTON_COPY].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_COPY].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_COPY].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_COPY].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_COPY].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_COPY].constraint.string_list = NULL;
+
+  opts[HP5590_OPT_BUTTON_EMAIL].name = SANE_NAME_EMAIL;
+  opts[HP5590_OPT_BUTTON_EMAIL].title = SANE_TITLE_EMAIL;
+  opts[HP5590_OPT_BUTTON_EMAIL].desc = SANE_DESC_EMAIL;
+  opts[HP5590_OPT_BUTTON_EMAIL].type = SANE_TYPE_BOOL;
+  opts[HP5590_OPT_BUTTON_EMAIL].unit = SANE_UNIT_NONE;
+  opts[HP5590_OPT_BUTTON_EMAIL].size = sizeof(SANE_Bool);
+  opts[HP5590_OPT_BUTTON_EMAIL].cap =  SANE_CAP_SOFT_SELECT | SANE_CAP_SOFT_DETECT;
+  opts[HP5590_OPT_BUTTON_EMAIL].constraint_type = SANE_CONSTRAINT_NONE;
+  opts[HP5590_OPT_BUTTON_EMAIL].constraint.string_list = NULL;
+
   ptr->opts = opts;
 
   return SANE_STATUS_GOOD;
@@ -643,6 +795,29 @@
   return &scanner->opts[option];
 }
 
+/*************************************DS:Support function read buttons status */
+SANE_Status
+readbutton_status(SANE_Handle handle)
+{
+    struct hp5590_scanner * scanner = handle;
+    enum button_status status;
+    SANE_Status	ret;
+
+
+    DBG (DBG_verbose, "%s: Checking scan buttons status (dn:%u) (name:%s) \n", __FUNCTION__,scanner->dn,scanner->sane.name);
+    ret = hp5590_read_buttons (scanner->dn,scanner->proto_flags,&status);
+    if (ret != SANE_STATUS_GOOD)
+    {
+        DBG (DBG_proc, "%s: Error reading button status (Error: %u) \n", __FUNCTION__,ret);
+        return ret;
+    }
+    DBG (DBG_verbose, "%s: Read scan button status\n", __FUNCTION__);
+    scanner->button_status=status;
+
+    return SANE_STATUS_GOOD;
+
+}
+
 /******************************************************************************/
 SANE_Status
 sane_control_option (SANE_Handle handle, SANE_Int option,
@@ -650,6 +825,7 @@
                      SANE_Int * info)
 {
   struct hp5590_scanner	*scanner = handle;
+  SANE_Status	ret;
   
   if (!value)
     return SANE_STATUS_INVAL;
@@ -661,7 +837,7 @@
     return SANE_STATUS_INVAL;
 
   if (action == SANE_ACTION_GET_VALUE)
-    {
+  {
       if (option == HP5590_OPT_NUM)
 	{
 	  DBG(3, "%s: get total number of options - %u\n", __FUNCTION__, HP5590_OPT_LAST);
@@ -669,12 +845,12 @@
 	  return SANE_STATUS_GOOD;
 	}
  
-      if (!scanner->opts)
-	return SANE_STATUS_INVAL;
+    if (!scanner->opts)
+    	return SANE_STATUS_INVAL;
       
       DBG (DBG_proc, "%s: get option '%s' value\n", __FUNCTION__, scanner->opts[option].name);
 
-      if (option == HP5590_OPT_BR_X)
+    if (option == HP5590_OPT_BR_X)
 	{
 	  *(SANE_Fixed *) value = SANE_FIX (scanner->br_x * 25.4);
 	}
@@ -757,16 +933,211 @@
 	  *(SANE_Bool *) value = scanner->extend_lamp_timeout;
 	}
 
-      if (option == HP5590_OPT_WAIT_FOR_BUTTON)
+    if (option == HP5590_OPT_WAIT_FOR_BUTTON)
 	{
 	  *(SANE_Bool *) value = scanner->wait_for_button;
 	}
 
-      if (option == HP5590_OPT_PREVIEW)
+
+    /* DS: Here we verify a previous button pressed and not checked
+     * a sort of small two elements buffer
+     */
+    if (option == HP5590_OPT_BUTTON_SCAN)
+    {
+        DBG (DBG_verbose, "%s: Read scan option \n", __FUNCTION__);
+
+        /* previously  pressed ? */
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+                /* return this and read next status for next time */
+        	*(SANE_Bool *) value = (scanner->button_status==BUTTON_SCAN) ? SANE_TRUE : SANE_FALSE;
+
+        	if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+        	   return ret;
+        }
+        else
+        {
+               /* not previously pressed we read it now */
+        	if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+        		return ret;
+
+        	*(SANE_Bool *) value = (scanner->button_status==BUTTON_SCAN) ? SANE_TRUE : SANE_FALSE;
+        }
+
+    }
+    if (option == HP5590_OPT_BUTTON_CANCEL)
+    {
+    	if (scanner->button_status!=BUTTON_NONE)
 	{
-	  *(SANE_Bool *) value = scanner->preview;
+                *(SANE_Bool *) value = (scanner->button_status==BUTTON_CANCEL) ? SANE_TRUE : SANE_FALSE;
+
+   		if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+    		   return ret;
 	}
+	else
+	{
+		if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                  return ret;
+
+		*(SANE_Bool *) value = (scanner->button_status==BUTTON_CANCEL) ? SANE_TRUE : SANE_FALSE;
+	}
+    }
+    if (option == HP5590_OPT_BUTTON_COLLECT)
+    {
+    	if (scanner->button_status!=BUTTON_NONE)
+	{
+              *(SANE_Bool *) value = (scanner->button_status==BUTTON_COLLECT) ? SANE_TRUE : SANE_FALSE;
+
+              if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+	}
+	else
+	{
+                if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                  return ret;
+
+                *(SANE_Bool *) value = (scanner->button_status==BUTTON_COLLECT) ? SANE_TRUE : SANE_FALSE;
+	}
+
+
+    }
+    if (option == HP5590_OPT_BUTTON_COPY)
+    {
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_COPY) ? SANE_TRUE : SANE_FALSE;
+
+             if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+               return ret;
+        }
+        else
+        {
+            if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_COPY) ? SANE_TRUE : SANE_FALSE;
+        }
+
+    }
+    if (option == HP5590_OPT_BUTTON_UP)
+    {
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_UP) ? SANE_TRUE : SANE_FALSE;
+
+             if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+               return ret;
+        }
+        else
+        {
+            if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_UP) ? SANE_TRUE : SANE_FALSE;
+        }
+
+
+    }
+    if (option == HP5590_OPT_BUTTON_DOWN)
+    {
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_DOWN) ? SANE_TRUE : SANE_FALSE;
+
+             if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+               return ret;
+        }
+        else
+        {
+            if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_DOWN) ? SANE_TRUE : SANE_FALSE;
+        }
+
+
+    }
+    if (option == HP5590_OPT_BUTTON_EMAIL)
+    {
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_EMAIL) ? SANE_TRUE : SANE_FALSE;
+
+             if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+               return ret;
+        }
+        else
+        {
+            if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_EMAIL) ? SANE_TRUE : SANE_FALSE;
+        }
+
+
     }
+    if (option == HP5590_OPT_BUTTON_FILE)
+    {
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_FILE) ? SANE_TRUE : SANE_FALSE;
+
+             if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+               return ret;
+        }
+        else
+        {
+            if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_FILE) ? SANE_TRUE : SANE_FALSE;
+        }
+
+
+    }
+    if (option == HP5590_OPT_BUTTON_MODE)
+    {
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_MODE) ? SANE_TRUE : SANE_FALSE;
+
+             if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+               return ret;
+        }
+        else
+        {
+            if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_MODE) ? SANE_TRUE : SANE_FALSE;
+        }
+
+    }
+    if (option == HP5590_OPT_BUTTON_POWER)
+    {
+        if (scanner->button_status!=BUTTON_NONE)
+        {
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_POWER) ? SANE_TRUE : SANE_FALSE;
+
+             if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+               return ret;
+        }
+        else
+        {
+            if ( (ret=readbutton_status(handle)) != SANE_STATUS_GOOD)
+                return ret;
+
+            *(SANE_Bool *) value = (scanner->button_status==BUTTON_POWER) ? SANE_TRUE : SANE_FALSE;
+        }
+
+
+    }
+
+    if (option == HP5590_OPT_PREVIEW)
+    {
+	  *(SANE_Bool *) value = scanner->preview;
+    }
+  }
  
   if (action == SANE_ACTION_SET_VALUE)
     {
@@ -906,11 +1277,13 @@
 	  scanner->wait_for_button = *(SANE_Bool *) value;
 	}
 
+
+
       if (option == HP5590_OPT_PREVIEW)
 	{
 	  scanner->preview = *(SANE_Bool *) value;
 	}
-    }
+  }
    
   return SANE_STATUS_GOOD;
 }
@@ -976,6 +1349,7 @@
 }
 
 /******************************************************************************/
+
 SANE_Status
 sane_start (SANE_Handle handle)
 {
@@ -988,6 +1362,7 @@
   if (!scanner)
     return SANE_STATUS_INVAL;
 
+
   if (   scanner->scanning == SANE_TRUE
       && (  scanner->source == SOURCE_ADF
 	 || scanner->source == SOURCE_ADF_DUPLEX))
@@ -1003,7 +1378,7 @@
 	}
 
       if (ret != SANE_STATUS_NO_DOCS)
-	return ret;
+    	  return ret;
     }
 
   sane_cancel (handle);
@@ -1012,38 +1387,38 @@
     {
       enum button_status status;
       for (;;)
-	{
-	  ret = hp5590_read_buttons (scanner->dn,
-	  		     	     scanner->proto_flags,
-				     &status);
-	  if (ret != SANE_STATUS_GOOD)
-	    return ret;
-
-	  if (status == BUTTON_CANCEL)
-	    return SANE_STATUS_CANCELLED;
-
-	  if (status != BUTTON_NONE && status != BUTTON_POWER)
-	    break;
-	  sleep (1);
-	}
+      {
+          ret = hp5590_read_buttons (scanner->dn,
+	                             scanner->proto_flags,
+                                     &status);
+          if (ret != SANE_STATUS_GOOD)
+             return ret;
+
+          if (status == BUTTON_CANCEL)
+             return SANE_STATUS_CANCELLED;
+
+          if (status != BUTTON_NONE && status != BUTTON_POWER)
+             break;
+          sleep (1);
+      }
     }
 
   DBG (DBG_verbose, "Init scanner\n");  
   ret = hp5590_init_scanner (scanner->dn, scanner->proto_flags,
   			     NULL, SCANNER_NONE);
   if (ret != SANE_STATUS_GOOD)
-    return ret;
+	  return ret;
 
   ret = hp5590_power_status (scanner->dn, scanner->proto_flags);
   if (ret != SANE_STATUS_GOOD)
-    return ret;
+	  return ret;
 
   DBG (DBG_verbose, "Wakeup\n");
   ret = hp5590_select_source_and_wakeup (scanner->dn, scanner->proto_flags,
   					 scanner->source,
 					 scanner->extend_lamp_timeout);
   if (ret != SANE_STATUS_GOOD)
-    return ret;
+	  return ret;
  
   ret = hp5590_set_scan_params (scanner->dn,
   				scanner->proto_flags,
@@ -1097,7 +1472,7 @@
 	       "(image size: %u, bytes per line %u)\n",
 	       scanner->image_size, bytes_per_line);
           hp5590_reset_scan_head (scanner->dn, scanner->proto_flags);
-	  return SANE_STATUS_INVAL;
+          return SANE_STATUS_INVAL;
 	}
       DBG (1, "Color 24/48 bits: image size correctly aligned on bytes per line "
 	   "(images size: %u, bytes per line: %u)\n",
-- 
sane-devel mailing list: sane-devel@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/sane-devel
Unsubscribe: Send mail with subject "unsubscribe your_password"
             to sane-devel-requ...@lists.alioth.debian.org

Reply via email to