genesys: Store sensor settings in std::vector on gl646

merge-requests/139/head
Povilas Kanapickas 2019-08-17 11:49:08 +03:00
rodzic a8ed3df0fd
commit f228e427a9
2 zmienionych plików z 54 dodań i 92 usunięć

Wyświetl plik

@ -214,25 +214,16 @@ static void gl646_stop_motor(Genesys_Device* dev)
static int static int
get_lowest_resolution(int sensor_id, unsigned channels) get_lowest_resolution(int sensor_id, unsigned channels)
{ {
int i, nb; int dpi = 9600;
int dpi; for (const auto& sensor : sensor_master) {
// computes distance and keep mode if it is closer than previous
i = 0; if (sensor_id == sensor.sensor && sensor.channels == channels) {
dpi = 9600; if (sensor.dpi < dpi) {
nb = sizeof (sensor_master) / sizeof (Sensor_Master); dpi = sensor.dpi;
while (i < nb) }
{ }
/* computes distance and keep mode if it is closer than previous */
if (sensor_id == sensor_master[i].sensor
&& sensor_master[i].channels == channels)
{
if (sensor_master[i].dpi < dpi)
{
dpi = sensor_master[i].dpi;
}
}
i++;
} }
DBG(DBG_info, "%s: %d\n", __func__, dpi); DBG(DBG_info, "%s: %d\n", __func__, dpi);
return dpi; return dpi;
} }
@ -247,35 +238,28 @@ get_lowest_resolution(int sensor_id, unsigned channels)
static int static int
get_closest_resolution(int sensor_id, int required, unsigned channels) get_closest_resolution(int sensor_id, int required, unsigned channels)
{ {
int i, nb; int dpi = 0;
int dist, dpi; int dist = 9600;
i = 0; for (const auto& sensor : sensor_master) {
dpi = 0; if (sensor_id != sensor.sensor)
dist = 9600; continue;
nb = sizeof (sensor_master) / sizeof (Sensor_Master);
while (i < nb) // exit on perfect match
{ if (sensor.dpi == required && sensor.channels == channels) {
/* exit on perfect match */ DBG(DBG_info, "%s: match found for %d\n", __func__, required);
if (sensor_id == sensor_master[i].sensor return required;
&& sensor_master[i].dpi == required }
&& sensor_master[i].channels == channels)
{ // computes distance and keep mode if it is closer than previous
DBG(DBG_info, "%s: match found for %d\n", __func__, required); if (sensor.channels == channels) {
return required; if (std::abs(sensor.dpi - required) < dist) {
} dpi = sensor.dpi;
/* computes distance and keep mode if it is closer than previous */ dist = std::abs(sensor.dpi - required);
if (sensor_id == sensor_master[i].sensor }
&& sensor_master[i].channels == channels) }
{
if (abs (sensor_master[i].dpi - required) < dist)
{
dpi = sensor_master[i].dpi;
dist = abs (sensor_master[i].dpi - required);
}
}
i++;
} }
DBG(DBG_info, "%s: closest match for %d is %d\n", __func__, required, dpi); DBG(DBG_info, "%s: closest match for %d is %d\n", __func__, required, dpi);
return dpi; return dpi;
} }
@ -290,22 +274,13 @@ get_closest_resolution(int sensor_id, int required, unsigned channels)
*/ */
static unsigned get_ccd_size_divisor(int sensor_id, int required, unsigned channels) static unsigned get_ccd_size_divisor(int sensor_id, int required, unsigned channels)
{ {
int i, nb; for (const auto& sensor : sensor_master) {
// exit on perfect match
i = 0; if (sensor_id == sensor.sensor && sensor.dpi == required && sensor.channels == channels) {
nb = sizeof (sensor_master) / sizeof (Sensor_Master); DBG(DBG_io, "%s: match found for %d (ccd_size_divisor=%d)\n", __func__, required,
while (i < nb) sensor.ccd_size_divisor);
{ return sensor.ccd_size_divisor;
/* exit on perfect match */ }
if (sensor_id == sensor_master[i].sensor
&& sensor_master[i].dpi == required
&& sensor_master[i].channels == channels)
{
DBG(DBG_io, "%s: match found for %d (ccd_size_divisor=%d)\n", __func__, required,
sensor_master[i].ccd_size_divisor);
return sensor_master[i].ccd_size_divisor;
}
i++;
} }
DBG(DBG_info, "%s: failed to find match for %d dpi\n", __func__, required); DBG(DBG_info, "%s: failed to find match for %d dpi\n", __func__, required);
return 1; return 1;
@ -320,22 +295,13 @@ static unsigned get_ccd_size_divisor(int sensor_id, int required, unsigned chann
*/ */
static int get_cksel(int sensor_id, int required, unsigned channels) static int get_cksel(int sensor_id, int required, unsigned channels)
{ {
int i, nb; for (const auto& sensor : sensor_master) {
// exit on perfect match
i = 0; if (sensor_id == sensor.sensor && sensor.dpi == required && sensor.channels == channels) {
nb = sizeof (sensor_master) / sizeof (Sensor_Master); DBG(DBG_io, "%s: match found for %d (cksel=%d)\n", __func__, required,
while (i < nb) sensor.cksel);
{ return sensor.cksel;
/* exit on perfect match */ }
if (sensor_id == sensor_master[i].sensor
&& sensor_master[i].dpi == required
&& sensor_master[i].channels == channels)
{
DBG(DBG_io, "%s: match found for %d (cksel=%d)\n", __func__, required,
sensor_master[i].cksel);
return sensor_master[i].cksel;
}
i++;
} }
DBG(DBG_error, "%s: failed to find match for %d dpi\n", __func__, required); DBG(DBG_error, "%s: failed to find match for %d dpi\n", __func__, required);
/* fail safe fallback */ /* fail safe fallback */
@ -413,7 +379,6 @@ static void gl646_setup_registers(Genesys_Device* dev,
uint32_t endx = startx + pixels; uint32_t endx = startx + pixels;
int i, nb; int i, nb;
Sensor_Master *sensor_mst = NULL;
Motor_Master *motor = NULL; Motor_Master *motor = NULL;
unsigned int used1, used2, vfinal; unsigned int used1, used2, vfinal;
unsigned int bpp; /**> bytes per pixel */ unsigned int bpp; /**> bytes per pixel */
@ -437,20 +402,17 @@ static void gl646_setup_registers(Genesys_Device* dev,
xresolution = resolution; xresolution = resolution;
} }
/* for the given resolution, search for master // for the given resolution, search for master sensor mode setting
* sensor mode setting */ const Sensor_Master* sensor_mst = nullptr;
i = 0; for (const auto& sensor : sensor_master) {
nb = sizeof (sensor_master) / sizeof (Sensor_Master); if (dev->model->ccd_type == sensor.sensor && sensor.dpi == xresolution &&
while (i < nb) sensor.channels == session.params.channels)
{ {
if (dev->model->ccd_type == sensor_master[i].sensor sensor_mst = &sensor;
&& sensor_master[i].dpi == xresolution break;
&& sensor_master[i].channels == session.params.channels) }
{
sensor_mst = &sensor_master[i];
}
i++;
} }
if (sensor_mst == NULL) { if (sensor_mst == NULL) {
throw SaneException("unable to find settings for sensor %d at %d dpi channels=%d", throw SaneException("unable to find settings for sensor %d at %d dpi channels=%d",
dev->model->ccd_type, xresolution, session.params.channels); dev->model->ccd_type, xresolution, session.params.channels);

Wyświetl plik

@ -305,7 +305,7 @@ struct Sensor_Master
* master sensor settings, for a given sensor and dpi, * master sensor settings, for a given sensor and dpi,
* it gives exposure and CCD time * it gives exposure and CCD time
*/ */
static Sensor_Master sensor_master[] = { static std::vector<Sensor_Master> sensor_master = {
/* HP3670 master settings */ /* HP3670 master settings */
{CCD_HP3670, 75, 3, 75, 4879, 4, 1, { 0, 0, 0 }, { { 0x08, 0x00 }, { 0x09, 0x0a }, { 0x0a, 0x0b }, { 0x0b, 0x0d }, { 0x16, 0x33 }, { 0x17, 0x07 }, { 0x18, 0x33 }, { 0x19, 0x2a }, { 0x1a, 0x02 }, { 0x1b, 0x13 }, { 0x1c, 0xc0 }, { 0x1d, 0x43 }, { 0x52, 0x0f }, { 0x53, 0x13 }, { 0x54, 0x17 }, { 0x55, 0x03 }, { 0x56, 0x07 }, { 0x57, 0x0b }, { 0x58, 0x83 }, { 0x59, 0x15 }, { 0x5a, 0xc1 }, { 0x5b, 0x05 }, { 0x5c, 0x0a }, { 0x5d, 0x0f }, { 0x5e, 0x00 } } }, {CCD_HP3670, 75, 3, 75, 4879, 4, 1, { 0, 0, 0 }, { { 0x08, 0x00 }, { 0x09, 0x0a }, { 0x0a, 0x0b }, { 0x0b, 0x0d }, { 0x16, 0x33 }, { 0x17, 0x07 }, { 0x18, 0x33 }, { 0x19, 0x2a }, { 0x1a, 0x02 }, { 0x1b, 0x13 }, { 0x1c, 0xc0 }, { 0x1d, 0x43 }, { 0x52, 0x0f }, { 0x53, 0x13 }, { 0x54, 0x17 }, { 0x55, 0x03 }, { 0x56, 0x07 }, { 0x57, 0x0b }, { 0x58, 0x83 }, { 0x59, 0x15 }, { 0x5a, 0xc1 }, { 0x5b, 0x05 }, { 0x5c, 0x0a }, { 0x5d, 0x0f }, { 0x5e, 0x00 } } },
{CCD_HP3670, 100, 3, 100, 4487, 4, 1, { 0, 0, 0 }, { { 0x08, 0x00 }, { 0x09, 0x0a }, { 0x0a, 0x0b }, { 0x0b, 0x0d }, { 0x16, 0x33 }, { 0x17, 0x07 }, { 0x18, 0x33 }, { 0x19, 0x2a }, { 0x1a, 0x02 }, { 0x1b, 0x13 }, { 0x1c, 0xc0 }, { 0x1d, 0x43 }, { 0x52, 0x0f }, { 0x53, 0x13 }, { 0x54, 0x17 }, { 0x55, 0x03 }, { 0x56, 0x07 }, { 0x57, 0x0b }, { 0x58, 0x83 }, { 0x59, 0x15 }, { 0x5a, 0xc1 }, { 0x5b, 0x05 }, { 0x5c, 0x0a }, { 0x5d, 0x0f }, { 0x5e, 0x00 } } }, {CCD_HP3670, 100, 3, 100, 4487, 4, 1, { 0, 0, 0 }, { { 0x08, 0x00 }, { 0x09, 0x0a }, { 0x0a, 0x0b }, { 0x0b, 0x0d }, { 0x16, 0x33 }, { 0x17, 0x07 }, { 0x18, 0x33 }, { 0x19, 0x2a }, { 0x1a, 0x02 }, { 0x1b, 0x13 }, { 0x1c, 0xc0 }, { 0x1d, 0x43 }, { 0x52, 0x0f }, { 0x53, 0x13 }, { 0x54, 0x17 }, { 0x55, 0x03 }, { 0x56, 0x07 }, { 0x57, 0x0b }, { 0x58, 0x83 }, { 0x59, 0x15 }, { 0x5a, 0xc1 }, { 0x5b, 0x05 }, { 0x5c, 0x0a }, { 0x5d, 0x0f }, { 0x5e, 0x00 } } },