设置区间参数的步长
This commit is contained in:
parent
c075cea1d0
commit
cf6af1d0e1
|
@ -572,7 +572,7 @@ SANE_Option_Descriptor* hg_sane_middleware::string_option_to_SANE_descriptor(con
|
||||||
return sod;
|
return sod;
|
||||||
}
|
}
|
||||||
SANE_Option_Descriptor* hg_sane_middleware::number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
SANE_Option_Descriptor* hg_sane_middleware::number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
||||||
, bool double_val, double* lower, double* upper)
|
, bool double_val, double* lower, double* upper, double* step)
|
||||||
{
|
{
|
||||||
int bytes = sizeof(SANE_Option_Descriptor) + sizeof(SANE_Range);
|
int bytes = sizeof(SANE_Option_Descriptor) + sizeof(SANE_Range);
|
||||||
SANE_Option_Descriptor *sod = NULL;
|
SANE_Option_Descriptor *sod = NULL;
|
||||||
|
@ -625,6 +625,13 @@ SANE_Option_Descriptor* hg_sane_middleware::number_option_to_SANE_descriptor(con
|
||||||
(*(SANE_Range*)str).max = (SANE_Word)*upper;
|
(*(SANE_Range*)str).max = (SANE_Word)*upper;
|
||||||
}
|
}
|
||||||
(*(SANE_Range*)str).quant = 0;
|
(*(SANE_Range*)str).quant = 0;
|
||||||
|
if (step)
|
||||||
|
{
|
||||||
|
if(double_val)
|
||||||
|
(*(SANE_Range*)str).quant = hg_sane_middleware::double_2_sane_fixed(*step);
|
||||||
|
else
|
||||||
|
(*(SANE_Range*)str).quant = (SANE_Word)(*step);
|
||||||
|
}
|
||||||
|
|
||||||
str = (char*)((SANE_Range*)str + 1);
|
str = (char*)((SANE_Range*)str + 1);
|
||||||
}
|
}
|
||||||
|
@ -795,7 +802,7 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
|
||||||
{
|
{
|
||||||
std::string title(""), desc(""), val("");
|
std::string title(""), desc(""), val("");
|
||||||
std::vector<std::string> constraints;
|
std::vector<std::string> constraints;
|
||||||
double lower = .0f, upper = .0f;
|
double lower = .0f, upper = .0f, step = .0f;
|
||||||
bool db_val = false;
|
bool db_val = false;
|
||||||
|
|
||||||
jsn->get_value("title", title);
|
jsn->get_value("title", title);
|
||||||
|
@ -839,12 +846,14 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
|
||||||
int l = 0;
|
int l = 0;
|
||||||
if (range->get_value("min", l))
|
if (range->get_value("min", l))
|
||||||
{
|
{
|
||||||
int u = 0;
|
int u = 0, s = 1;
|
||||||
range->get_value("max", u);
|
range->get_value("max", u);
|
||||||
|
range->get_value("step", s);
|
||||||
lower = l;
|
lower = l;
|
||||||
upper = u;
|
upper = u;
|
||||||
|
step = s;
|
||||||
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
||||||
, false, &lower, &upper);
|
, false, &lower, &upper, &step);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -866,8 +875,10 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
|
||||||
if (range->get_value("min", lower))
|
if (range->get_value("min", lower))
|
||||||
{
|
{
|
||||||
range->get_value("max", upper);
|
range->get_value("max", upper);
|
||||||
|
step = (upper - lower) / 10.0f;
|
||||||
|
range->get_value("step", step);
|
||||||
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
||||||
, true, &lower, &upper);
|
, true, &lower, &upper, &step);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -889,25 +900,25 @@ SANE_Option_Descriptor* hg_sane_middleware::from_json(scanner_handle h, const st
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
||||||
, false, NULL, NULL);
|
, false, NULL, NULL, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (val == "bool")
|
else if (val == "bool")
|
||||||
{
|
{
|
||||||
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
||||||
, false, NULL, NULL);
|
, false, NULL, NULL, NULL);
|
||||||
ret->type = SANE_TYPE_BOOL;
|
ret->type = SANE_TYPE_BOOL;
|
||||||
}
|
}
|
||||||
else if (val == "button")
|
else if (val == "button")
|
||||||
{
|
{
|
||||||
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
||||||
, false, NULL, NULL);
|
, false, NULL, NULL, NULL);
|
||||||
ret->type = SANE_TYPE_BUTTON;
|
ret->type = SANE_TYPE_BUTTON;
|
||||||
}
|
}
|
||||||
else if (val == "group")
|
else if (val == "group")
|
||||||
{
|
{
|
||||||
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
ret = hg_sane_middleware::number_option_to_SANE_descriptor(name.c_str(), title.c_str(), desc.c_str()
|
||||||
, false, NULL, NULL);
|
, false, NULL, NULL, NULL);
|
||||||
ret->type = SANE_TYPE_GROUP;
|
ret->type = SANE_TYPE_GROUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -170,7 +170,7 @@ public:
|
||||||
static SANE_Option_Descriptor* string_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
static SANE_Option_Descriptor* string_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
||||||
, const std::vector<std::string>& values);
|
, const std::vector<std::string>& values);
|
||||||
static SANE_Option_Descriptor* number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
static SANE_Option_Descriptor* number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
||||||
, bool double_val, double* lower, double* upper); // NO constraint if lower or upper were NULL
|
, bool double_val, double* lower, double* upper, double* step); // NO constraint if lower or upper were NULL
|
||||||
static SANE_Option_Descriptor* number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
static SANE_Option_Descriptor* number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
||||||
, const std::vector<int>& values); // NO constraint if values was empty
|
, const std::vector<int>& values); // NO constraint if values was empty
|
||||||
static SANE_Option_Descriptor* number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
static SANE_Option_Descriptor* number_option_to_SANE_descriptor(const char* name, const char* title, const char* desc
|
||||||
|
|
Loading…
Reference in New Issue