From df8a411de386ed632b6cda98ec8e9bef0fce121f Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 30 Nov 2019 19:06:45 +0200 Subject: [PATCH] genesys: Extract reliable reading of home sensor to separate function --- backend/genesys/gl124.cpp | 13 +------------ backend/genesys/gl841.cpp | 12 +----------- backend/genesys/gl843.cpp | 14 +------------- backend/genesys/gl846.cpp | 12 +----------- backend/genesys/gl847.cpp | 12 +----------- backend/genesys/low.cpp | 20 ++++++++++++++++++++ backend/genesys/low.h | 5 +++++ 7 files changed, 30 insertions(+), 58 deletions(-) diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index 64bed98d8..d9f9a8277 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -1205,18 +1205,7 @@ void CommandSetGl124::slow_back_home(Genesys_Device* dev, bool wait_until_home) // post scan gpio : without that HOMSNR is unreliable gl124_homsnr_gpio(dev); - // first read gives HOME_SENSOR true - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - dev->interface->sleep_ms(100); - - // second is reliable - status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + auto status = scanner_read_reliable_status(*dev); if (status.is_at_home) { DBG (DBG_info, "%s: already at home, completed\n", __func__); diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index e408310eb..091eb4dc9 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -2257,17 +2257,7 @@ void CommandSetGl841::slow_back_home(Genesys_Device* dev, bool wait_until_home) dev->cmd_set->save_power(dev, false); // first read gives HOME_SENSOR true - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - dev->interface->sleep_ms(100); - - // second is reliable - status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + auto status = scanner_read_reliable_status(*dev); dev->scanhead_position_in_steps = 0; diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index b01f8819e..a3a37dcc2 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -1811,19 +1811,7 @@ void CommandSetGl843::slow_back_home(Genesys_Device* dev, bool wait_until_home) /* regular slow back home */ dev->scanhead_position_in_steps = 0; - // first read gives HOME_SENSOR true - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - - dev->interface->sleep_ms(100); - - // second is reliable - status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + auto status = scanner_read_reliable_status(*dev); if (status.is_at_home) { return; diff --git a/backend/genesys/gl846.cpp b/backend/genesys/gl846.cpp index 65cdd1934..eecfc528c 100644 --- a/backend/genesys/gl846.cpp +++ b/backend/genesys/gl846.cpp @@ -957,17 +957,7 @@ void CommandSetGl846::slow_back_home(Genesys_Device* dev, bool wait_until_home) gl846_homsnr_gpio(dev); // first read gives HOME_SENSOR true - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - dev->interface->sleep_ms(100); - - // second is reliable - status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + auto status = scanner_read_reliable_status(*dev); /* is sensor at home? */ if (status.is_at_home) { diff --git a/backend/genesys/gl847.cpp b/backend/genesys/gl847.cpp index f8a754f07..19666d4fb 100644 --- a/backend/genesys/gl847.cpp +++ b/backend/genesys/gl847.cpp @@ -1010,17 +1010,7 @@ void CommandSetGl847::slow_back_home(Genesys_Device* dev, bool wait_until_home) gl847_homsnr_gpio(dev); // first read gives HOME_SENSOR true - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - dev->interface->sleep_ms(100); - - // second is reliable - status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + auto status = scanner_read_reliable_status(*dev); if (status.is_at_home) { DBG(DBG_info, "%s: already at home, completed\n", __func__); diff --git a/backend/genesys/low.cpp b/backend/genesys/low.cpp index d4e70e939..7857a07dc 100644 --- a/backend/genesys/low.cpp +++ b/backend/genesys/low.cpp @@ -305,6 +305,26 @@ Status scanner_read_status(Genesys_Device& dev) return status; } +Status scanner_read_reliable_status(Genesys_Device& dev) +{ + DBG_HELPER(dbg); + + auto status = scanner_read_status(dev); + if (DBG_LEVEL >= DBG_io) { + debug_print_status(dbg, status); + } + + dev.interface->sleep_ms(100); + + // second is reliable + status = scanner_read_status(dev); + if (DBG_LEVEL >= DBG_io) { + debug_print_status(dbg, status); + } + + return status; +} + /** * decodes and prints content of status register * @param val value read from status register diff --git a/backend/genesys/low.h b/backend/genesys/low.h index 16466b7ea..ec708ae68 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -250,8 +250,13 @@ inline GenesysRegister* sanei_genesys_get_address(Genesys_Register_Set* regs, ui extern void sanei_genesys_init_cmd_set(Genesys_Device* dev); +// reads the status of the scanner Status scanner_read_status(Genesys_Device& dev); +// reads the status of the scanner reliably. This is done by reading the status twice. The first +// read sometimes returns the home sensor as engaged when this is not true. +Status scanner_read_reliable_status(Genesys_Device& dev); + extern void debug_print_status(DebugMessageHelper& dbg, Status status); extern void sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t size,