Merge branch 'genesys-error-handling' into 'master'

genesys: Improve error handling

See merge request sane-project/backends!86
This commit is contained in:
Povilas Kanapickas
2019-07-05 23:39:04 +00:00
15 changed files with 865 additions and 630 deletions
+6 -1
View File
@@ -480,7 +480,12 @@ libsane_fujitsu_la_LDFLAGS = $(DIST_SANELIBS_LDFLAGS)
libsane_fujitsu_la_LIBADD = $(COMMON_LIBS) libfujitsu.la ../sanei/sanei_init_debug.lo ../sanei/sanei_constrain_value.lo ../sanei/sanei_config.lo ../sanei/sanei_config2.lo sane_strstatus.lo ../sanei/sanei_usb.lo ../sanei/sanei_scsi.lo ../sanei/sanei_magic.lo $(MATH_LIB) $(SCSI_LIBS) $(USB_LIBS) $(RESMGR_LIBS)
EXTRA_DIST += fujitsu.conf.in
libgenesys_la_SOURCES = genesys.cc genesys.h genesys_gl646.cc genesys_gl646.h genesys_gl841.cc genesys_gl841.h genesys_gl843.cc genesys_gl843.h genesys_gl846.cc genesys_gl846.h genesys_gl847.cc genesys_gl847.h genesys_gl124.cc genesys_gl124.h genesys_low.cc genesys_low.h
libgenesys_la_SOURCES = genesys.cc genesys.h genesys_sanei.h genesys_sanei.cc genesys_error.h genesys_error.cc \
genesys_gl646.cc genesys_gl646.h genesys_gl841.cc genesys_gl841.h \
genesys_gl843.cc genesys_gl843.h genesys_gl846.cc genesys_gl846.h \
genesys_gl847.cc genesys_gl847.h genesys_gl124.cc genesys_gl124.h \
genesys_low.cc genesys_low.h
libgenesys_la_CPPFLAGS = $(AM_CPPFLAGS) -DBACKEND_NAME=genesys
nodist_libsane_genesys_la_SOURCES = genesys-s.cc
+50 -66
View File
@@ -61,6 +61,7 @@
#define DEBUG_NOT_STATIC
#include "genesys.h"
#include "genesys_sanei.h"
#include "../include/sane/sanei_config.h"
#include "../include/sane/sanei_magic.h"
#include "genesys_devices.cc"
@@ -944,7 +945,7 @@ genesys_send_offset_and_shading (Genesys_Device * dev, const Genesys_Sensor& sen
{
int dpihw;
int start_address;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s: (size = %d)\n", __func__, size);
@@ -1019,7 +1020,7 @@ SANE_Status
sanei_genesys_init_shading_data (Genesys_Device * dev, const Genesys_Sensor& sensor,
int pixels_per_line)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int channels;
int i;
@@ -1446,7 +1447,7 @@ static SANE_Status genesys_coarse_calibration(Genesys_Device * dev, Genesys_Sens
int black_pixels;
int white_average;
int channels;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t offset[4] = { 0xa0, 0x00, 0xa0, 0x40 }; /* first value isn't used */
uint16_t white[12], dark[12];
int i, j;
@@ -1758,7 +1759,7 @@ genesys_average_data (uint8_t * average_data,
static SANE_Status
genesys_dark_shading_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
size_t size;
uint32_t pixels_per_line;
uint8_t channels;
@@ -1958,7 +1959,7 @@ genesys_dummy_dark_shading (Genesys_Device * dev, const Genesys_Sensor& sensor)
static SANE_Status
genesys_white_shading_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
size_t size;
uint32_t pixels_per_line;
uint8_t channels;
@@ -2087,7 +2088,7 @@ genesys_white_shading_calibration (Genesys_Device * dev, const Genesys_Sensor& s
static SANE_Status
genesys_dark_white_shading_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
size_t size;
uint32_t pixels_per_line;
uint8_t *average_white, *average_dark;
@@ -2736,7 +2737,7 @@ compute_shifted_coefficients (Genesys_Device * dev,
static SANE_Status
genesys_send_shading_coefficient(Genesys_Device * dev, const Genesys_Sensor& sensor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint32_t pixels_per_line;
uint8_t channels;
int o;
@@ -3133,7 +3134,7 @@ genesys_save_calibration (Genesys_Device * dev, const Genesys_Sensor& sensor)
static SANE_Status
genesys_flatbed_calibration(Genesys_Device * dev, Genesys_Sensor& sensor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint32_t pixels_per_line;
int yres;
@@ -3566,7 +3567,7 @@ static SANE_Status
genesys_wait_not_moving (Genesys_Device * dev, int mseconds)
{
uint8_t value;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s: waiting %d mseconds for motor to stop\n", __func__, mseconds);
while (mseconds > 0)
@@ -3735,7 +3736,7 @@ genesys_warmup_lamp (Genesys_Device * dev)
static SANE_Status
genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
unsigned int steps, expected;
SANE_Bool empty;
@@ -4068,7 +4069,7 @@ static SANE_Status accurate_line_read(Genesys_Device * dev,
{
buffer.reset();
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
status = dev->model->cmd_set->bulk_read_data(dev, 0x45, buffer.get_write_pos(buffer.size()),
buffer.size());
if (status != SANE_STATUS_GOOD)
@@ -4092,7 +4093,7 @@ static SANE_Status
genesys_fill_line_interp_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, size_t size)
{
size_t count;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
/* fill buffer if needed */
if (dev->oe_buffer.avail() == 0)
@@ -4156,7 +4157,7 @@ static SANE_Status
genesys_fill_segmented_buffer (Genesys_Device * dev, uint8_t *work_buffer_dst, size_t size)
{
size_t count;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int depth,i,n,k;
depth = dev->settings.depth;
@@ -4254,7 +4255,7 @@ genesys_fill_read_buffer (Genesys_Device * dev)
{
size_t size;
size_t space;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t *work_buffer_dst;
DBGSTART;
@@ -4348,7 +4349,7 @@ static SANE_Status
genesys_read_ordered_data (Genesys_Device * dev, SANE_Byte * destination,
size_t * len)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
size_t bytes, extra;
unsigned int channels, depth, src_pixels;
unsigned int ccd_shift[12], shift_count;
@@ -5180,7 +5181,7 @@ static SANE_Status
init_options (Genesys_Scanner * s)
{
SANE_Int option, count, min_dpi;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
SANE_Word *dpi_list;
Genesys_Model *model = s->dev->model;
SANE_Range *x_range, *y_range;
@@ -5792,9 +5793,9 @@ check_present (SANE_String_Const devname) noexcept
static SANE_Status
attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
{
DBG_HELPER(dbg);
Genesys_Device *dev = 0;
SANE_Int dn, vendor, product;
SANE_Status status;
unsigned int i;
@@ -5820,23 +5821,13 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
DBG(DBG_info, "%s: trying to open device `%s'\n", __func__, devname);
status = sanei_usb_open (devname, &dn);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_warn, "%s: couldn't open device `%s': %s\n", __func__, devname,
sane_strstatus (status));
return status;
}
else
UsbDevice usb_dev;
usb_dev.open(devname);
DBG(DBG_info, "%s: device `%s' successfully opened\n", __func__, devname);
status = sanei_usb_get_vendor_product (dn, &vendor, &product);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: couldn't get vendor and product ids of device `%s': %s\n", __func__,
devname, sane_strstatus (status));
return status;
}
int vendor, product;
usb_dev.get_vendor_product(vendor, product);
/* KV-SS080 is an auxiliary device which requires a master device to be here */
if(vendor == 0x04da && product == 0x100f)
@@ -5845,10 +5836,8 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
sanei_usb_find_devices (vendor, 0x1006, check_present);
sanei_usb_find_devices (vendor, 0x1007, check_present);
sanei_usb_find_devices (vendor, 0x1010, check_present);
if(present==SANE_FALSE)
{
DBG(DBG_error, "%s: master device not present\n", __func__);
return SANE_STATUS_INVAL;
if (present == SANE_FALSE) {
throw SaneException("master device not present");
}
}
@@ -5874,7 +5863,7 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
return SANE_STATUS_NO_MEM;
}
s_devices->push_back(Genesys_Device());
s_devices->emplace_back();
dev = &s_devices->back();
dev->file_name = new_devname;
@@ -5887,18 +5876,19 @@ attach (SANE_String_Const devname, Genesys_Device ** devp, SANE_Bool may_wait)
DBG(DBG_info, "%s: found %s flatbed scanner %s at %s\n", __func__, dev->model->vendor,
dev->model->model, dev->file_name);
if (devp)
*devp = dev;
sanei_usb_close (dn);
DBGCOMPLETED;
return SANE_STATUS_GOOD;
if (devp) {
*devp = dev;
}
usb_dev.close();
return SANE_STATUS_GOOD;
}
static SANE_Status
attach_one_device_impl(SANE_String_Const devname)
{
Genesys_Device *dev;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
RIE (attach (devname, &dev, SANE_FALSE));
@@ -5932,7 +5922,7 @@ static SANE_Status
probe_genesys_devices (void)
{
SANEI_Config config;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBGSTART;
@@ -6213,7 +6203,7 @@ genesys_buffer_image(Genesys_Scanner *s)
SANE_Status
sane_init_impl(SANE_Int * version_code, SANE_Auth_Callback authorize)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG_INIT ();
DBG(DBG_init, "SANE Genesys backend version %d.%d from %s\n",
@@ -6336,11 +6326,12 @@ SANE_Status sane_get_devices(const SANE_Device *** device_list, SANE_Bool local_
SANE_Status
sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle)
{
DBG_HELPER(dbg);
Genesys_Device *dev = nullptr;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
char *tmpstr;
DBG(DBG_proc, "%s: start (devicename = `%s')\n", __func__, devicename);
DBG(DBG_proc, "%s: devicename = `%s')\n", __func__, devicename);
/* devicename="" or devicename="genesys" are default values that use
* first available device
@@ -6386,13 +6377,9 @@ sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle)
DBG(DBG_error0, " scanner and what does (not) work.\n");
}
status = sanei_usb_open (dev->file_name, &dev->dn);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_warn, "%s: couldn't open device `%s': %s\n", __func__, dev->file_name,
sane_strstatus(status));
return status;
}
dbg.vstatus("open device '%s'", dev->file_name);
dev->usb_dev.open(dev->file_name);
dbg.clear();
s_scanners->push_back(Genesys_Scanner());
@@ -6442,8 +6429,7 @@ sane_open_impl(SANE_String_Const devicename, SANE_Handle * handle)
sanei_genesys_read_calibration (s->dev);
}
DBGCOMPLETED;
return SANE_STATUS_GOOD;
return SANE_STATUS_GOOD;
}
SANE_Status sane_open(SANE_String_Const devicename, SANE_Handle* handle)
@@ -6457,7 +6443,7 @@ SANE_Status sane_open(SANE_String_Const devicename, SANE_Handle* handle)
void
sane_close_impl(SANE_Handle handle)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBGSTART;
@@ -6522,15 +6508,13 @@ sane_close_impl(SANE_Handle handle)
/* LAMP OFF : same register across all the ASICs */
sanei_genesys_write_register (s->dev, 0x03, 0x00);
/* clear before closing */
sanei_usb_clear_halt (s->dev->dn);
catch_all_exceptions(__func__, [&](){ s->dev->usb_dev.clear_halt(); });
/* we need this to avoid these ASIC getting stuck
* in bulk writes */
sanei_usb_reset (s->dev->dn);
// we need this to avoid these ASIC getting stuck in bulk writes
catch_all_exceptions(__func__, [&](){ s->dev->usb_dev.reset(); });
sanei_usb_close (s->dev->dn);
// not freeing s->dev because it's in the dev list
// not freeing s->dev because it's in the dev list
catch_all_exceptions(__func__, [&](){ s->dev->usb_dev.close(); });
s_scanners->erase(it);
@@ -7250,7 +7234,7 @@ SANE_Status sane_control_option(SANE_Handle handle, SANE_Int option,
SANE_Status sane_get_parameters_impl(SANE_Handle handle, SANE_Parameters* params)
{
Genesys_Scanner *s = (Genesys_Scanner*) handle;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBGSTART;
+3 -3
View File
@@ -325,7 +325,7 @@ genesys_shrink_lines_1 (
static SANE_Status
genesys_crop(Genesys_Scanner *s)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Device *dev = s->dev;
int top = 0;
int bottom = 0;
@@ -375,7 +375,7 @@ genesys_crop(Genesys_Scanner *s)
static SANE_Status
genesys_deskew(Genesys_Scanner *s, const Genesys_Sensor& sensor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Device *dev = s->dev;
int x = 0, y = 0, bg;
@@ -440,7 +440,7 @@ genesys_despeck(Genesys_Scanner *s)
static SANE_Status
genesys_derotate (Genesys_Scanner * s)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int angle = 0;
DBGSTART;
+115
View File
@@ -0,0 +1,115 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
This file is part of the SANE package.
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., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE.
The exception is that, if you link a SANE library with other files
to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public
License. Your use of that executable is in no way restricted on
account of linking the SANE library code into it.
This exception does not, however, invalidate any other reasons why
the executable file might be covered by the GNU General Public
License.
If you submit changes to SANE to the maintainers to be included in
a subsequent release, you agree by submitting the changes that
those changes may be distributed with this exception intact.
If you write modifications of your own for SANE, it is your choice
whether to permit this exception to apply to your modifications.
If you do not wish that, delete this exception notice.
*/
#define DEBUG_DECLARE_ONLY
#include "genesys_error.h"
#include <cstdarg>
#include <cstdio>
extern "C" void sanei_debug_msg(int level, int max_level, const char *be, const char *fmt,
va_list ap);
#if (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
extern "C" char* __cxa_get_globals();
#endif
static unsigned num_uncaught_exceptions()
{
#if __cplusplus >= 201703L
int count = std::uncaught_exceptions();
return count >= 0 ? count : 0;
#elif (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
// the format of the __cxa_eh_globals struct is enshrined into the Itanium C++ ABI and it's
// very unlikely we'll get issues referencing it directly
char* cxa_eh_globals_ptr = __cxa_get_globals();
return *reinterpret_cast<unsigned*>(cxa_eh_globals_ptr + sizeof(void*));
#else
return std::uncaught_exception() ? 1 : 0;
#endif
}
DebugMessageHelper::DebugMessageHelper(const char* func)
{
func_ = func;
num_exceptions_on_enter_ = num_uncaught_exceptions();
msg_[0] = '\0';
DBG(DBG_proc, "%s: start\n", func_);
}
DebugMessageHelper::DebugMessageHelper(const char* func, const char* format, ...)
{
func_ = func;
num_exceptions_on_enter_ = num_uncaught_exceptions();
msg_[0] = '\0';
DBG(DBG_proc, "%s: start\n", func_);
DBG(DBG_proc, "%s: ", func_);
std::va_list args;
va_start(args, format);
sanei_debug_msg(DBG_proc, DBG_LEVEL, STRINGIFY(BACKEND_NAME), format, args);
va_end(args);
DBG(DBG_proc, "\n");
}
DebugMessageHelper::~DebugMessageHelper()
{
if (num_exceptions_on_enter_ < num_uncaught_exceptions()) {
if (msg_[0] != '\0') {
DBG(DBG_error, "%s: failed during %s\n", func_, msg_);
} else {
DBG(DBG_error, "%s: failed\n", func_);
}
} else {
DBG(DBG_proc, "%s: completed\n", func_);
}
}
void DebugMessageHelper::vstatus(const char* format, ...)
{
std::va_list args;
va_start(args, format);
std::vsnprintf(msg_, MAX_BUF_SIZE, format, args);
va_end(args);
}
+202
View File
@@ -0,0 +1,202 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
This file is part of the SANE package.
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., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE.
The exception is that, if you link a SANE library with other files
to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public
License. Your use of that executable is in no way restricted on
account of linking the SANE library code into it.
This exception does not, however, invalidate any other reasons why
the executable file might be covered by the GNU General Public
License.
If you submit changes to SANE to the maintainers to be included in
a subsequent release, you agree by submitting the changes that
those changes may be distributed with this exception intact.
If you write modifications of your own for SANE, it is your choice
whether to permit this exception to apply to your modifications.
If you do not wish that, delete this exception notice.
*/
#ifndef BACKEND_GENESYS_ERROR_H
#define BACKEND_GENESYS_ERROR_H
#include "../include/sane/config.h"
#include "../include/sane/sane.h"
#include "../include/sane/sanei_backend.h"
#include <stdexcept>
#include <cstring>
#include <string>
#define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */
#define DBG_error 1 /* fatal errors */
#define DBG_init 2 /* initialization and scanning time messages */
#define DBG_warn 3 /* warnings and non-fatal errors */
#define DBG_info 4 /* informational messages */
#define DBG_proc 5 /* starting/finishing functions */
#define DBG_io 6 /* io functions */
#define DBG_io2 7 /* io functions that are called very often */
#define DBG_data 8 /* log image data */
class SaneException : std::exception {
public:
SaneException(SANE_Status status) : status_(status)
{
set_msg(nullptr);
}
SaneException(SANE_Status status, const char* msg) : status_(status)
{
set_msg(msg);
}
SaneException(const char* msg) : SaneException(SANE_STATUS_INVAL, msg) {}
SANE_Status status() const { return status_; }
virtual const char* what() const noexcept override { return msg_.c_str(); }
private:
void set_msg(const char* msg)
{
const char* status_msg = sane_strstatus(status_);
std::size_t status_msg_len = std::strlen(status_msg);
if (msg) {
std::size_t msg_len = std::strlen(msg);
msg_.reserve(msg_len + status_msg_len + 3);
msg_ = msg;
msg_ += " : ";
msg_ += status_msg;
return;
}
msg_.reserve(status_msg_len);
msg_ = status_msg;
}
std::string msg_;
SANE_Status status_;
};
/**
* call a function and return on error
*/
#define RIE(function) \
do { status = function; \
if (status != SANE_STATUS_GOOD) \
{ \
DBG(DBG_error, "%s: %s\n", __func__, sane_strstatus (status)); \
return status; \
} \
} while (SANE_FALSE)
// call a function and throw an exception on error
#define TIE(function) \
do { \
SANE_Status tmp_status = function; \
if (tmp_status != SANE_STATUS_GOOD) { \
throw SaneException(tmp_status); \
} \
} while (false)
#define DBGSTART DBG (DBG_proc, "%s start\n", __func__);
#define DBGCOMPLETED DBG (DBG_proc, "%s completed\n", __func__);
class DebugMessageHelper {
public:
static constexpr unsigned MAX_BUF_SIZE = 120;
DebugMessageHelper(const char* func);
DebugMessageHelper(const char* func, const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 3, 4)))
#endif
;
~DebugMessageHelper();
void status(const char* msg) { vstatus("%s", msg); }
void vstatus(const char* format, ...)
#ifdef __GNUC__
__attribute__((format(printf, 2, 3)))
#endif
;
void clear() { msg_[0] = '\n'; }
private:
const char* func_ = nullptr;
char msg_[MAX_BUF_SIZE];
unsigned num_exceptions_on_enter_ = 0;
};
#define DBG_HELPER(var) DebugMessageHelper var(__func__)
#define DBG_HELPER_ARGS(var, ...) DebugMessageHelper var(__func__, __VA_ARGS__)
template<class F>
SANE_Status wrap_exceptions_to_status_code(const char* func, F&& function)
{
try {
return function();
} catch (const SaneException& exc) {
return exc.status();
} catch (const std::bad_alloc& exc) {
return SANE_STATUS_NO_MEM;
} catch (const std::exception& exc) {
DBG(DBG_error, "%s: got uncaught exception: %s\n", func, exc.what());
return SANE_STATUS_INVAL;
} catch (...) {
DBG(DBG_error, "%s: got unknown uncaught exception\n", func);
return SANE_STATUS_INVAL;
}
}
template<class F>
void catch_all_exceptions(const char* func, F&& function)
{
try {
function();
} catch (const SaneException& exc) {
DBG(DBG_error, "%s: got exception: %s\n", func, exc.what());
} catch (const std::bad_alloc& exc) {
DBG(DBG_error, "%s: got exception: could not allocate memory: %s\n", func, exc.what());
} catch (const std::exception& exc) {
DBG(DBG_error, "%s: got uncaught exception: %s\n", func, exc.what());
} catch (...) {
DBG(DBG_error, "%s: got unknown uncaught exception\n", func);
}
}
inline void wrap_status_code_to_exception(SANE_Status status)
{
if (status == SANE_STATUS_GOOD)
return;
throw SaneException(status);
}
#endif // BACKEND_GENESYS_ERROR_H
+18 -18
View File
@@ -497,7 +497,7 @@ static SANE_Status
gl124_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
@@ -630,7 +630,7 @@ static SANE_Status
gl124_set_fe(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBG(DBG_proc, "%s (%s)\n", __func__, set == AFE_INIT ? "init" : set == AFE_SET ? "set" : set ==
@@ -690,7 +690,7 @@ gl124_init_motor_regs_scan (Genesys_Device * dev,
ScanColorMode scan_mode,
unsigned int flags)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed;
unsigned int lincnt, fast_dpi;
uint16_t scan_table[SLOPE_TABLE_SIZE];
@@ -999,7 +999,7 @@ gl124_init_optical_regs_scan (Genesys_Device * dev,
unsigned int dpiset, cksel, dpihw, factor;
unsigned int bytes;
GenesysRegister *r;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint32_t expmax, exp;
DBG(DBG_proc, "%s : exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d, "
@@ -1275,7 +1275,7 @@ gl124_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys
SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */
unsigned optical_res;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, params);
@@ -1646,7 +1646,7 @@ gl124_start_action (Genesys_Device * dev)
static SANE_Status
gl124_stop_action (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val40, val;
unsigned int loop;
@@ -1736,7 +1736,7 @@ gl124_stop_action (Genesys_Device * dev)
static SANE_Status
gl124_setup_scan_gpio(Genesys_Device *dev, int resolution)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBGSTART;
@@ -1793,7 +1793,7 @@ gl124_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBGSTART;
@@ -1830,7 +1830,7 @@ static SANE_Status
gl124_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
SANE_Bool check_stop)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s (check_stop = %d)\n", __func__, check_stop);
if (reg == NULL)
@@ -1863,7 +1863,7 @@ gl124_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
static
SANE_Status gl124_rewind(Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t byte;
DBGSTART;
@@ -1905,7 +1905,7 @@ SANE_Status
gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
uint8_t val;
float resolution;
@@ -2072,7 +2072,7 @@ static SANE_Status
gl124_feed (Genesys_Device * dev, unsigned int steps, int reverse)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
float resolution;
uint8_t val;
@@ -2169,7 +2169,7 @@ static SANE_Status
gl124_search_start_position (Genesys_Device * dev)
{
int size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg = dev->reg;
int steps;
@@ -2277,7 +2277,7 @@ static SANE_Status
gl124_init_regs_for_coarse_calibration(Genesys_Device* dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t channels;
uint8_t cksel;
@@ -2339,7 +2339,7 @@ static SANE_Status
gl124_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int move, resolution, dpihw, factor;
DBGSTART;
@@ -2450,7 +2450,7 @@ gl124_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor)
int move_dpi;
float start;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, dev->settings);
@@ -3415,7 +3415,7 @@ gl124_init_memory_layout (Genesys_Device * dev)
static SANE_Status
gl124_init(Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG_INIT ();
DBGSTART;
@@ -3433,7 +3433,7 @@ gl124_init(Genesys_Device * dev)
static SANE_Status
gl124_boot (Genesys_Device * dev, SANE_Bool cold)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBGSTART;
+46 -101
View File
@@ -57,35 +57,28 @@
/**
* reads value from gpio endpoint
*/
static SANE_Status
gl646_gpio_read (SANE_Int dn, uint8_t * value)
static void gl646_gpio_read(UsbDevice& usb_dev, uint8_t* value)
{
return sanei_usb_control_msg (dn, REQUEST_TYPE_IN,
REQUEST_REGISTER, GPIO_READ, INDEX, 1, value);
DBG_HELPER(dbg);
usb_dev.control_msg(REQUEST_TYPE_IN, REQUEST_REGISTER, GPIO_READ, INDEX, 1, value);
}
/**
* writes the given value to gpio endpoint
*/
static SANE_Status
gl646_gpio_write (SANE_Int dn, uint8_t value)
static void gl646_gpio_write(UsbDevice& usb_dev, uint8_t value)
{
DBG(DBG_proc, "%s(0x%02x)\n", __func__, value);
return sanei_usb_control_msg (dn, REQUEST_TYPE_OUT,
REQUEST_REGISTER, GPIO_WRITE,
INDEX, 1, &value);
DBG_HELPER_ARGS(dbg, "(0x%02x)", value);
usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, GPIO_WRITE, INDEX, 1, &value);
}
/**
* writes the given value to gpio output enable endpoint
*/
static SANE_Status
gl646_gpio_output_enable (SANE_Int dn, uint8_t value)
static void gl646_gpio_output_enable(UsbDevice& usb_dev, uint8_t value)
{
DBG(DBG_proc, "%s(0x%02x)\n", __func__, value);
return sanei_usb_control_msg (dn, REQUEST_TYPE_OUT,
REQUEST_REGISTER, GPIO_OUTPUT_ENABLE,
INDEX, 1, &value);
DBG_HELPER_ARGS(dbg, "(0x%02x)", value);
usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, GPIO_OUTPUT_ENABLE, INDEX, 1, &value);
}
/* Read bulk data (e.g. scanned data) */
@@ -1046,7 +1039,7 @@ gl646_setup_sensor (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_
static SANE_Status
gl646_asic_test (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
size_t size, verify_size;
unsigned int i;
@@ -1354,7 +1347,7 @@ gl646_send_slope_table (Genesys_Device * dev, int table_nr,
{
int dpihw;
int start_address;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s (table_nr = %d, steps = %d)=%d .. %d\n", __func__, table_nr, steps,
slope_table[0], slope_table[steps - 1]);
@@ -1501,12 +1494,7 @@ gl646_wm_hp3670(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set,
DBG(DBG_error, "%s: writing reg2 failed: %s\n", __func__, sane_strstatus(status));
return status;
}
status = gl646_gpio_output_enable (dev->dn, 0x07);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to enable GPIO: %s\n", __func__, sane_strstatus(status));
return status;
}
gl646_gpio_output_enable(dev->usb_dev, 0x07);
break;
case AFE_POWER_SAVE:
status = sanei_genesys_fe_write_data (dev, 0x01, 0x06);
@@ -1586,7 +1574,7 @@ gl646_wm_hp3670(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set,
static SANE_Status
gl646_set_fe(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set, int dpi)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int i;
uint8_t val;
@@ -1635,12 +1623,7 @@ gl646_set_fe(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set, in
if (dev->model->ccd_type == CCD_HP2300)
{
val = 0x07;
status = gl646_gpio_output_enable (dev->dn, val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to enable GPIO: %s\n", __func__, sane_strstatus(status));
return status;
}
gl646_gpio_output_enable(dev->usb_dev, val);
}
return status;
}
@@ -1912,13 +1895,8 @@ gl646_load_document (Genesys_Device * dev)
count = 0;
do
{
status = gl646_gpio_read (dev->dn, &val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to read paper sensor %s\n", __func__,
sane_strstatus(status));
return status;
}
gl646_gpio_read(dev->usb_dev, &val);
DBG(DBG_info, "%s: GPIO=0x%02x\n", __func__, val);
if ((val & 0x04) != 0x04)
{
@@ -2048,7 +2026,7 @@ gl646_detect_document_end (Genesys_Device * dev)
{
print_status (val);
}
status = gl646_gpio_read (dev->dn, &gpio);
gl646_gpio_read(dev->usb_dev, &gpio);
DBG(DBG_info, "%s: GPIO=0x%02x\n", __func__, gpio);
/* detect document event. There one event when the document go in,
@@ -2121,13 +2099,9 @@ gl646_eject_document (Genesys_Device * dev)
/* at the end there will be noe more document */
dev->document = SANE_FALSE;
/* first check for document event */
status = gl646_gpio_read (dev->dn, &gpio);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to read paper sensor %s\n", __func__, sane_strstatus(status));
return status;
}
// first check for document event
gl646_gpio_read(dev->usb_dev, &gpio);
DBG(DBG_info, "%s: GPIO=0x%02x\n", __func__, gpio);
/* test status : paper event + HOMESNR -> no more doc ? */
@@ -2244,13 +2218,9 @@ gl646_eject_document (Genesys_Device * dev)
}
while (((state & REG41_HOMESNR) == 0) && (count < 150));
/* read GPIO on exit */
status = gl646_gpio_read (dev->dn, &gpio);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to read paper sensor %s\n", __func__, sane_strstatus(status));
return status;
}
// read GPIO on exit
gl646_gpio_read(dev->usb_dev, &gpio);
DBG(DBG_info, "%s: GPIO=0x%02x\n", __func__, gpio);
DBG(DBG_proc, "%s: end\n", __func__);
@@ -2263,7 +2233,7 @@ gl646_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re
SANE_Bool start_motor)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
// FIXME: SEQUENTIAL not really needed in this case
Genesys_Register_Set local_reg(Genesys_Register_Set::SEQUENTIAL);
@@ -2430,7 +2400,7 @@ static
SANE_Status
gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Settings settings;
uint8_t val;
int i;
@@ -2605,7 +2575,7 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
static SANE_Status
gl646_search_start_position (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Settings settings;
unsigned int resolution, x, y;
@@ -2826,7 +2796,7 @@ static bool gl646_needs_home_before_init_regs_for_scan(Genesys_Device* dev)
static SANE_Status
gl646_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBGSTART;
@@ -2981,7 +2951,7 @@ gl646_send_gamma_table (Genesys_Device * dev, const Genesys_Sensor& sensor)
{
int size;
int address;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int bits;
DBGSTART;
@@ -3869,7 +3839,7 @@ gl646_init_regs_for_warmup (Genesys_Device * dev,
static SANE_Status
gl646_repark_head (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Settings settings;
unsigned int expected, steps;
@@ -3947,7 +3917,7 @@ gl646_repark_head (Genesys_Device * dev)
static SANE_Status
gl646_init (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
struct timeval tv;
uint8_t cold = 0, val = 0;
uint32_t addr = 0xdead;
@@ -3998,10 +3968,9 @@ gl646_init (Genesys_Device * dev)
if (cold)
{
DBG(DBG_info, "%s: device is cold\n", __func__);
val = 0x04;
RIE (sanei_usb_control_msg
(dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_INIT,
INDEX, 1, &val));
val = 0x04;
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_INIT, INDEX, 1, &val);
/* ASIC reset */
RIE (sanei_genesys_write_register (dev, 0x0e, 0x00));
@@ -4038,31 +4007,15 @@ gl646_init (Genesys_Device * dev)
sanei_genesys_write_register (dev, 0x68, dev->gpo.enable[0]);
sanei_genesys_write_register (dev, 0x69, dev->gpo.enable[1]);
/* enable GPIO */
val = 6;
status = gl646_gpio_output_enable (dev->dn, val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: GPO enable failed ... %s\n", __func__, sane_strstatus(status));
return status;
}
val = 0;
// enable GPIO
gl646_gpio_output_enable(dev->usb_dev, 6);
/* writes 0 to GPIO */
status = gl646_gpio_write (dev->dn, val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: GPO write failed ... %s\n", __func__, sane_strstatus(status));
return status;
}
// writes 0 to GPIO
gl646_gpio_write(dev->usb_dev, 0);
// clear GPIO enable
gl646_gpio_output_enable(dev->usb_dev, 0);
/* clear GPIO enable */
status = gl646_gpio_output_enable (dev->dn, val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: GPO disable failed ... %s\n", __func__, sane_strstatus(status));
return status;
}
sanei_genesys_write_register (dev, 0x66, 0x10);
sanei_genesys_write_register (dev, 0x66, 0x00);
sanei_genesys_write_register (dev, 0x66, 0x10);
@@ -4407,7 +4360,7 @@ simple_scan (Genesys_Device * dev, const Genesys_Sensor& sensor,
static SANE_Status
simple_move (Genesys_Device * dev, SANE_Int distance)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Settings settings;
DBG(DBG_proc, "%s: %d mm\n", __func__, distance);
@@ -4453,18 +4406,10 @@ gl646_update_hardware_sensors (Genesys_Scanner * session)
{
Genesys_Device *dev = session->dev;
uint8_t value;
SANE_Status status;
/* do what is needed to get a new set of events, but try to not loose
any of them.
*/
status = gl646_gpio_read (dev->dn, &value);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed to read GPIO %s\n", __func__, sane_strstatus(status));
return status;
}
DBG(DBG_io, "%s: GPIO=0x%02x\n", __func__, value);
// do what is needed to get a new set of events, but try to not loose any of them.
gl646_gpio_read(dev->usb_dev, &value);
DBG(DBG_io, "%s: GPIO=0x%02x\n", __func__, value);
// scan button
if (dev->model->buttons & GENESYS_HAS_SCAN_SW) {
@@ -4577,14 +4522,14 @@ gl646_update_hardware_sensors (Genesys_Scanner * session)
}
}
return status;
return SANE_STATUS_GOOD;
}
static SANE_Status
write_control (Genesys_Device * dev, const Genesys_Sensor& sensor, int resolution)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t control[4];
uint32_t addr = 0xdead;
+26 -26
View File
@@ -68,7 +68,7 @@
static SANE_Status
gl841_set_buffer_address_gamma (Genesys_Device * dev, uint32_t addr)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_io, "%s: setting address to 0x%05x\n", __func__, addr & 0xfffffff0);
@@ -308,7 +308,7 @@ static void sanei_gl841_setup_sensor(Genesys_Device * dev, const Genesys_Sensor&
static SANE_Status
sanei_gl841_asic_test (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
size_t size, verify_size;
unsigned int i;
@@ -761,7 +761,7 @@ gl841_send_slope_table (Genesys_Device * dev, int table_nr,
{
int dpihw;
int start_address;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
char msg[4000];
/*#ifdef WORDS_BIGENDIAN*/
int i;
@@ -1000,7 +1000,7 @@ static SANE_Status
gl841_set_fe(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int i;
DBG(DBG_proc, "%s (%s)\n", __func__,
@@ -1218,7 +1218,7 @@ gl841_init_motor_regs_off(Genesys_Register_Set * reg,
*/
static SANE_Status gl841_write_freq(Genesys_Device *dev, unsigned int ydpi)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
/**< fast table */
uint8_t tdefault[] = {0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0x36,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xb6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0xf6,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76,0x18,0x76};
uint8_t t1200[] = {0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc7,0x31,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc0,0x11,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0xc7,0xb1,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0x07,0xe0,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc7,0xf1,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc0,0x51,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0xc7,0x71,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20,0x07,0x20};
@@ -1268,7 +1268,7 @@ gl841_init_motor_regs(Genesys_Device * dev,
unsigned int action,
unsigned int flags)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
unsigned int fast_exposure;
int scan_power_mode;
int use_fast_fed = 0;
@@ -1436,7 +1436,7 @@ gl841_init_motor_regs_scan(Genesys_Device * dev, const Genesys_Sensor& sensor,
int scan_power_mode,
unsigned int flags)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
unsigned int fast_exposure;
int use_fast_fed = 0;
int dummy_power_mode;
@@ -1811,7 +1811,7 @@ gl841_init_optical_regs_scan(Genesys_Device * dev,
unsigned int end;
unsigned int dpiset;
GenesysRegister* r;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint16_t expavg, expr, expb, expg;
DBG(DBG_proc, "%s : exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d, "
@@ -2148,7 +2148,7 @@ gl841_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys
SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */
int optical_res;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
unsigned int oflags; /**> optical flags */
DBG(DBG_info, "%s ", __func__);
@@ -2772,7 +2772,7 @@ static SANE_Status
gl841_set_powersaving (Genesys_Device * dev,
int delay /* in minutes */ )
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
// FIXME: SEQUENTIAL not really needed in this case
Genesys_Register_Set local_reg(Genesys_Register_Set::SEQUENTIAL);
int rate, exposure_time, tgtime, time;
@@ -2852,7 +2852,7 @@ static SANE_Status
gl841_stop_action (Genesys_Device * dev)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val40, val;
unsigned int loop;
@@ -2929,7 +2929,7 @@ gl841_stop_action (Genesys_Device * dev)
static SANE_Status
gl841_get_paper_sensor(Genesys_Device * dev, SANE_Bool * paper_loaded)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
status = sanei_genesys_read_register(dev, REG6D, &val);
@@ -2946,7 +2946,7 @@ static SANE_Status
gl841_eject_document (Genesys_Device * dev)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
SANE_Bool paper_loaded;
unsigned int init_steps;
@@ -3105,7 +3105,7 @@ gl841_eject_document (Genesys_Device * dev)
static SANE_Status
gl841_load_document (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
SANE_Bool paper_loaded;
int loop = 300;
DBG(DBG_proc, "%s\n", __func__);
@@ -3226,7 +3226,7 @@ gl841_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re
SANE_Bool start_motor)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
// FIXME: SEQUENTIAL not really needed in this case
Genesys_Register_Set local_reg(Genesys_Register_Set::SEQUENTIAL);
uint8_t val;
@@ -3275,7 +3275,7 @@ static SANE_Status
gl841_end_scan (Genesys_Device * dev, Genesys_Register_Set __sane_unused__ * reg,
SANE_Bool check_stop)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s (check_stop = %d)\n", __func__, check_stop);
@@ -3303,7 +3303,7 @@ static SANE_Status
gl841_feed (Genesys_Device * dev, int steps)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
int loop;
@@ -3387,7 +3387,7 @@ static SANE_Status
gl841_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
uint8_t val;
int loop = 0;
@@ -3541,7 +3541,7 @@ static SANE_Status
gl841_search_start_position (Genesys_Device * dev)
{
int size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
int steps;
@@ -3652,7 +3652,7 @@ static SANE_Status
gl841_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t channels;
uint8_t cksel;
@@ -3716,7 +3716,7 @@ static SANE_Status
gl841_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
SANE_Int ydpi;
float starty=0;
@@ -3802,7 +3802,7 @@ gl841_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor)
int move_dpi;
float start;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, dev->settings);
@@ -3919,7 +3919,7 @@ static SANE_Status
gl841_send_gamma_table(Genesys_Device * dev, const Genesys_Sensor& sensor)
{
int size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBGSTART;
@@ -4927,7 +4927,7 @@ gl841_init_regs_for_warmup (Genesys_Device * dev,
static SANE_Status
sanei_gl841_repark_head (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s\n", __func__);
@@ -4995,7 +4995,7 @@ gl841_is_compatible_calibration (Genesys_Device * dev, const Genesys_Sensor& sen
static SANE_Status
gl841_init (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
size_t size;
@@ -5171,7 +5171,7 @@ gl841_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Bool forward, SANE_Bool black)
{
unsigned int pixels, lines, channels;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
size_t size;
int steps, depth, dpi;
+23 -23
View File
@@ -61,7 +61,7 @@
static SANE_Status
gl843_set_buffer_address (Genesys_Device * dev, uint32_t addr)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_io, "%s: setting address to 0x%05x\n", __func__, addr & 0xffff);
@@ -715,7 +715,7 @@ static SANE_Status
gl843_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
@@ -758,7 +758,7 @@ static SANE_Status
gl843_set_fe (Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
int i;
@@ -876,7 +876,7 @@ gl843_init_motor_regs_scan (Genesys_Device * dev,
int scan_power_mode,
unsigned int flags)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed, coeff;
unsigned int lincnt;
uint16_t scan_table[1024];
@@ -1099,7 +1099,7 @@ gl843_init_optical_regs_scan (Genesys_Device * dev,
unsigned int tgtime; /**> exposure time multiplier */
unsigned int cksel; /**> clock per system pixel time in capturing image */
GenesysRegister *r;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s : exposure=%d, used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d, "
"ccd_size_divisor=%d, flags=%x\n", __func__, exposure, used_res, start, pixels, channels,
@@ -1432,7 +1432,7 @@ static SANE_Status gl843_init_scan_regs(Genesys_Device* dev, const Genesys_Senso
int scan_power_mode = 0;
size_t requested_buffer_size, read_buffer_size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, session.params);
@@ -1750,7 +1750,7 @@ static SANE_Status
gl843_save_power (Genesys_Device * dev, SANE_Bool enable)
{
uint8_t val;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s: enable = %d\n", __func__, enable);
if (dev == NULL)
@@ -1804,7 +1804,7 @@ gl843_stop_action_no_move(Genesys_Device* dev, Genesys_Register_Set* reg)
static SANE_Status
gl843_stop_action (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val40, val;
unsigned int loop;
@@ -1881,7 +1881,7 @@ gl843_stop_action (Genesys_Device * dev)
static SANE_Status
gl843_get_paper_sensor (Genesys_Device * dev, SANE_Bool * paper_loaded)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
status = sanei_genesys_read_register (dev, REG6D, &val);
@@ -2177,7 +2177,7 @@ static SANE_Status
gl843_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Register_Set * reg,
SANE_Bool start_motor)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
uint16_t dpiset, dpihw;
@@ -2266,7 +2266,7 @@ static SANE_Status
gl843_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
SANE_Bool check_stop)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s (check_stop = %d)\n", __func__, check_stop);
if (reg == NULL)
@@ -2305,7 +2305,7 @@ gl843_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
uint8_t val;
int loop = 0;
@@ -2392,7 +2392,7 @@ static SANE_Status
gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
uint8_t val;
float resolution;
@@ -2542,7 +2542,7 @@ static SANE_Status
gl843_search_start_position (Genesys_Device * dev)
{
int size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
int steps;
@@ -2652,7 +2652,7 @@ static SANE_Status
gl843_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t channels;
uint8_t cksel;
@@ -2720,7 +2720,7 @@ static SANE_Status
gl843_feed (Genesys_Device * dev, unsigned int steps)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
float resolution;
uint8_t val;
@@ -2817,7 +2817,7 @@ static SANE_Status
gl843_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int move, resolution, dpihw, factor;
uint16_t strpixel;
@@ -2933,7 +2933,7 @@ gl843_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor)
int move_dpi;
float start;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, dev->settings);
@@ -3014,7 +3014,7 @@ static SANE_Status
gl843_send_gamma_table(Genesys_Device* dev, const Genesys_Sensor& sensor)
{
int size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int i;
DBGSTART;
@@ -3819,7 +3819,7 @@ gl843_init_gpio (Genesys_Device * dev)
static SANE_Status
gl843_boot (Genesys_Device * dev, SANE_Bool cold)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBGSTART;
@@ -3922,7 +3922,7 @@ gl843_boot (Genesys_Device * dev, SANE_Bool cold)
static SANE_Status
gl843_init (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG_INIT ();
DBGSTART;
@@ -4005,7 +4005,7 @@ gl843_search_strip (Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Bool forward, SANE_Bool black)
{
unsigned int pixels, lines, channels;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
size_t size;
int steps, depth, dpi;
@@ -4264,7 +4264,7 @@ static SANE_Status
gl843_send_shading_data (Genesys_Device * dev, const Genesys_Sensor& sensor,
uint8_t * data, int size)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint32_t final_size, length, i;
uint8_t *buffer;
int count,offset;
+17 -17
View File
@@ -430,7 +430,7 @@ static SANE_Status
gl846_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
@@ -560,7 +560,7 @@ static SANE_Status
gl846_set_fe(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s (%s)\n", __func__, set == AFE_INIT ? "init" : set == AFE_SET ? "set" :
set == AFE_POWER_SAVE ? "powersave" : "huh?");
@@ -597,7 +597,7 @@ gl846_init_motor_regs_scan (Genesys_Device * dev,
int scan_power_mode,
unsigned int flags)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed;
unsigned int fast_dpi;
uint16_t scan_table[SLOPE_TABLE_SIZE];
@@ -859,7 +859,7 @@ gl846_init_optical_regs_scan (Genesys_Device * dev,
unsigned int dpiset, dpihw,segnb,cksel,factor;
unsigned int bytes;
GenesysRegister *r;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s : exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d, "
"half_ccd=%d, flags=%x\n", __func__, exposure_time, used_res, start, pixels, channels, depth,
@@ -1120,7 +1120,7 @@ gl846_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys
SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */
int optical_res;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, params);
@@ -1488,7 +1488,7 @@ gl846_start_action (Genesys_Device * dev)
static SANE_Status
gl846_stop_action (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val40, val;
unsigned int loop;
@@ -1568,7 +1568,7 @@ gl846_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re
SANE_Bool start_motor)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
GenesysRegister *r;
@@ -1611,7 +1611,7 @@ static SANE_Status
gl846_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
SANE_Bool check_stop)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s (check_stop = %d)\n", __func__, check_stop);
if (reg == NULL)
@@ -1640,7 +1640,7 @@ static SANE_Status
gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
float resolution;
uint8_t val;
@@ -1797,7 +1797,7 @@ static SANE_Status
gl846_search_start_position (Genesys_Device * dev)
{
int size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
int steps;
@@ -1909,7 +1909,7 @@ static SANE_Status
gl846_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t channels;
uint8_t cksel;
@@ -1972,7 +1972,7 @@ static SANE_Status
gl846_feed (Genesys_Device * dev, unsigned int steps)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
float resolution;
uint8_t val;
@@ -2072,7 +2072,7 @@ static SANE_Status
gl846_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
float move;
DBGSTART;
@@ -2149,7 +2149,7 @@ gl846_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor)
int move_dpi;
float start;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, dev->settings);
@@ -2619,7 +2619,7 @@ gl846_init_memory_layout (Genesys_Device * dev)
static SANE_Status
gl846_boot (Genesys_Device * dev, SANE_Bool cold)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBGSTART;
@@ -2691,7 +2691,7 @@ gl846_boot (Genesys_Device * dev, SANE_Bool cold)
*/
static SANE_Status gl846_init(Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG_INIT ();
DBGSTART;
@@ -2743,7 +2743,7 @@ gl846_search_strip(Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Bool forward, SANE_Bool black)
{
unsigned int pixels, lines, channels;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
size_t size;
int steps, depth, dpi;
+18 -18
View File
@@ -450,7 +450,7 @@ static SANE_Status
gl847_send_slope_table (Genesys_Device * dev, int table_nr,
uint16_t * slope_table, int steps)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int i;
char msg[10000];
@@ -593,7 +593,7 @@ gl847_set_fe(Genesys_Device * dev, const Genesys_Sensor& sensor, uint8_t set)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBG(DBG_proc, "%s (%s)\n", __func__, set == AFE_INIT ? "init" : set == AFE_SET ? "set" : set ==
@@ -631,7 +631,7 @@ gl847_init_motor_regs_scan (Genesys_Device * dev,
int scan_power_mode,
unsigned int flags)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int use_fast_fed;
unsigned int fast_dpi;
uint16_t scan_table[SLOPE_TABLE_SIZE];
@@ -874,7 +874,7 @@ gl847_init_optical_regs_scan (Genesys_Device * dev,
unsigned int dpiset, dpihw,segnb,cksel,factor;
unsigned int bytes;
GenesysRegister *r;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s : exposure_time=%d, used_res=%d, start=%d, pixels=%d, channels=%d, depth=%d, "
"half_ccd=%d, flags=%x\n", __func__, exposure_time, used_res, start, pixels, channels, depth,
@@ -1137,7 +1137,7 @@ gl847_init_scan_regs(Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys
SANE_Bool half_ccd; /* false: full CCD res is used, true, half max CCD res is used */
int optical_res;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, params);
@@ -1506,7 +1506,7 @@ gl847_start_action (Genesys_Device * dev)
static SANE_Status
gl847_stop_action (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val40, val;
unsigned int loop;
@@ -1586,7 +1586,7 @@ gl847_begin_scan (Genesys_Device * dev, const Genesys_Sensor& sensor, Genesys_Re
SANE_Bool start_motor)
{
(void) sensor;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
GenesysRegister *r;
@@ -1631,7 +1631,7 @@ static SANE_Status
gl847_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
SANE_Bool check_stop)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_proc, "%s (check_stop = %d)\n", __func__, check_stop);
if (reg == NULL)
@@ -1664,7 +1664,7 @@ gl847_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg,
static
SANE_Status gl847_rewind(Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t byte;
DBGSTART;
@@ -1705,7 +1705,7 @@ SANE_Status
gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
float resolution;
uint8_t val;
@@ -1863,7 +1863,7 @@ static SANE_Status
gl847_search_start_position (Genesys_Device * dev)
{
int size;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
int steps;
@@ -1975,7 +1975,7 @@ static SANE_Status
gl847_init_regs_for_coarse_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t channels;
uint8_t cksel;
@@ -2039,7 +2039,7 @@ static SANE_Status
gl847_feed (Genesys_Device * dev, unsigned int steps)
{
Genesys_Register_Set local_reg;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
GenesysRegister *r;
float resolution;
uint8_t val;
@@ -2138,7 +2138,7 @@ static SANE_Status
gl847_init_regs_for_shading(Genesys_Device * dev, const Genesys_Sensor& sensor,
Genesys_Register_Set& regs)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
float move;
DBGSTART;
@@ -2215,7 +2215,7 @@ gl847_init_regs_for_scan (Genesys_Device * dev, const Genesys_Sensor& sensor)
int move_dpi;
float start;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG(DBG_info, "%s ", __func__);
debug_dump(DBG_info, dev->settings);
@@ -2734,7 +2734,7 @@ gl847_init_memory_layout (Genesys_Device * dev)
static SANE_Status
gl847_boot (Genesys_Device * dev, SANE_Bool cold)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
DBGSTART;
@@ -2793,7 +2793,7 @@ gl847_boot (Genesys_Device * dev, SANE_Bool cold)
*/
static SANE_Status gl847_init (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBG_INIT ();
DBGSTART;
@@ -2851,7 +2851,7 @@ gl847_search_strip (Genesys_Device * dev, const Genesys_Sensor& sensor,
SANE_Bool forward, SANE_Bool black)
{
unsigned int pixels, lines, channels;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set local_reg;
size_t size;
int steps, depth, dpi;
+100 -255
View File
@@ -217,9 +217,9 @@ extern unsigned sanei_genesys_get_bulk_max_size(Genesys_Device * dev)
return 0xf000;
}
SANE_Status sanei_genesys_bulk_read_data_send_header(Genesys_Device* dev, size_t len)
void sanei_genesys_bulk_read_data_send_header(Genesys_Device* dev, size_t len)
{
SANE_Status status;
DBG_HELPER(dbg);
uint8_t outdata[8];
if (dev->model->asic_type == GENESYS_GL124 ||
@@ -250,22 +250,16 @@ SANE_Status sanei_genesys_bulk_read_data_send_header(Genesys_Device* dev, size_t
outdata[6] = ((len >> 16) & 0xff);
outdata[7] = ((len >> 24) & 0xff);
status = sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, 0x00, sizeof(outdata), outdata);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s failed while writing command: %s\n",
__func__, sane_strstatus (status));
return status;
}
return SANE_STATUS_GOOD;
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_BUFFER, 0x00,
sizeof(outdata), outdata);
}
SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
size_t len)
{
DBG_HELPER(dbg);
// currently supported: GL646, GL841, GL843, GL846, GL847, GL124
SANE_Status status;
size_t size, target;
uint8_t *buffer;
@@ -289,13 +283,8 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
return SANE_STATUS_GOOD;
if (is_addr_used) {
status = sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_SET_REGISTER, 0x00, 1, &addr);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s failed while setting register: %s\n", __func__,
sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_SET_REGISTER, 0x00,
1, &addr);
}
target = len;
@@ -304,9 +293,7 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
size_t max_in_size = sanei_genesys_get_bulk_max_size(dev);
if (!has_header_before_each_chunk) {
status = sanei_genesys_bulk_read_data_send_header(dev, len);
if (status != SANE_STATUS_GOOD)
return status;
sanei_genesys_bulk_read_data_send_header(dev, len);
}
// loop until computed data size is read
@@ -318,20 +305,12 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
}
if (has_header_before_each_chunk) {
status = sanei_genesys_bulk_read_data_send_header(dev, size);
if (status != SANE_STATUS_GOOD)
return status;
sanei_genesys_bulk_read_data_send_header(dev, size);
}
DBG(DBG_io2, "%s: trying to read %lu bytes of data\n", __func__, (u_long) size);
status = sanei_usb_read_bulk(dev->dn, data, &size);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s failed while reading bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
dev->usb_dev.bulk_read(data, &size);
DBG(DBG_io2, "%s: read %lu bytes, %lu remaining\n", __func__,
(u_long) size, (u_long) (target - size));
@@ -344,28 +323,23 @@ SANE_Status sanei_genesys_bulk_read_data(Genesys_Device * dev, uint8_t addr, uin
fwrite(buffer, len, 1, dev->binary);
}
DBGCOMPLETED;
return SANE_STATUS_GOOD;
}
SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, uint8_t* data,
size_t len)
{
DBG_HELPER(dbg);
// supported: GL646, GL841, GL843
SANE_Status status;
size_t size;
uint8_t outdata[8];
DBGSTART;
DBG(DBG_io, "%s writing %lu bytes\n", __func__, (u_long) len);
status = sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_SET_REGISTER, INDEX, 1, &addr);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s failed while setting register: %s\n", __func__, sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_SET_REGISTER, INDEX,
1, &addr);
size_t max_out_size = sanei_genesys_get_bulk_max_size(dev);
@@ -392,20 +366,10 @@ SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, ui
outdata[6] = ((size >> 16) & 0xff);
outdata[7] = ((size >> 24) & 0xff);
status = sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, 0x00, sizeof (outdata), outdata);
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_BUFFER, 0x00,
sizeof(outdata), outdata);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s failed while writing command: %s\n", __func__, sane_strstatus(status));
return status;
}
status = sanei_usb_write_bulk (dev->dn, data, &size);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s failed while writing bulk data: %s\n", __func__,
sane_strstatus(status));
return status;
}
dev->usb_dev.bulk_write(data, &size);
DBG(DBG_io2, "%s: wrote %lu bytes, %lu remaining\n", __func__, (u_long) size,
(u_long) (len - size));
@@ -414,8 +378,7 @@ SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, ui
data += size;
}
DBGCOMPLETED;
return status;
return SANE_STATUS_GOOD;
}
/** @brief write to one high (addr >= 0x100) register
@@ -427,24 +390,20 @@ SANE_Status sanei_genesys_bulk_write_data(Genesys_Device * dev, uint8_t addr, ui
SANE_Status
sanei_genesys_write_hregister (Genesys_Device * dev, uint16_t reg, uint8_t val)
{
SANE_Status status;
DBG_HELPER(dbg);
uint8_t buffer[2];
buffer[0]=reg & 0xff;
buffer[1]=val;
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
0x100 | VALUE_SET_REGISTER, INDEX, 2, buffer);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x, 0x%02x): failed : %s\n", __func__, reg, val,
sane_strstatus(status));
return status;
}
DBG(DBG_io, "%s (0x%02x, 0x%02x) completed\n", __func__, reg, val);
return status;
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_BUFFER, 0x100 | VALUE_SET_REGISTER, INDEX,
2, buffer);
DBG(DBG_io, "%s (0x%02x, 0x%02x) completed\n", __func__, reg, val);
return SANE_STATUS_GOOD;
}
/** @brief read from one high (addr >= 0x100) register
@@ -457,18 +416,13 @@ sanei_genesys_write_hregister (Genesys_Device * dev, uint16_t reg, uint8_t val)
SANE_Status
sanei_genesys_read_hregister (Genesys_Device * dev, uint16_t reg, uint8_t * val)
{
SANE_Status status;
DBG_HELPER(dbg);
SANE_Byte value[2];
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_IN, REQUEST_BUFFER,
0x100 | VALUE_GET_REGISTER, 0x22+((reg & 0xff)<<8), 2, value);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x): failed while reading register: %s\n", __func__, reg,
sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_IN, REQUEST_BUFFER, 0x100 | VALUE_GET_REGISTER,
0x22+((reg & 0xff)<<8), 2, value);
*val=value[0];
DBG(DBG_io2, "%s(0x%02x)=0x%02x\n", __func__, reg, *val);
@@ -476,9 +430,9 @@ sanei_genesys_read_hregister (Genesys_Device * dev, uint16_t reg, uint8_t * val)
if((value[1] & 0xff) != 0x55)
{
DBG(DBG_error,"%s: invalid read, scanner unplugged ?\n", __func__);
status=SANE_STATUS_IO_ERROR;
return SANE_STATUS_IO_ERROR;
}
return status;
return SANE_STATUS_GOOD;
}
/**
@@ -488,24 +442,19 @@ URB 10 control 0x40 0x04 0x83 0x00 len 2 wrote 0xa6 0x04
static SANE_Status
sanei_genesys_write_gl847_register (Genesys_Device * dev, uint8_t reg, uint8_t val)
{
SANE_Status status;
DBG_HELPER(dbg);
uint8_t buffer[2];
buffer[0]=reg;
buffer[1]=val;
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_SET_REGISTER, INDEX, 2, buffer);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x, 0x%02x): failed : %s\n", __func__, reg, val,
sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_SET_REGISTER, INDEX,
2, buffer);
DBG(DBG_io, "%s (0x%02x, 0x%02x) completed\n", __func__, reg, val);
return status;
return SANE_STATUS_GOOD;
}
/**
@@ -514,7 +463,8 @@ sanei_genesys_write_gl847_register (Genesys_Device * dev, uint8_t reg, uint8_t v
SANE_Status
sanei_genesys_write_register (Genesys_Device * dev, uint16_t reg, uint8_t val)
{
SANE_Status status;
DBG_HELPER(dbg);
SANE_Byte reg8;
/* 16 bit register address space */
@@ -533,29 +483,16 @@ sanei_genesys_write_register (Genesys_Device * dev, uint16_t reg, uint8_t val)
}
reg8=reg & 0xff;
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_SET_REGISTER, INDEX, 1, &reg8);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x, 0x%02x): failed while setting register: %s\n", __func__, reg, val,
sane_strstatus(status));
return status;
}
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_WRITE_REGISTER, INDEX, 1, &val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x, 0x%02x): failed while writing register value: %s\n", __func__,
reg, val, sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_SET_REGISTER, INDEX,
1, &reg8);
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_WRITE_REGISTER, INDEX,
1, &val);
DBG(DBG_io, "%s (0x%02x, 0x%02x) completed\n", __func__, reg, val);
return status;
return SANE_STATUS_GOOD;
}
/**
@@ -567,20 +504,12 @@ sanei_genesys_write_register (Genesys_Device * dev, uint16_t reg, uint8_t val)
* @param val value to write
*/
SANE_Status
sanei_genesys_write_0x8c (Genesys_Device * dev, uint8_t index, uint8_t val)
sanei_genesys_write_0x8c(Genesys_Device * dev, uint8_t index, uint8_t val)
{
SANE_Status status;
DBG(DBG_io, "%s: 0x%02x,0x%02x\n", __func__, index, val);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_BUF_ENDACCESS, index, 1, &val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed %s\n", __func__, sane_strstatus(status));
}
return status;
DBG_HELPER_ARGS(dbg, "0x%02x,0x%02x", index, val);
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_BUF_ENDACCESS, index,
1, &val);
return SANE_STATUS_GOOD;
}
/* read reg 0x41:
@@ -589,18 +518,13 @@ sanei_genesys_write_0x8c (Genesys_Device * dev, uint8_t index, uint8_t val)
static SANE_Status
sanei_genesys_read_gl847_register (Genesys_Device * dev, uint16_t reg, uint8_t * val)
{
SANE_Status status;
DBG_HELPER(dbg);
SANE_Status status = SANE_STATUS_GOOD;
SANE_Byte value[2];
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_IN, REQUEST_BUFFER,
VALUE_GET_REGISTER, 0x22+(reg<<8), 2, value);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x): failed while setting register: %s\n", __func__, reg,
sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_IN, REQUEST_BUFFER, VALUE_GET_REGISTER, 0x22+(reg<<8),
2, value);
*val=value[0];
DBG(DBG_io2, "%s(0x%02x)=0x%02x\n", __func__, reg, *val);
@@ -617,7 +541,8 @@ sanei_genesys_read_gl847_register (Genesys_Device * dev, uint16_t reg, uint8_t *
SANE_Status
sanei_genesys_read_register (Genesys_Device * dev, uint16_t reg, uint8_t * val)
{
SANE_Status status;
DBG_HELPER(dbg);
SANE_Byte reg8;
/* 16 bit register address space */
@@ -634,39 +559,26 @@ sanei_genesys_read_register (Genesys_Device * dev, uint16_t reg, uint8_t * val)
return sanei_genesys_read_gl847_register(dev, reg, val);
/* 8 bit register address space */
reg8=(SANE_Byte)(reg& 0Xff);
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_OUT, REQUEST_REGISTER,
VALUE_SET_REGISTER, INDEX, 1, &reg8);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x, 0x%02x): failed while setting register: %s\n", __func__,
reg, *val, sane_strstatus(status));
return status;
}
reg8=(SANE_Byte)(reg& 0Xff);
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_REGISTER, VALUE_SET_REGISTER, INDEX,
1, &reg8);
*val = 0;
status =
sanei_usb_control_msg (dev->dn, REQUEST_TYPE_IN, REQUEST_REGISTER,
VALUE_READ_REGISTER, INDEX, 1, val);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s (0x%02x, 0x%02x): failed while reading register value: %s\n", __func__,
reg, *val, sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_IN, REQUEST_REGISTER, VALUE_READ_REGISTER, INDEX,
1, val);
DBG(DBG_io, "%s (0x%02x, 0x%02x) completed\n", __func__, reg, *val);
return status;
return SANE_STATUS_GOOD;
}
/* Set address for writing data */
SANE_Status
sanei_genesys_set_buffer_address (Genesys_Device * dev, uint32_t addr)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
if(dev->model->asic_type==GENESYS_GL847
|| dev->model->asic_type==GENESYS_GL845
@@ -711,7 +623,7 @@ SANE_Status
sanei_genesys_fe_read_data (Genesys_Device * dev, uint8_t addr,
uint16_t *data)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t value;
Genesys_Register_Set reg;
@@ -752,7 +664,7 @@ SANE_Status
sanei_genesys_fe_write_data (Genesys_Device * dev, uint8_t addr,
uint16_t data)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
Genesys_Register_Set reg(Genesys_Register_Set::SEQUENTIAL);
DBG(DBG_io, "%s (0x%02x, 0x%04x)\n", __func__, addr, data);
@@ -855,7 +767,7 @@ genesys_dpiset (Genesys_Register_Set * reg)
SANE_Status
sanei_genesys_read_valid_words (Genesys_Device * dev, unsigned int *words)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t value;
DBGSTART;
@@ -918,7 +830,7 @@ sanei_genesys_read_valid_words (Genesys_Device * dev, unsigned int *words)
SANE_Status
sanei_genesys_read_scancnt (Genesys_Device * dev, unsigned int *words)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t value;
DBG(DBG_proc, "%s: start\n", __func__);
@@ -958,7 +870,7 @@ SANE_Status
sanei_genesys_test_buffer_empty (Genesys_Device * dev, SANE_Bool * empty)
{
uint8_t val = 0;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
sanei_genesys_sleep_ms(1);
status = sanei_genesys_get_status (dev, &val);
@@ -991,7 +903,7 @@ SANE_Status
sanei_genesys_read_data_from_scanner (Genesys_Device * dev, uint8_t * data,
size_t size)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
int time_count = 0;
unsigned int words = 0;
@@ -1037,7 +949,7 @@ sanei_genesys_read_data_from_scanner (Genesys_Device * dev, uint8_t * data,
SANE_Status
sanei_genesys_read_feed_steps (Genesys_Device * dev, unsigned int *steps)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t value;
DBG(DBG_proc, "%s\n", __func__);
@@ -1125,6 +1037,8 @@ void sanei_genesys_set_motor_power(Genesys_Register_Set& regs, bool set)
*/
SANE_Status sanei_genesys_bulk_write_register(Genesys_Device * dev, Genesys_Register_Set& reg)
{
DBG_HELPER(dbg);
SANE_Status status = SANE_STATUS_GOOD;
if (dev->model->asic_type == GENESYS_GL646 ||
@@ -1153,34 +1067,20 @@ SANE_Status sanei_genesys_bulk_write_register(Genesys_Device * dev, Genesys_Regi
outdata[6] = ((buffer.size() >> 16) & 0xff);
outdata[7] = ((buffer.size() >> 24) & 0xff);
status = sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_BUFFER, INDEX, sizeof(outdata), outdata);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s: failed while writing command: %s\n", __func__, sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_BUFFER, INDEX,
sizeof(outdata), outdata);
size_t write_size = buffer.size();
status = sanei_usb_write_bulk (dev->dn, buffer.data(), &write_size);
if (status != SANE_STATUS_GOOD) {
DBG(DBG_error, "%s: failed while writing bulk data: %s\n", __func__, sane_strstatus(status));
return status;
}
dev->usb_dev.bulk_write(buffer.data(), &write_size);
} else {
for (size_t i = 0; i < reg.size();) {
size_t c = reg.size() - i;
if (c > 32) /*32 is max on GL841. checked that.*/
c = 32;
status = sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER,
VALUE_SET_REGISTER, INDEX, c * 2,
buffer.data() + i * 2);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed while writing command: %s\n", __func__,
sane_strstatus(status));
return status;
}
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_SET_REGISTER,
INDEX, c * 2, buffer.data() + i * 2);
i += c;
}
@@ -1210,6 +1110,8 @@ SANE_Status sanei_genesys_bulk_write_register(Genesys_Device * dev, Genesys_Regi
SANE_Status
sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t size, uint8_t * data)
{
DBG_HELPER(dbg);
uint8_t outdata[8];
size_t written,blksize;
SANE_Status status = SANE_STATUS_GOOD;
@@ -1235,16 +1137,8 @@ sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t size, uint8
DBG (DBG_io, "%s: %s\n", __func__, msg);
}
/* write addr and size for AHB */
status =
sanei_usb_control_msg(dev->dn, REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_BUFFER,
0x01, 8, outdata);
if (status != SANE_STATUS_GOOD)
{
DBG(DBG_error, "%s: failed while setting addr and size: %s\n", __func__,
sane_strstatus(status));
return status;
}
// write addr and size for AHB
dev->usb_dev.control_msg(REQUEST_TYPE_OUT, REQUEST_BUFFER, VALUE_BUFFER, 0x01, 8, outdata);
size_t max_out_size = sanei_genesys_get_bulk_max_size(dev);
@@ -1260,14 +1154,8 @@ sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t size, uint8
{
blksize = size - written;
}
status = sanei_usb_write_bulk(dev->dn, data + written, &blksize);
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error,
"sanei_genesys_write_ahb: failed while writing bulk data: %s\n",
sane_strstatus (status));
return status;
}
dev->usb_dev.bulk_write(data + written, &blksize);
written += blksize;
}
while (written < size);
@@ -1371,7 +1259,7 @@ sanei_genesys_send_gamma_table(Genesys_Device * dev, const Genesys_Sensor& senso
int size;
int i;
uint8_t val;
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
DBGSTART;
@@ -1432,20 +1320,17 @@ sanei_genesys_send_gamma_table(Genesys_Device * dev, const Genesys_Sensor& senso
SANE_Status
sanei_genesys_asic_init(Genesys_Device* dev, int /*max_regs*/)
{
SANE_Status status;
DBG_HELPER(dbg);
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
SANE_Bool cold = SANE_TRUE;
DBGSTART;
/* URB 16 control 0xc0 0x0c 0x8e 0x0b len 1 read 0x00 */
status = sanei_usb_control_msg (dev->dn, REQUEST_TYPE_IN, REQUEST_REGISTER, VALUE_GET_REGISTER, 0x00, 1, &val);
if (status != SANE_STATUS_GOOD)
{
DBG (DBG_error, "%s: request register failed %s\n", __func__,
sane_strstatus (status));
return status;
}
// URB 16 control 0xc0 0x0c 0x8e 0x0b len 1 read 0x00 */
dev->usb_dev.control_msg(REQUEST_TYPE_IN, REQUEST_REGISTER, VALUE_GET_REGISTER, 0x00, 1, &val);
DBG (DBG_io2, "%s: value=0x%02x\n", __func__, val);
DBG (DBG_info, "%s: device is %s\n", __func__, (val & 0x08) ? "USB 1.0" : "USB2.0");
if (val & 0x08)
@@ -1503,8 +1388,7 @@ sanei_genesys_asic_init(Genesys_Device* dev, int /*max_regs*/)
/* Set powersaving (default = 15 minutes) */
RIE (dev->model->cmd_set->set_powersaving (dev, 15));
DBGCOMPLETED;
return status;
return status;
}
/**
@@ -1513,7 +1397,7 @@ sanei_genesys_asic_init(Genesys_Device* dev, int /*max_regs*/)
SANE_Status
sanei_genesys_wait_for_home (Genesys_Device * dev)
{
SANE_Status status;
SANE_Status status = SANE_STATUS_GOOD;
uint8_t val;
int loop;
int max=300;
@@ -2115,45 +1999,6 @@ void run_functions_at_backend_exit()
s_functions_run_at_backend_exit.release();
}
#if (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
extern "C" char* __cxa_get_globals();
#endif
static unsigned num_uncaught_exceptions()
{
#if __cplusplus >= 201703L
int count = std::uncaught_exceptions();
return count >= 0 ? count : 0;
#elif (defined(__GNUC__) || defined(__CLANG__)) && (defined(__linux__) || defined(__APPLE__))
// the format of the __cxa_eh_globals struct is enshrined into the Itanium C++ ABI and it's
// very unlikely we'll get issues referencing it directly
char* cxa_eh_globals_ptr = __cxa_get_globals();
return *reinterpret_cast<unsigned*>(cxa_eh_globals_ptr + sizeof(void*));
#else
return std::uncaught_exception() ? 1 : 0;
#endif
}
DebugMessageHelper::DebugMessageHelper(const char* func)
{
func_ = func;
num_exceptions_on_enter_ = num_uncaught_exceptions();
DBG(DBG_proc, "%s: start", func_);
}
DebugMessageHelper::~DebugMessageHelper()
{
if (num_exceptions_on_enter_ < num_uncaught_exceptions()) {
if (status_) {
DBG(DBG_error, "%s: failed during %s", func_, status_);
} else {
DBG(DBG_error, "%s: failed", func_);
}
} else {
DBG(DBG_proc, "%s: completed", func_);
}
}
void debug_dump(unsigned level, const Genesys_Settings& settings)
{
DBG(level, "settings:\n"
+4 -102
View File
@@ -81,6 +81,9 @@
#include "../include/_stdint.h"
#include "genesys_error.h"
#include "genesys_sanei.h"
#include <algorithm>
#include <array>
#include <cstring>
@@ -92,50 +95,6 @@
#include <string>
#include <vector>
#define DBG_error0 0 /* errors/warnings printed even with devuglevel 0 */
#define DBG_error 1 /* fatal errors */
#define DBG_init 2 /* initialization and scanning time messages */
#define DBG_warn 3 /* warnings and non-fatal errors */
#define DBG_info 4 /* informational messages */
#define DBG_proc 5 /* starting/finishing functions */
#define DBG_io 6 /* io functions */
#define DBG_io2 7 /* io functions that are called very often */
#define DBG_data 8 /* log image data */
class SaneException : std::exception {
public:
SaneException(SANE_Status status) : status_(status) {}
SANE_Status status() const { return status_; }
virtual const char* what() const noexcept override { return sane_strstatus(status_); }
private:
SANE_Status status_;
};
/**
* call a function and return on error
*/
#define RIE(function) \
do { status = function; \
if (status != SANE_STATUS_GOOD) \
{ \
DBG(DBG_error, "%s: %s\n", __func__, sane_strstatus (status)); \
return status; \
} \
} while (SANE_FALSE)
// call a function and throw an exception on error
#define TIE(function) \
do { \
SANE_Status tmp_status = function; \
if (tmp_status != SANE_STATUS_GOOD) { \
throw SaneException(tmp_status); \
} \
} while (false)
#define DBGSTART DBG (DBG_proc, "%s start\n", __func__);
#define DBGCOMPLETED DBG (DBG_proc, "%s completed\n", __func__);
#define FREE_IFNOT_NULL(x) if(x!=NULL) { free(x); x=NULL;}
#define GENESYS_RED 0
@@ -1332,7 +1291,7 @@ struct Genesys_Device
// frees commonly used data
void clear();
SANE_Int dn = 0;
UsbDevice usb_dev;
SANE_Word vendorId = 0; /**< USB vendor identifier */
SANE_Word productId = 0; /**< USB product identifier */
@@ -1854,63 +1813,6 @@ extern void sanei_genesys_usleep(unsigned int useconds);
// same as sanei_genesys_usleep just that the duration is in milliseconds
extern void sanei_genesys_sleep_ms(unsigned int milliseconds);
class DebugMessageHelper {
public:
DebugMessageHelper(const char* func);
~DebugMessageHelper();
void status(const char* status) { status_ = status; }
void clear() { status_ = nullptr; }
private:
const char* func_ = nullptr;
const char* status_ = nullptr;
unsigned num_exceptions_on_enter_ = 0;
};
#define DBG_HELPER(var) DebugMessageHelper var(__func__)
template<class F>
SANE_Status wrap_exceptions_to_status_code(const char* func, F&& function)
{
try {
return function();
} catch (const SaneException& exc) {
return exc.status();
} catch (const std::bad_alloc& exc) {
return SANE_STATUS_NO_MEM;
} catch (const std::exception& exc) {
DBG(DBG_error, "%s: got uncaught exception: %s\n", func, exc.what());
return SANE_STATUS_INVAL;
} catch (...) {
DBG(DBG_error, "%s: got unknown uncaught exception\n", func);
return SANE_STATUS_INVAL;
}
}
template<class F>
void catch_all_exceptions(const char* func, F&& function)
{
try {
function();
} catch (const SaneException& exc) {
DBG(DBG_error, "%s: got exception: %s\n", func, exc.what());
} catch (const std::bad_alloc& exc) {
DBG(DBG_error, "%s: got exception: could not allocate memory: %s\n", func, exc.what());
} catch (const std::exception& exc) {
DBG(DBG_error, "%s: got uncaught exception: %s\n", func, exc.what());
} catch (...) {
DBG(DBG_error, "%s: got unknown uncaught exception\n", func);
}
}
inline void wrap_status_code_to_exception(SANE_Status status)
{
if (status == SANE_STATUS_GOOD)
return;
throw SaneException(status);
}
void add_function_to_run_at_backend_exit(std::function<void()> function);
// calls functions added via add_function_to_run_at_backend_exit() in reverse order of being
+140
View File
@@ -0,0 +1,140 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
This file is part of the SANE package.
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., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE.
The exception is that, if you link a SANE library with other files
to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public
License. Your use of that executable is in no way restricted on
account of linking the SANE library code into it.
This exception does not, however, invalidate any other reasons why
the executable file might be covered by the GNU General Public
License.
If you submit changes to SANE to the maintainers to be included in
a subsequent release, you agree by submitting the changes that
those changes may be distributed with this exception intact.
If you write modifications of your own for SANE, it is your choice
whether to permit this exception to apply to your modifications.
If you do not wish that, delete this exception notice.
*/
#define DEBUG_DECLARE_ONLY
#include "genesys_sanei.h"
UsbDevice::~UsbDevice()
{
if (is_open()) {
DBG(DBG_error, "UsbDevice not closed; closing automatically");
close();
}
}
void UsbDevice::open(const char* dev_name)
{
DBG_HELPER(dbg);
if (is_open()) {
throw SaneException("device already open");
}
int device_num = 0;
dbg.status("open device");
TIE(sanei_usb_open(dev_name, &device_num));
name_ = dev_name;
device_num_ = device_num;
is_open_ = true;
}
void UsbDevice::clear_halt()
{
DBG_HELPER(dbg);
assert_is_open();
TIE(sanei_usb_clear_halt(device_num_));
}
void UsbDevice::reset()
{
DBG_HELPER(dbg);
assert_is_open();
TIE(sanei_usb_reset(device_num_));
}
void UsbDevice::close()
{
DBG_HELPER(dbg);
assert_is_open();
// we can't do much if closing fails, so we close the device on our side regardless of the
// function succeeds
int device_num = device_num_;
set_not_open();
sanei_usb_close(device_num);
}
void UsbDevice::get_vendor_product(int& vendor, int& product)
{
DBG_HELPER(dbg);
assert_is_open();
TIE(sanei_usb_get_vendor_product(device_num_, &vendor, &product));
}
void UsbDevice::control_msg(int rtype, int reg, int value, int index, int length, uint8_t* data)
{
DBG_HELPER(dbg);
assert_is_open();
TIE(sanei_usb_control_msg(device_num_, rtype, reg, value, index, length, data));
}
void UsbDevice::bulk_read(uint8_t* buffer, size_t* size)
{
DBG_HELPER(dbg);
assert_is_open();
TIE(sanei_usb_read_bulk(device_num_, buffer, size));
}
void UsbDevice::bulk_write(const uint8_t* buffer, size_t* size)
{
DBG_HELPER(dbg);
assert_is_open();
TIE(sanei_usb_write_bulk(device_num_, buffer, size));
}
void UsbDevice::assert_is_open() const
{
if (!is_open()) {
throw SaneException("device not open");
}
}
void UsbDevice::set_not_open()
{
device_num_ = 0;
is_open_ = false;
name_ = "";
}
+97
View File
@@ -0,0 +1,97 @@
/* sane - Scanner Access Now Easy.
Copyright (C) 2019 Povilas Kanapickas <povilas@radix.lt>
This file is part of the SANE package.
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., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA.
As a special exception, the authors of SANE give permission for
additional uses of the libraries contained in this release of SANE.
The exception is that, if you link a SANE library with other files
to produce an executable, this does not by itself cause the
resulting executable to be covered by the GNU General Public
License. Your use of that executable is in no way restricted on
account of linking the SANE library code into it.
This exception does not, however, invalidate any other reasons why
the executable file might be covered by the GNU General Public
License.
If you submit changes to SANE to the maintainers to be included in
a subsequent release, you agree by submitting the changes that
those changes may be distributed with this exception intact.
If you write modifications of your own for SANE, it is your choice
whether to permit this exception to apply to your modifications.
If you do not wish that, delete this exception notice.
*/
#ifndef BACKEND_GENESYS_SANEI_H
#define BACKEND_GENESYS_SANEI_H
#include "genesys_error.h"
#include "../include/sane/sanei_usb.h"
#include <cstdint>
#include <string>
class UsbDevice {
public:
UsbDevice() = default;
UsbDevice(const UsbDevice& other) = delete;
UsbDevice& operator=(const UsbDevice&) = delete;
UsbDevice(UsbDevice&& other) :
name_(other.name_),
is_open_(other.is_open_),
device_num_(other.device_num_)
{
other.set_not_open();
}
~UsbDevice();
bool is_open() const { return is_open_; }
int device_number() const { return device_num_; }
const std::string& name() const { return name_; }
void open(const char* dev_name);
void clear_halt();
void reset();
void close();
void get_vendor_product(int& vendor, int& product);
void control_msg(int rtype, int reg, int value, int index, int length, uint8_t* data);
void bulk_read(uint8_t* buffer, size_t* size);
void bulk_write(const uint8_t* buffer, size_t* size);
private:
void assert_is_open() const;
void set_not_open();
std::string name_;
bool is_open_ = false;
int device_num_ = 0;
};
#endif // BACKEND_GENESYS_SANEI_H