休眠时间映射到TIME_TO_SLEEP属性
This commit is contained in:
parent
f4ac35d396
commit
5f60310cc0
|
@ -763,6 +763,38 @@ float trans_range(float val, float min_from, float max_from, float min_to, float
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int twain_val;
|
||||||
|
std::string drv_str;
|
||||||
|
}g_sleep_map[] = {{SANE_POWER_NONE, "\344\270\215\344\274\221\347\234\240"}
|
||||||
|
, {SANE_POWER_MINUTES_5, "\344\272\224\345\210\206\351\222\237"}
|
||||||
|
, {SANE_POWER_MINUTES_10, "\345\215\201\345\210\206\351\222\237"}
|
||||||
|
, {SANE_POWER_MINUTES_20, ""}
|
||||||
|
, {SANE_POWER_MINUTES_30, "\345\215\212\345\260\217\346\227\266"}
|
||||||
|
, {SANE_POWER_MINUTES_60, "\344\270\200\345\260\217\346\227\266"}
|
||||||
|
, {SANE_POWER_MINUTES_120, "\344\270\244\345\260\217\346\227\266"}
|
||||||
|
, {SANE_POWER_MINUTES_240, "\345\233\233\345\260\217\346\227\266"}
|
||||||
|
};
|
||||||
|
static int sleep_time_2_twain(const char* utf8)
|
||||||
|
{
|
||||||
|
for (auto& v : g_sleep_map)
|
||||||
|
if (v.drv_str == utf8)
|
||||||
|
return v.twain_val;
|
||||||
|
|
||||||
|
return SANE_POWER_NONE;
|
||||||
|
}
|
||||||
|
static std::string sleep_time_from_twain(int twain)
|
||||||
|
{
|
||||||
|
if (twain == SANE_POWER_MINUTES_20)
|
||||||
|
twain = SANE_POWER_MINUTES_30;
|
||||||
|
for (auto& v : g_sleep_map)
|
||||||
|
if (v.twain_val == twain)
|
||||||
|
return v.drv_str;
|
||||||
|
|
||||||
|
return g_sleep_map[0].drv_str;
|
||||||
|
}
|
||||||
|
|
||||||
static void log_attr_access(int attr, int method)
|
static void log_attr_access(int attr, int method)
|
||||||
{
|
{
|
||||||
wchar_t msg[128] = { 0 };
|
wchar_t msg[128] = { 0 };
|
||||||
|
@ -3158,32 +3190,40 @@ void huagao_ds::init_support_caps(void)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SANE_ID(ex_power) > 0)
|
//if (SANE_ID(ex_power) > 0)
|
||||||
{
|
{
|
||||||
m_query[(CapType)(CapTypeEx::CAP_TYPE_EX_POWER_LEVEL)] = msgSupportGetAllSetReset;
|
m_query[(CapType)(CapTypeEx::CAP_TYPE_EX_POWER_LEVEL)] = msgSupportGetAllSetReset;
|
||||||
m_caps[(CapType)(CapTypeEx::CAP_TYPE_EX_POWER_LEVEL)] = [this](Msg msg, Capability& data)->Result {
|
m_caps[(CapType)(CapTypeEx::CAP_TYPE_EX_POWER_LEVEL)] = [this](Msg msg, Capability& data)->Result {
|
||||||
log_attr_access((int)CapTypeEx::CAP_TYPE_EX_POWER_LEVEL, (int)msg);
|
log_attr_access((int)CapTypeEx::CAP_TYPE_EX_POWER_LEVEL, (int)msg);
|
||||||
int cur = SANE_POWER_MINUTES_30, def = SANE_POWER_MINUTES_30;
|
int cur = SANE_POWER_NONE, def = SANE_POWER_NONE;
|
||||||
std::vector<int> all;
|
std::vector<std::string> all;
|
||||||
GET_SANE_OPT_EX(int, scanner_, ex_power, NULL, &all);
|
GET_SANE_OPT(std::string, scanner_, TIME_TO_SLEEP, NULL, &all);
|
||||||
cur = all[sane_opts::RANGE_POS_CURRENT];
|
cur = sleep_time_2_twain(all[sane_opts::RANGE_POS_CURRENT].c_str());
|
||||||
def = all[sane_opts::RANGE_POS_DEFAULT];
|
def = sleep_time_2_twain(all[sane_opts::RANGE_POS_DEFAULT].c_str());
|
||||||
if (Msg::Set == msg || Msg::Reset == msg) {
|
if (Msg::Set == msg || Msg::Reset == msg) {
|
||||||
if (msg == Msg::Set)
|
if (msg == Msg::Set)
|
||||||
def = data.currentItem<UInt32>();
|
def = data.currentItem<UInt32>();
|
||||||
|
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
SET_SANE_OPT_EX(ret, scanner_, ex_power, &def);
|
std::string str(sleep_time_from_twain(def));
|
||||||
|
SET_SANE_OPT(ret, scanner_, TIME_TO_SLEEP, &str);
|
||||||
return ret == SCANNER_ERR_OK ? success() : badValue();
|
return ret == SCANNER_ERR_OK ? success() : badValue();
|
||||||
}
|
}
|
||||||
UInt32 now = cur, init = def, ind = 0,
|
UInt32 now = cur, init = def, ind = 0,
|
||||||
curInd = distance<int>(all, cur),
|
curInd = 0,
|
||||||
defInd = distance<int>(all, def);
|
defInd = 0;
|
||||||
std::list<UInt32> vals;
|
std::list<UInt32> vals;
|
||||||
for (size_t i = sane_opts::RANGE_POS_ENUM_BEGIN; i < all.size(); ++i)
|
for (size_t i = sane_opts::RANGE_POS_ENUM_BEGIN; i < all.size(); ++i)
|
||||||
{
|
{
|
||||||
vals.push_back(all[i]);
|
int v = sleep_time_2_twain(all[i].c_str());
|
||||||
|
if (v == cur)
|
||||||
|
curInd = i;
|
||||||
|
if (v == def)
|
||||||
|
defInd = i;
|
||||||
|
vals.push_back(v);
|
||||||
}
|
}
|
||||||
|
curInd -= sane_opts::RANGE_POS_ENUM_BEGIN;
|
||||||
|
defInd -= sane_opts::RANGE_POS_ENUM_BEGIN;
|
||||||
return CapSupGetAllResetEx<UInt32, UInt32, (CapType)CapTypeEx::CAP_TYPE_EX_POWER_LEVEL>(msg, data, vals, now, init, curInd, defInd);
|
return CapSupGetAllResetEx<UInt32, UInt32, (CapType)CapTypeEx::CAP_TYPE_EX_POWER_LEVEL>(msg, data, vals, now, init, curInd, defInd);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue