1650
/* Set values of Analog Device type frontend */
1652
gl841_set_ad_fe (Genesys_Device * dev, uint8_t set)
1654
SANE_Status status = SANE_STATUS_GOOD;
1656
DBG (DBG_proc, "gl841_set_ad_fe(): start\n");
1657
if (set == AFE_INIT)
1659
DBG (DBG_proc, "gl841_set_ad_fe(): setting DAC %u\n",
1660
dev->model->dac_type);
1662
/* sets to default values */
1663
sanei_genesys_init_fe (dev);
1665
/* write them to analog frontend */
1666
status = sanei_genesys_fe_write_data (dev, 0x00, dev->frontend.reg[0]);
1667
if (status != SANE_STATUS_GOOD)
1669
DBG (DBG_error, "gl841_set_ad_fe: writing reg 0x00 failed: %s\n",
1670
sane_strstatus (status));
1674
status = sanei_genesys_fe_write_data (dev, 0x01, dev->frontend.reg[1]);
1675
if (status != SANE_STATUS_GOOD)
1677
DBG (DBG_error, "gl841_set_ad_fe: writing reg 0x01 failed: %s\n",
1678
sane_strstatus (status));
1682
for (i = 0; i < 6; i++)
1685
sanei_genesys_fe_write_data (dev, 0x02 + i, 0x00);
1686
if (status != SANE_STATUS_GOOD)
1689
"gl841_set_ad_fe: writing sign[%d] failed: %s\n", 0x02 + i,
1690
sane_strstatus (status));
1697
/* write them to analog frontend */
1698
status = sanei_genesys_fe_write_data (dev, 0x00, dev->frontend.reg[0]);
1699
if (status != SANE_STATUS_GOOD)
1701
DBG (DBG_error, "gl841_set_ad_fe: writing reg 0x00 failed: %s\n",
1702
sane_strstatus (status));
1706
status = sanei_genesys_fe_write_data (dev, 0x01, dev->frontend.reg[1]);
1707
if (status != SANE_STATUS_GOOD)
1709
DBG (DBG_error, "gl841_set_ad_fe: writing reg 0x01 failed: %s\n",
1710
sane_strstatus (status));
1714
/* Write fe 0x02 (red gain)*/
1715
status = sanei_genesys_fe_write_data (dev, 0x02, dev->frontend.gain[0]);
1716
if (status != SANE_STATUS_GOOD)
1718
DBG (DBG_error, "gl841_set_ad_fe: writing fe 0x02 (gain r) fail: %s\n",
1719
sane_strstatus (status));
1723
/* Write fe 0x03 (green gain)*/
1724
status = sanei_genesys_fe_write_data (dev, 0x03, dev->frontend.gain[1]);
1725
if (status != SANE_STATUS_GOOD)
1727
DBG (DBG_error, "gl841_set_ad_fe: writing fe 0x03 (gain g) fail: %s\n",
1728
sane_strstatus (status));
1732
/* Write fe 0x04 (blue gain)*/
1733
status = sanei_genesys_fe_write_data (dev, 0x04, dev->frontend.gain[2]);
1734
if (status != SANE_STATUS_GOOD)
1736
DBG (DBG_error, "gl841_set_ad_fe: writing fe 0x04 (gain b) fail: %s\n",
1737
sane_strstatus (status));
1741
/* Write fe 0x05 (red offset)*/
1743
sanei_genesys_fe_write_data (dev, 0x05, dev->frontend.offset[0]);
1744
if (status != SANE_STATUS_GOOD)
1746
DBG (DBG_error, "gl841_set_ad_fe: write fe 0x05 (offset r) fail: %s\n",
1747
sane_strstatus (status));
1751
/* Write fe 0x06 (green offset)*/
1753
sanei_genesys_fe_write_data (dev, 0x06, dev->frontend.offset[1]);
1754
if (status != SANE_STATUS_GOOD)
1756
DBG (DBG_error, "gl841_set_ad_fe: write fe 0x06 (offset g) fail: %s\n",
1757
sane_strstatus (status));
1761
/* Write fe 0x07 (blue offset)*/
1763
sanei_genesys_fe_write_data (dev, 0x07, dev->frontend.offset[2]);
1764
if (status != SANE_STATUS_GOOD)
1766
DBG (DBG_error, "gl841_set_ad_fe: write fe 0x07 (offset b) fail: %s\n",
1767
sane_strstatus (status));
1771
DBG (DBG_proc, "gl841_set_ad_fe(): end\n");
1633
1776
/* Set values of analog frontend */
1634
1777
static SANE_Status
1635
1778
gl841_set_fe (Genesys_Device * dev, uint8_t set)
3971
4134
DBG (DBG_info, "%s: no more document\n", __FUNCTION__);
3972
4135
dev->document = SANE_FALSE;
3974
channels = dev->current_setup.channels;
3975
depth = dev->current_setup.depth;
3976
read_bytes_left = (int) dev->read_bytes_left;
3977
DBG (DBG_io, "gl841_detect_document_end: read_bytes_left=%d\n",
3980
/* read lins read */
3981
status = sanei_genesys_read_scancnt (dev, &scancnt);
3982
if (status != SANE_STATUS_GOOD)
3988
/* compute number of line read */
3989
tmp = (int) dev->total_bytes_read;
3990
if (depth == 1 || dev->settings.scan_mode == SCAN_MODE_LINEART)
3991
flines = tmp * 8 / dev->settings.pixels / channels;
3993
flines = tmp / (depth / 8) / dev->settings.pixels / channels;
3995
/* number of scanned lines, but no read yet */
3996
flines = scancnt - flines;
3999
"gl841_detect_document_end: %d scanned but not read lines\n",
4003
/* adjust number of bytes to read
4004
* we need to read the final bytes which are word per line * number of last lines
4005
* to have doc leaving feeder */
4007
(SANE_UNFIX (dev->model->post_scan) * dev->current_setup.yres) /
4008
MM_PER_INCH + flines;
4009
DBG (DBG_io, "gl841_detect_document_end: adding %d line to flush\n",
4012
/* number of bytes to read from scanner to get document out of it after
4013
* end of document dectected by hardware sensor */
4014
bytes_to_flush = lines * dev->wpl;
4016
/* if we are already close to end of scan, flushing isn't needed */
4017
if (bytes_to_flush < read_bytes_left)
4019
/* we take all these step to work around an overflow on some plateforms */
4020
tmp = (int) dev->total_bytes_read;
4021
DBG (DBG_io, "gl841_detect_document_end: tmp=%d\n", tmp);
4022
bytes_remain = (int) dev->total_bytes_to_read;
4023
DBG (DBG_io, "gl841_detect_document_end: bytes_remain=%d\n",
4025
bytes_remain = bytes_remain - tmp;
4026
DBG (DBG_io, "gl841_detect_document_end: bytes_remain=%d\n",
4029
/* remaining lines to read by frontend for the current scan */
4030
if (depth == 1 || dev->settings.scan_mode == SCAN_MODE_LINEART)
4032
flines = bytes_remain * 8 / dev->settings.pixels / channels;
4035
flines = bytes_remain / (depth / 8)
4036
/ dev->settings.pixels / channels;
4037
DBG (DBG_io, "gl841_detect_document_end: flines=%d\n", flines);
4041
/* change the value controlling communication with the frontend :
4042
* total bytes to read is current value plus the number of remaining lines
4043
* multiplied by bytes per line */
4044
sublines = flines - lines;
4046
if (depth == 1 || dev->settings.scan_mode == SCAN_MODE_LINEART)
4048
((dev->settings.pixels * sublines) / 8 +
4049
(((dev->settings.pixels * sublines) % 8) ? 1 : 0)) *
4053
dev->settings.pixels * sublines * channels * (depth / 8);
4055
dev->total_bytes_to_read -= sub_bytes;
4057
/* then adjust the physical bytes to read */
4058
if (read_bytes_left > sub_bytes)
4060
dev->read_bytes_left -= sub_bytes;
4064
dev->total_bytes_to_read = dev->total_bytes_read;
4065
dev->read_bytes_left = 0;
4068
DBG (DBG_io, "gl841_detect_document_end: sublines=%d\n",
4070
DBG (DBG_io, "gl841_detect_document_end: subbytes=%d\n",
4073
"gl841_detect_document_end: total_bytes_to_read=%d\n",
4074
dev->total_bytes_to_read);
4075
DBG (DBG_io, "gl841_detect_document_end: read_bytes_left=%d\n",
4081
DBG (DBG_io, "gl841_detect_document_end: no flushing needed\n");
4137
/* we can't rely on total_bytes_to_read since the frontend
4138
* might have been slow to read data, so we re-evaluate the
4139
* amount of data to scan form the hardware settings
4141
status=sanei_genesys_read_scancnt(dev,&scancnt);
4142
if(status!=SANE_STATUS_GOOD)
4144
dev->total_bytes_to_read = dev->total_bytes_read;
4145
dev->read_bytes_left = 0;
4146
DBG (DBG_proc, "%s: finished\n", __FUNCTION__);
4147
return SANE_STATUS_GOOD;
4149
if (dev->settings.scan_mode == SCAN_MODE_COLOR && dev->model->is_cis)
4153
DBG (DBG_io, "%s: scancnt=%u lines\n",__FUNCTION__, scancnt);
4155
RIE(sanei_genesys_read_register(dev, 0x25, &val));
4157
RIE(sanei_genesys_read_register(dev, 0x26, &val));
4159
RIE(sanei_genesys_read_register(dev, 0x27, &val));
4161
DBG (DBG_io, "%s: lincnt=%u lines\n",__FUNCTION__, lincnt);
4162
postcnt=(SANE_UNFIX(dev->model->post_scan)/MM_PER_INCH)*dev->settings.yres;
4163
DBG (DBG_io, "%s: postcnt=%u lines\n",__FUNCTION__, postcnt);
4165
/* the current scancnt is also the final one, so we use it to
4166
* compute total bytes to read. We also add the line count to eject document */
4167
total_bytes_to_read=(scancnt+postcnt)*dev->wpl;
4168
DBG (DBG_io, "%s: old total_bytes_to_read=%u\n",__FUNCTION__,dev->total_bytes_to_read);
4169
DBG (DBG_io, "%s: new total_bytes_to_read=%u\n",__FUNCTION__,total_bytes_to_read);
4171
/* assign new end value */
4172
if(dev->total_bytes_to_read>total_bytes_to_read)
4174
DBG (DBG_io, "%s: scan shorten\n",__FUNCTION__);
4175
dev->total_bytes_to_read=total_bytes_to_read;
4085
4179
DBG (DBG_proc, "%s: finished\n", __FUNCTION__);
5133
/** @brief calibration for AD frontend devices
5134
* experiments show that modifying offset is of little (if no) influence
5136
* CHRIS: This was added from gl646.c as again offset seems to make no
5139
* TODO PLUSTEK_3600 Michael Rickmann:
5140
* offset calibration makes a lot of a difference but currently
5141
* makes everything to dark
5144
ad_fe_offset_calibration (Genesys_Device * dev)
5146
SANE_Status status = SANE_STATUS_GOOD;
5148
DBG (DBG_proc, "ad_fe_offset_calibration: start\n");
5149
DBG (DBG_info, "ad_fe_offset_calibration: offset=(%d,%d,%d)\n",
5150
dev->frontend.offset[0], dev->frontend.offset[1],
5151
dev->frontend.offset[2]);
5152
DBG (DBG_proc, "ad_fe_offset_calibration: end\n");
5023
5156
/* this function does the offset calibration by scanning one line of the calibration
5024
5157
area below scanner's top. There is a black margin and the remaining is white.
5025
5158
sanei_genesys_search_start() must have been called so that the offsets and margins