From d75aa89c9f12502cf30402da84a72c495db0be27 Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 20 Jul 2019 11:02:01 +0300 Subject: [PATCH] genesys: Return errors as exceptions from *slow_back_home() --- backend/genesys.cc | 39 ++++++++++++--------------------------- backend/genesys_gl124.cc | 14 +++++--------- backend/genesys_gl124.h | 3 +-- backend/genesys_gl646.cc | 33 ++++++++++++++------------------- backend/genesys_gl646.h | 4 +--- backend/genesys_gl841.cc | 28 +++++++++++++--------------- backend/genesys_gl843.cc | 30 +++++++++++++----------------- backend/genesys_gl846.cc | 22 ++++++++++------------ backend/genesys_gl846.h | 3 +-- backend/genesys_gl847.cc | 26 +++++++++++--------------- backend/genesys_low.cc | 4 ++-- backend/genesys_low.h | 2 +- 12 files changed, 84 insertions(+), 124 deletions(-) diff --git a/backend/genesys.cc b/backend/genesys.cc index 2d7bd74b5..2a4e5526b 100644 --- a/backend/genesys.cc +++ b/backend/genesys.cc @@ -1884,7 +1884,7 @@ static void genesys_repark_sensor_before_shading(Genesys_Device* dev) if (dev->model->cmd_set->rewind) { TIE(dev->model->cmd_set->rewind(dev)); } else { - TIE(dev->model->cmd_set->slow_back_home(dev, SANE_TRUE)); + dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); } if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || @@ -1987,7 +1987,7 @@ genesys_white_shading_calibration (Genesys_Device * dev, const Genesys_Sensor& s if (dev->model->flags & GENESYS_FLAG_SHADING_REPARK) { - status = dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); + dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); } return status; @@ -3684,13 +3684,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) } dev->parking = SANE_FALSE; - status = dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to move scanhead to home position: %s\n", __func__, - sane_strstatus(status)); - return status; - } + dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); dev->scanhead_position_in_steps = 0; } else @@ -3699,13 +3693,8 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) /* TODO: check we can drop this since we cannot have the scanner's head wandering here */ dev->parking = SANE_FALSE; - status = dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to move scanhead to home position: %s\n", __func__, - sane_strstatus(status)); - return status; - } + dev->model->cmd_set->slow_back_home (dev, SANE_TRUE); + dev->scanhead_position_in_steps = 0; } } @@ -3793,7 +3782,7 @@ genesys_start_scan (Genesys_Device * dev, SANE_Bool lamp_off) dev->model->cmd_set->needs_home_before_init_regs_for_scan(dev) && dev->model->cmd_set->slow_back_home) { - RIE(dev->model->cmd_set->slow_back_home(dev, SANE_TRUE)); + dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); } if (dev->settings.scan_method == ScanMethod::TRANSPARENCY || @@ -4293,7 +4282,7 @@ genesys_read_ordered_data (Genesys_Device * dev, SANE_Byte * destination, && !(dev->model->flags & GENESYS_FLAG_MUST_WAIT) && dev->parking == SANE_FALSE) { - dev->model->cmd_set->slow_back_home (dev, SANE_FALSE); + dev->model->cmd_set->slow_back_home(dev, SANE_FALSE); dev->parking = SANE_TRUE; } return SANE_STATUS_EOF; @@ -5956,7 +5945,7 @@ genesys_buffer_image(Genesys_Scanner *s) if (dev->model->is_sheetfed == SANE_FALSE && dev->parking == SANE_FALSE) { - dev->model->cmd_set->slow_back_home (dev, dev->model->flags & GENESYS_FLAG_MUST_WAIT); + dev->model->cmd_set->slow_back_home(dev, dev->model->flags & GENESYS_FLAG_MUST_WAIT); dev->parking = !(s->dev->model->flags & GENESYS_FLAG_MUST_WAIT); } @@ -7194,7 +7183,7 @@ sane_read_impl(SANE_Handle handle, SANE_Byte * buf, SANE_Int max_len, SANE_Int* && !(dev->model->flags & GENESYS_FLAG_MUST_WAIT) && dev->parking == SANE_FALSE) { - dev->model->cmd_set->slow_back_home (dev, SANE_FALSE); + dev->model->cmd_set->slow_back_home(dev, SANE_FALSE); dev->parking = SANE_TRUE; } return SANE_STATUS_EOF; @@ -7313,13 +7302,9 @@ void sane_cancel_impl(SANE_Handle handle) { if(s->dev->parking==SANE_FALSE) { - status = s->dev->model->cmd_set->slow_back_home (s->dev, s->dev->model->flags & GENESYS_FLAG_MUST_WAIT); - if (status != SANE_STATUS_GOOD) - { - DBG(DBG_error, "%s: failed to move scanhead to home position: %s\n", __func__, - sane_strstatus(status)); - return; - } + s->dev->model->cmd_set->slow_back_home (s->dev, s->dev->model->flags & + GENESYS_FLAG_MUST_WAIT); + s->dev->parking = !(s->dev->model->flags & GENESYS_FLAG_MUST_WAIT); } } diff --git a/backend/genesys_gl124.cc b/backend/genesys_gl124.cc index d888ee053..bef9b8de4 100644 --- a/backend/genesys_gl124.cc +++ b/backend/genesys_gl124.cc @@ -1732,9 +1732,7 @@ SANE_Status gl124_rewind(Genesys_Device * dev) * @param wait_until_home true to make the function waiting for head * to be home before returning, if fals returne immediately * @returns SANE_STATUS_GOO on success */ -static -SANE_Status -gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) +static void gl124_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home) { DBG_HELPER_ARGS(dbg, "wait_until_home = %d", wait_until_home); Genesys_Register_Set local_reg; @@ -1768,7 +1766,7 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG (DBG_info, "%s: already at home, completed\n", __func__); dev->scanhead_position_in_steps = 0; - return SANE_STATUS_GOOD; + return; } /* feed a little first */ @@ -1839,7 +1837,7 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG(DBG_info, "%s: reached home position\n", __func__); dev->scanhead_position_in_steps = 0; - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); ++loop; @@ -1847,12 +1845,10 @@ gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) /* when we come here then the scanner needed too much time for this, so we better stop the motor */ gl124_stop_action (dev); - DBG(DBG_error, "%s: timeout while waiting for scanhead to go home\n", __func__); - return SANE_STATUS_IO_ERROR; + throw SaneException(SANE_STATUS_IO_ERROR, "timeout while waiting for scanhead to go home"); } DBG(DBG_info, "%s: scanhead is still moving\n", __func__); - return SANE_STATUS_GOOD; } /** @brief moves the slider to steps at motor base dpi @@ -2907,7 +2903,7 @@ gl124_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor gl124_stop_action(dev); - status = gl124_slow_back_home (dev, SANE_TRUE); + gl124_slow_back_home(dev, SANE_TRUE); return status; } diff --git a/backend/genesys_gl124.h b/backend/genesys_gl124.h index 7febfa602..e3660a0ca 100644 --- a/backend/genesys_gl124.h +++ b/backend/genesys_gl124.h @@ -471,8 +471,7 @@ static void gl124_begin_scan(Genesys_Device* dev, const Genesys_Sensor& sensor, static SANE_Status gl124_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, SANE_Bool check_stop); -static SANE_Status -gl124_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home); +static void gl124_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home); static SANE_Status gl124_init(Genesys_Device * dev); static void gl124_send_shading_data(Genesys_Device* dev, const Genesys_Sensor& sensor, uint8_t* data, int size); diff --git a/backend/genesys_gl646.cc b/backend/genesys_gl646.cc index 0f2750262..45d03bdbb 100644 --- a/backend/genesys_gl646.cc +++ b/backend/genesys_gl646.cc @@ -2057,9 +2057,7 @@ gl646_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, * @param dev scanner's device * @param wait_until_home true if the function waits until head parked */ -static -SANE_Status -gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) +static void gl646_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home) { DBG_HELPER_ARGS(dbg, "wait_until_home = %d\n", wait_until_home); Genesys_Settings settings; @@ -2079,7 +2077,7 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) if (val & REG41_HOMESNR) /* is sensor at home? */ { DBG(DBG_info, "%s: end since already at home\n", __func__); - return SANE_STATUS_GOOD; + return; } /* stop motor if needed */ @@ -2099,15 +2097,14 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) if (((val & (REG41_MOTMFLG | REG41_HOMESNR)) == REG41_HOMESNR)) /* at home and motor is off */ { DBG(DBG_info, "%s: already at home and not moving\n", __func__); - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); } if (!i) /* the loop counted down to 0, scanner still is busy */ { - DBG(DBG_error, "%s: motor is still on: device busy\n", __func__); - return SANE_STATUS_DEVICE_BUSY; + throw SaneException(SANE_STATUS_DEVICE_BUSY, "motor is still on: device busy"); } /* setup for a backward scan of 65535 steps, with no actual data reading */ @@ -2149,7 +2146,7 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) if (dev->model->is_sheetfed == SANE_TRUE) { DBG(DBG_proc, "%s: end \n", __func__); - return SANE_STATUS_GOOD; + return; } // starts scan @@ -2167,23 +2164,21 @@ gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) DBG(DBG_info, "%s: reached home position\n", __func__); DBG(DBG_proc, "%s: end\n", __func__); sanei_genesys_sleep_ms(500); - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); ++loop; } - // when we come here then the scanner needed too much time for this, so we better stop the - // motor - gl646_stop_motor(dev); - end_scan(dev, &dev->reg, SANE_TRUE, SANE_FALSE); - DBG(DBG_error, "%s: timeout while waiting for scanhead to go home\n", __func__); - return SANE_STATUS_IO_ERROR; + // when we come here then the scanner needed too much time for this, so we better + // stop the motor + catch_all_exceptions(__func__, [&](){ gl646_stop_motor (dev); }); + catch_all_exceptions(__func__, [&](){ end_scan(dev, &dev->reg, SANE_TRUE, SANE_FALSE); }); + throw SaneException(SANE_STATUS_IO_ERROR, "timeout while waiting for scanhead to go home"); } DBG(DBG_info, "%s: scanhead is still moving\n", __func__); - return SANE_STATUS_GOOD; } /** @@ -3442,8 +3437,8 @@ gl646_repark_head (Genesys_Device * dev) } while (steps < expected); - /* toggle motor flag, put an huge step number and redo move backward */ - status = gl646_slow_back_home (dev, 1); + // toggle motor flag, put an huge step number and redo move backward + gl646_slow_back_home(dev, 1); return status; } @@ -3624,7 +3619,7 @@ gl646_init (Genesys_Device * dev) } else { - RIE (gl646_slow_back_home (dev, SANE_TRUE)); + gl646_slow_back_home(dev, SANE_TRUE); } } diff --git a/backend/genesys_gl646.h b/backend/genesys_gl646.h index b991d7763..686c61cdd 100644 --- a/backend/genesys_gl646.h +++ b/backend/genesys_gl646.h @@ -173,9 +173,7 @@ static SANE_Status gl646_save_power (Genesys_Device * dev, SANE_Bool enable); -static -SANE_Status -gl646_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home); +static void gl646_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home); static SANE_Status diff --git a/backend/genesys_gl841.cc b/backend/genesys_gl841.cc index 81d70d76e..0741d6aae 100644 --- a/backend/genesys_gl841.cc +++ b/backend/genesys_gl841.cc @@ -2886,9 +2886,8 @@ static void gl841_feed(Genesys_Device* dev, int steps) throw SaneException(SANE_STATUS_IO_ERROR, "timeout while waiting for scanhead to go home"); } -/* Moves the slider to the home (top) position slowly */ -static SANE_Status -gl841_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) +// Moves the slider to the home (top) position slowly +static void gl841_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home) { DBG_HELPER_ARGS(dbg, "wait_until_home = %d", wait_until_home); Genesys_Register_Set local_reg; @@ -2900,7 +2899,7 @@ gl841_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG(DBG_proc, "%s: there is no \"home\"-concept for sheet fed\n", __func__); DBG(DBG_proc, "%s: finished\n", __func__); - return SANE_STATUS_GOOD; + return; } // reset gpio pin @@ -2939,7 +2938,7 @@ gl841_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG(DBG_info, "%s: already at home, completed\n", __func__); dev->scanhead_position_in_steps = 0; - return SANE_STATUS_GOOD; + return; } /* end previous scan if any */ @@ -2991,20 +2990,19 @@ gl841_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG(DBG_info, "%s: reached home position\n", __func__); DBG(DBG_proc, "%s: finished\n", __func__); - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); ++loop; } - /* when we come here then the scanner needed too much time for this, so we better stop the motor */ - gl841_stop_action (dev); - DBG(DBG_error, "%s: timeout while waiting for scanhead to go home\n", __func__); - return SANE_STATUS_IO_ERROR; + // when we come here then the scanner needed too much time for this, so we better stop + // the motor + catch_all_exceptions(__func__, [&](){ gl841_stop_action(dev); }); + throw SaneException(SANE_STATUS_IO_ERROR, "timeout while waiting for scanhead to go home"); } DBG(DBG_info, "%s: scanhead is still moving\n", __func__); - return SANE_STATUS_GOOD; } /* Automatically set top-left edge of the scan area by scanning a 200x200 pixels @@ -4283,8 +4281,8 @@ sanei_gl841_repark_head (Genesys_Device * dev) gl841_feed(dev,232); - /* toggle motor flag, put an huge step number and redo move backward */ - status = gl841_slow_back_home (dev, SANE_TRUE); + // toggle motor flag, put an huge step number and redo move backward + gl841_slow_back_home(dev, SANE_TRUE); return status; } @@ -4380,8 +4378,8 @@ gl841_init (Genesys_Device * dev) // Set analog frontend gl841_set_fe(dev, sensor, AFE_INIT); - /* Move home */ - RIE (gl841_slow_back_home (dev, SANE_TRUE)); + // Move home + gl841_slow_back_home(dev, SANE_TRUE); // Init shading data sanei_genesys_init_shading_data(dev, sensor, sensor.sensor_pixels); diff --git a/backend/genesys_gl843.cc b/backend/genesys_gl843.cc index 32405b4ed..f2c0a653c 100644 --- a/backend/genesys_gl843.cc +++ b/backend/genesys_gl843.cc @@ -2222,7 +2222,7 @@ gl843_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, /** @brief park XPA lamp * park the XPA lamp if needed */ -static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev) +static void gl843_park_xpa_lamp(Genesys_Device* dev) { DBG_HELPER(dbg); Genesys_Register_Set local_reg; @@ -2279,7 +2279,7 @@ static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev) gl843_set_xpa_motor_power(dev, false); dev->needs_home_ta = SANE_FALSE; - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); ++loop; @@ -2287,25 +2287,22 @@ static SANE_Status gl843_park_xpa_lamp (Genesys_Device * dev) /* we are not parked here.... should we fail ? */ DBG(DBG_info, "%s: XPA lamp is not parked\n", __func__); - return SANE_STATUS_GOOD; } /** @brief Moves the slider to the home (top) position slowly * */ -static SANE_Status -gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) +static void gl843_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home) { DBG_HELPER_ARGS(dbg, "wait_until_home = %d", wait_until_home); Genesys_Register_Set local_reg; - SANE_Status status = SANE_STATUS_GOOD; GenesysRegister *r; uint8_t val; float resolution; int loop = 0; - if (dev->needs_home_ta) { - RIE(gl843_park_xpa_lamp(dev)); - } + if (dev->needs_home_ta) { + gl843_park_xpa_lamp(dev); + } /* regular slow back home */ dev->scanhead_position_in_steps = 0; @@ -2324,7 +2321,7 @@ gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) } if (val & HOMESNR) /* is sensor at home? */ { - return SANE_STATUS_GOOD; + return; } local_reg = dev->reg; @@ -2393,20 +2390,19 @@ gl843_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG(DBG_info, "%s: reached home position\n", __func__); DBG(DBG_proc, "%s: finished\n", __func__); - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); ++loop; } - /* when we come here then the scanner needed too much time for this, so we better stop the motor */ - gl843_stop_action (dev); - DBG(DBG_error, "%s: timeout while waiting for scanhead to go home\n", __func__); - return SANE_STATUS_IO_ERROR; + // when we come here then the scanner needed too much time for this, so we better stop + // the motor + catch_all_exceptions(__func__, [&](){ gl843_stop_action(dev); }); + throw SaneException(SANE_STATUS_IO_ERROR, "timeout while waiting for scanhead to go home"); } DBG(DBG_info, "%s: scanhead is still moving\n", __func__); - return SANE_STATUS_GOOD; } /* Automatically set top-left edge of the scan area by scanning a 200x200 pixels @@ -3499,7 +3495,7 @@ gl843_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor gl843_stop_action(dev); - status=gl843_slow_back_home (dev, SANE_TRUE); + gl843_slow_back_home(dev, SANE_TRUE); return status; } diff --git a/backend/genesys_gl846.cc b/backend/genesys_gl846.cc index 18925554c..19c52f6dc 100644 --- a/backend/genesys_gl846.cc +++ b/backend/genesys_gl846.cc @@ -1477,9 +1477,8 @@ gl846_end_scan (Genesys_Device * dev, Genesys_Register_Set * reg, return status; } -/* Moves the slider to the home (top) postion slowly */ -static SANE_Status -gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) +// Moves the slider to the home (top) postion slowly +static void gl846_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home) { DBG_HELPER_ARGS(dbg, "wait_until_home = %d", wait_until_home); Genesys_Register_Set local_reg; @@ -1514,7 +1513,7 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG(DBG_info, "%s: already at home, completed\n", __func__); dev->scanhead_position_in_steps = 0; - return SANE_STATUS_GOOD; + return; } local_reg = dev->reg; @@ -1584,20 +1583,19 @@ gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) DBG(DBG_info, "%s: reached home position\n", __func__); gl846_stop_action (dev); dev->scanhead_position_in_steps = 0; - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); ++loop; } - /* when we come here then the scanner needed too much time for this, so we better stop the motor */ - gl846_stop_action (dev); - DBG(DBG_error, "%s: timeout while waiting for scanhead to go home\n", __func__); - return SANE_STATUS_IO_ERROR; + // when we come here then the scanner needed too much time for this, so we better stop + // the motor + catch_all_exceptions(__func__, [&](){ gl846_stop_action(dev); }); + throw SaneException(SANE_STATUS_IO_ERROR, "timeout while waiting for scanhead to go home"); } DBG(DBG_info, "%s: scanhead is still moving\n", __func__); - return SANE_STATUS_GOOD; } /* Automatically set top-left edge of the scan area by scanning a 200x200 pixels @@ -2226,7 +2224,7 @@ gl846_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Reg /* go back home */ if(move>20) { - status=gl846_slow_back_home (dev, SANE_TRUE); + gl846_slow_back_home(dev, SANE_TRUE); } return status; @@ -2932,7 +2930,7 @@ gl846_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor gl846_stop_action(dev); - status=gl846_slow_back_home (dev, SANE_TRUE); + gl846_slow_back_home(dev, SANE_TRUE); return status; } diff --git a/backend/genesys_gl846.h b/backend/genesys_gl846.h index b51917289..59040ba4c 100644 --- a/backend/genesys_gl846.h +++ b/backend/genesys_gl846.h @@ -362,8 +362,7 @@ static void gl846_feed(Genesys_Device* dev, unsigned int steps); static void gl846_stop_action(Genesys_Device* dev); -static SANE_Status -gl846_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home); +static void gl846_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home); static void gl846_boot(Genesys_Device* dev, SANE_Bool cold); diff --git a/backend/genesys_gl847.cc b/backend/genesys_gl847.cc index 904a67e9b..d0c8358e7 100644 --- a/backend/genesys_gl847.cc +++ b/backend/genesys_gl847.cc @@ -1539,9 +1539,7 @@ SANE_Status gl847_rewind(Genesys_Device * dev) * @param wait_until_home true to make the function waiting for head * to be home before returning, if fals returne immediately * @returns SANE_STATUS_GOO on success */ -static -SANE_Status -gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) +static void gl847_slow_back_home(Genesys_Device* dev, SANE_Bool wait_until_home) { DBG_HELPER_ARGS(dbg, "wait_until_home = %d", wait_until_home); Genesys_Register_Set local_reg; @@ -1576,7 +1574,7 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) { DBG(DBG_info, "%s: already at home, completed\n", __func__); dev->scanhead_position_in_steps = 0; - return SANE_STATUS_GOOD; + return; } local_reg = dev->reg; @@ -1646,20 +1644,19 @@ gl847_slow_back_home (Genesys_Device * dev, SANE_Bool wait_until_home) DBG(DBG_info, "%s: reached home position\n", __func__); gl847_stop_action (dev); dev->scanhead_position_in_steps = 0; - return SANE_STATUS_GOOD; + return; } sanei_genesys_sleep_ms(100); ++loop; } - /* when we come here then the scanner needed too much time for this, so we better stop the motor */ - gl847_stop_action (dev); - DBG(DBG_error, "%s: timeout while waiting for scanhead to go home\n", __func__); - return SANE_STATUS_IO_ERROR; + // when we come here then the scanner needed too much time for this, so we better stop + // the motor + catch_all_exceptions(__func__, [&](){ gl847_stop_action(dev); }); + throw SaneException(SANE_STATUS_IO_ERROR, "timeout while waiting for scanhead to go home"); } DBG(DBG_info, "%s: scanhead is still moving\n", __func__); - return SANE_STATUS_GOOD; } /* Automatically set top-left edge of the scan area by scanning a 200x200 pixels @@ -2284,10 +2281,9 @@ gl847_led_calibration (Genesys_Device * dev, Genesys_Sensor& sensor, Genesys_Reg sensor.exposure.green = exp[1]; sensor.exposure.blue = exp[2]; - /* go back home */ - if(move>20) - { - status=gl847_slow_back_home (dev, SANE_TRUE); + // go back home + if (move>20) { + gl847_slow_back_home(dev, SANE_TRUE); } return status; @@ -3056,7 +3052,7 @@ gl847_coarse_gain_calibration(Genesys_Device * dev, const Genesys_Sensor& sensor gl847_stop_action(dev); - status=gl847_slow_back_home (dev, SANE_TRUE); + gl847_slow_back_home(dev, SANE_TRUE); return status; } diff --git a/backend/genesys_low.cc b/backend/genesys_low.cc index 2406589d8..fb1e617df 100644 --- a/backend/genesys_low.cc +++ b/backend/genesys_low.cc @@ -1273,8 +1273,8 @@ sanei_genesys_asic_init(Genesys_Device* dev, int /*max_regs*/) dev->already_initialized = SANE_TRUE; - /* Move to home if needed */ - RIE (dev->model->cmd_set->slow_back_home (dev, SANE_TRUE)); + // Move to home if needed + dev->model->cmd_set->slow_back_home(dev, SANE_TRUE); dev->scanhead_position_in_steps = 0; /* Set powersaving (default = 15 minutes) */ diff --git a/backend/genesys_low.h b/backend/genesys_low.h index c7c09bf01..e24153aa8 100644 --- a/backend/genesys_low.h +++ b/backend/genesys_low.h @@ -1090,7 +1090,7 @@ struct Genesys_Command_Set Genesys_Register_Set& regs); void (*wait_for_motor_stop) (Genesys_Device* dev); - SANE_Status (*slow_back_home) (Genesys_Device * dev, SANE_Bool wait_until_home); + void (*slow_back_home) (Genesys_Device* dev, SANE_Bool wait_until_home); SANE_Status (*rewind) (Genesys_Device * dev); void (*bulk_write_register) (Genesys_Device* dev, Genesys_Register_Set& regs);