From 66264538048e89679cc17bc0cea0b37b1f1f39ce Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Sat, 30 Nov 2019 19:06:46 +0200 Subject: [PATCH] genesys: Reduce duplication of scanner status printing --- backend/genesys/gl124.cpp | 8 +------- backend/genesys/gl646.cpp | 24 +----------------------- backend/genesys/gl841.cpp | 5 +---- backend/genesys/gl843.cpp | 15 +-------------- backend/genesys/gl846.cpp | 8 +------- backend/genesys/gl847.cpp | 8 +------- backend/genesys/low.cpp | 27 +++++++++++---------------- backend/genesys/low.h | 5 ++++- 8 files changed, 21 insertions(+), 79 deletions(-) diff --git a/backend/genesys/gl124.cpp b/backend/genesys/gl124.cpp index d9f9a8277..f412e3813 100644 --- a/backend/genesys/gl124.cpp +++ b/backend/genesys/gl124.cpp @@ -1021,10 +1021,7 @@ static void gl124_stop_action(Genesys_Device* dev) // post scan gpio : without that HOMSNR is unreliable gl124_homsnr_gpio(dev); - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + scanner_read_print_status(*dev); val40 = dev->interface->read_register(REG_0x100); @@ -1050,9 +1047,6 @@ static void gl124_stop_action(Genesys_Device* dev) while (loop > 0) { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } val40 = dev->interface->read_register(REG_0x100); /* if scanner is in command mode, we are done */ diff --git a/backend/genesys/gl646.cpp b/backend/genesys/gl646.cpp index 08b76d7c5..7555a7a7d 100644 --- a/backend/genesys/gl646.cpp +++ b/backend/genesys/gl646.cpp @@ -1210,10 +1210,7 @@ void CommandSetGl646::detect_document_end(Genesys_Device* dev) const unsigned int bytes_left; // test for document presence - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + scanner_read_print_status(*dev); gl646_gpio_read(dev->interface->get_usb_device(), &gpio); DBG(DBG_info, "%s: GPIO=0x%02x\n", __func__, gpio); @@ -1280,9 +1277,6 @@ void CommandSetGl646::eject_document(Genesys_Device* dev) const // test status : paper event + HOMESNR -> no more doc ? auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } // home sensor is set when document is inserted if (status.is_at_home) { @@ -1346,7 +1340,6 @@ void CommandSetGl646::eject_document(Genesys_Device* dev) const count = 0; do { status = scanner_read_status(*dev); - debug_print_status(dbg, status); dev->interface->sleep_ms(200); count++; @@ -1391,9 +1384,6 @@ static void end_scan_impl(Genesys_Device* dev, Genesys_Register_Set* reg, bool c /* we need to compute scanfsh before cancelling scan */ if (dev->model->is_sheetfed) { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } if (status.is_scanning_finished) { scanfsh = 1; } @@ -1414,9 +1404,6 @@ static void end_scan_impl(Genesys_Device* dev, Genesys_Register_Set* reg, bool c for (i = 0; i < 30; i++) /* do not wait longer than wait 3 seconds */ { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } if (status.is_scanning_finished) { scanfsh = 1; } @@ -1437,9 +1424,6 @@ static void end_scan_impl(Genesys_Device* dev, Genesys_Register_Set* reg, bool c { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } if (status.is_scanning_finished) { scanfsh = 1; @@ -1483,10 +1467,6 @@ void CommandSetGl646::slow_back_home(Genesys_Device* dev, bool wait_until_home) int loop = 0; auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - dev->scanhead_position_in_steps = 0; if (status.is_at_home) { @@ -2754,8 +2734,6 @@ void CommandSetGl646::init(Genesys_Device* dev) const // to detect real power up condition, we write to REG_0x41 with pwrbit set, then read it back. // When scanner is cold (just replugged) PWRBIT will be set in the returned value auto status = scanner_read_status(*dev); - debug_print_status(dbg, status); - if (status.is_replugged) { DBG(DBG_info, "%s: device is cold\n", __func__); } else { diff --git a/backend/genesys/gl841.cpp b/backend/genesys/gl841.cpp index 091eb4dc9..1c97d9305 100644 --- a/backend/genesys/gl841.cpp +++ b/backend/genesys/gl841.cpp @@ -1868,10 +1868,7 @@ static void gl841_stop_action(Genesys_Device* dev) Genesys_Register_Set local_reg; unsigned int loop; - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + scanner_read_print_status(*dev); uint8_t val40 = dev->interface->read_register(0x40); diff --git a/backend/genesys/gl843.cpp b/backend/genesys/gl843.cpp index a3a37dcc2..e532f95fe 100644 --- a/backend/genesys/gl843.cpp +++ b/backend/genesys/gl843.cpp @@ -1331,10 +1331,7 @@ static void gl843_stop_action(Genesys_Device* dev) DBG_HELPER(dbg); unsigned int loop; - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + scanner_read_print_status(*dev); uint8_t val40 = dev->interface->read_register(REG_0x40); @@ -1360,9 +1357,6 @@ static void gl843_stop_action(Genesys_Device* dev) loop = 10; while (loop > 0) { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } val40 = dev->interface->read_register(0x40); /* if scanner is in command mode, we are done */ @@ -1774,10 +1768,6 @@ static void gl843_park_xpa_lamp(Genesys_Device* dev) while (loop < 600) /* do not wait longer then 60 seconds */ { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - if (status.is_at_home) { DBG(DBG_info, "%s: reached home position\n", __func__); DBG(DBG_proc, "%s: finished\n", __func__); @@ -1875,9 +1865,6 @@ void CommandSetGl843::slow_back_home(Genesys_Device* dev, bool wait_until_home) while (loop < 300) /* do not wait longer then 30 seconds */ { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } if (status.is_at_home) { DBG(DBG_info, "%s: reached home position\n", __func__); diff --git a/backend/genesys/gl846.cpp b/backend/genesys/gl846.cpp index eecfc528c..fbaee2c4a 100644 --- a/backend/genesys/gl846.cpp +++ b/backend/genesys/gl846.cpp @@ -857,10 +857,7 @@ static void gl846_stop_action(Genesys_Device* dev) // post scan gpio : without that HOMSNR is unreliable gl846_homsnr_gpio(dev); - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + scanner_read_print_status(*dev); uint8_t val40 = dev->interface->read_register(REG_0x40); @@ -884,9 +881,6 @@ static void gl846_stop_action(Genesys_Device* dev) loop = 10; while (loop > 0) { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } val40 = dev->interface->read_register(REG_0x40); /* if scanner is in command mode, we are done */ diff --git a/backend/genesys/gl847.cpp b/backend/genesys/gl847.cpp index 19666d4fb..7cddc36fe 100644 --- a/backend/genesys/gl847.cpp +++ b/backend/genesys/gl847.cpp @@ -869,10 +869,7 @@ static void gl847_stop_action(Genesys_Device* dev) // post scan gpio : without that HOMSNR is unreliable gl847_homsnr_gpio(dev); - auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } + scanner_read_print_status(*dev); uint8_t val40 = dev->interface->read_register(REG_0x40); @@ -898,9 +895,6 @@ static void gl847_stop_action(Genesys_Device* dev) while (loop > 0) { auto status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } val40 = dev->interface->read_register(REG_0x40); /* if scanner is in command mode, we are done */ diff --git a/backend/genesys/low.cpp b/backend/genesys/low.cpp index 7857a07dc..ff50bf261 100644 --- a/backend/genesys/low.cpp +++ b/backend/genesys/low.cpp @@ -302,6 +302,11 @@ Status scanner_read_status(Genesys_Device& dev) status.is_lamp_on = value & LAMPSTS; status.is_front_end_busy = value & FEBUSY; status.is_motor_enabled = value & MOTORENB; + + if (DBG_LEVEL >= DBG_io) { + debug_print_status(dbg, status); + } + return status; } @@ -309,20 +314,14 @@ 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); - } - + scanner_read_status(dev); dev.interface->sleep_ms(100); + return scanner_read_status(dev); +} - // second is reliable - status = scanner_read_status(dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - - return status; +void scanner_read_print_status(Genesys_Device& dev) +{ + scanner_read_status(dev); } /** @@ -1700,10 +1699,6 @@ void sanei_genesys_wait_for_home(Genesys_Device* dev) elapsed_ms += 100; status = scanner_read_status(*dev); - if (DBG_LEVEL >= DBG_io) { - debug_print_status(dbg, status); - } - } while (elapsed_ms < timeout_ms && !status.is_at_home); /* if after the timeout, head is still not parked, error out */ diff --git a/backend/genesys/low.h b/backend/genesys/low.h index ec708ae68..db1206ae9 100644 --- a/backend/genesys/low.h +++ b/backend/genesys/low.h @@ -257,7 +257,10 @@ Status scanner_read_status(Genesys_Device& dev); // 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); +// reads and prints the scanner status +void scanner_read_print_status(Genesys_Device& dev); + +void debug_print_status(DebugMessageHelper& dbg, Status status); extern void sanei_genesys_write_ahb(Genesys_Device* dev, uint32_t addr, uint32_t size, uint8_t* data);