修改libusb_control_transfer返回值为字节数;消除编译警告
This commit is contained in:
parent
6712499fee
commit
287c7f2154
|
@ -77,9 +77,12 @@ set OEM=%4
|
||||||
echo oem=%OEM%
|
echo oem=%OEM%
|
||||||
echo cpu=%CPU%
|
echo cpu=%CPU%
|
||||||
echo pid=%PID%
|
echo pid=%PID%
|
||||||
|
set BUILD_CMD="C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe"
|
||||||
"%~dp0\sln\release\hgsetver.exe" "%~dp0\twain\brand.h" -oem %OEM% -cpu %CPU% -pid %PID% %COMPILE_RANGE%
|
"%~dp0\sln\release\hgsetver.exe" "%~dp0\twain\brand.h" -oem %OEM% -cpu %CPU% -pid %PID% %COMPILE_RANGE%
|
||||||
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" "%~dp0\device\scanner.vcxproj" /p:Configuration=Release /p:Platform=x86
|
if %COMPILE_RANGE%=="" (
|
||||||
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" "%~dp0\sane\sane.vcxproj" /p:Configuration=Release /p:Platform=x86
|
%BUILD_CMD% "%~dp0\device\scanner.vcxproj" /p:Configuration=Release /p:Platform=x86
|
||||||
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" "%~dp0\twain\twain.vcxproj" /p:Configuration=Release /p:Platform=x86
|
%BUILD_CMD% "%~dp0\sane\sane.vcxproj" /p:Configuration=Release /p:Platform=x86
|
||||||
|
)
|
||||||
|
%BUILD_CMD% "%~dp0\twain\twain.vcxproj" /p:Configuration=Release /p:Platform=x86
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -740,6 +740,7 @@ int usb_device::transfer_bulk(unsigned endpoint, unsigned char* data, int* lengt
|
||||||
}
|
}
|
||||||
int usb_device::transfer_control(uint8_t type, uint8_t req, uint16_t val, uint16_t ind, unsigned char* data, uint16_t len, unsigned timeout)
|
int usb_device::transfer_control(uint8_t type, uint8_t req, uint16_t val, uint16_t ind, unsigned char* data, uint16_t len, unsigned timeout)
|
||||||
{
|
{
|
||||||
|
// return transfer bytes ...
|
||||||
int ret = LIBUSB_ERROR_NOT_FOUND;
|
int ret = LIBUSB_ERROR_NOT_FOUND;
|
||||||
_IO_BLOCK_EX irp;
|
_IO_BLOCK_EX irp;
|
||||||
|
|
||||||
|
@ -756,10 +757,10 @@ int usb_device::transfer_control(uint8_t type, uint8_t req, uint16_t val, uint16
|
||||||
irp.uLength = len;
|
irp.uLength = len;
|
||||||
irp.uOffset = val;
|
irp.uOffset = val;
|
||||||
if (DeviceIoControl((HANDLE)handle_, IOCTL_SEND_USB_REQUEST, &irp, sizeof(irp), data, len, oc->io_bytes(), oc->over_lapped()))
|
if (DeviceIoControl((HANDLE)handle_, IOCTL_SEND_USB_REQUEST, &irp, sizeof(irp), data, len, oc->io_bytes(), oc->over_lapped()))
|
||||||
ret = LIBUSB_SUCCESS;
|
ret = *oc->io_bytes();
|
||||||
else if (GetLastError() == ERROR_IO_PENDING)
|
else if (GetLastError() == ERROR_IO_PENDING)
|
||||||
{
|
{
|
||||||
ret = WaitForSingleObject(oc->over_lapped()->hEvent, timeout) == WAIT_TIMEOUT ? LIBUSB_ERROR_TIMEOUT : LIBUSB_SUCCESS;
|
ret = WaitForSingleObject(oc->over_lapped()->hEvent, timeout) == WAIT_TIMEOUT ? LIBUSB_ERROR_TIMEOUT : *oc->io_bytes();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
ret = LIBUSB_ERROR_PIPE;
|
ret = LIBUSB_ERROR_PIPE;
|
||||||
|
|
|
@ -123,12 +123,12 @@ enum twain_xfer
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef bool(__stdcall* set_opt_value)(void* val, value_role role, void* param); // return false to stop the callback
|
typedef bool(__stdcall* set_opt_value)(void* val, value_role role, void* param); // return false to stop the callback
|
||||||
__declspec(novtable) struct IRef
|
struct __declspec(novtable) IRef
|
||||||
{
|
{
|
||||||
COM_API_DECLARE(long, add_ref(void));
|
COM_API_DECLARE(long, add_ref(void));
|
||||||
COM_API_DECLARE(long, release(void));
|
COM_API_DECLARE(long, release(void));
|
||||||
};
|
};
|
||||||
__declspec(novtable) struct IScanImg : public IRef
|
struct __declspec(novtable) IScanImg : public IRef
|
||||||
{
|
{
|
||||||
COM_API_DECLARE(int, width(void));
|
COM_API_DECLARE(int, width(void));
|
||||||
COM_API_DECLARE(int, line_bytes(void));
|
COM_API_DECLARE(int, line_bytes(void));
|
||||||
|
@ -144,7 +144,7 @@ __declspec(novtable) struct IScanImg : public IRef
|
||||||
COM_API_DECLARE(void, keep_file(bool keep));
|
COM_API_DECLARE(void, keep_file(bool keep));
|
||||||
COM_API_DECLARE(void, copy_header(SANE_Parameters* head));
|
COM_API_DECLARE(void, copy_header(SANE_Parameters* head));
|
||||||
};
|
};
|
||||||
__declspec(novtable) struct ISaneInvoker : public IRef
|
struct __declspec(novtable) ISaneInvoker : public IRef
|
||||||
{
|
{
|
||||||
COM_API_DECLARE(int, start(void));
|
COM_API_DECLARE(int, start(void));
|
||||||
COM_API_DECLARE(int, stop(void));
|
COM_API_DECLARE(int, stop(void));
|
||||||
|
|
|
@ -439,7 +439,7 @@ static void copy_type(int& to, UInt32 from)
|
||||||
}
|
}
|
||||||
static void copy_type(Fix32& to, double from)
|
static void copy_type(Fix32& to, double from)
|
||||||
{
|
{
|
||||||
to = from;
|
to = (float)from;
|
||||||
}
|
}
|
||||||
static void copy_type(Fix32& to, float from)
|
static void copy_type(Fix32& to, float from)
|
||||||
{
|
{
|
||||||
|
@ -947,9 +947,9 @@ Result huagao_ds::imageInfoGet(const Identity&, ImageInfo& data)
|
||||||
data.setWidth(head.pixels_per_line);
|
data.setWidth(head.pixels_per_line);
|
||||||
|
|
||||||
int res = 200;
|
int res = 200;
|
||||||
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL, NULL);
|
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL);
|
||||||
data.setXResolution(res);
|
data.setXResolution((float)res);
|
||||||
data.setYResolution(res);
|
data.setYResolution((float)res);
|
||||||
data.compression(m_compression);
|
data.compression(m_compression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,7 +963,7 @@ Result huagao_ds::imageLayoutGet(const Identity&, ImageLayout& data)
|
||||||
return seqError();
|
return seqError();
|
||||||
|
|
||||||
int res = 200;
|
int res = 200;
|
||||||
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL, NULL);
|
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL);
|
||||||
|
|
||||||
scanner_->get_first_image_header(&head);
|
scanner_->get_first_image_header(&head);
|
||||||
data.setDocumentNumber(1);
|
data.setDocumentNumber(1);
|
||||||
|
@ -1028,7 +1028,7 @@ Result huagao_ds::imageMemXferGet(const Identity& origin, ImageMemXfer& data)
|
||||||
data.setColumns(img->width());
|
data.setColumns(img->width());
|
||||||
data.setRows(rows);
|
data.setRows(rows);
|
||||||
data.setXOffset(0);
|
data.setXOffset(0);
|
||||||
data.setYOffset(off / line_l);
|
data.setYOffset(UInt32(off / line_l));
|
||||||
data.setCompression(m_compression);
|
data.setCompression(m_compression);
|
||||||
if (m_compression != Compression::None)
|
if (m_compression != Compression::None)
|
||||||
{
|
{
|
||||||
|
@ -1048,7 +1048,7 @@ Result huagao_ds::imageMemXferGet(const Identity& origin, ImageMemXfer& data)
|
||||||
if (off < img->bytes())
|
if (off < img->bytes())
|
||||||
{
|
{
|
||||||
pending_xfer_.img = img;
|
pending_xfer_.img = img;
|
||||||
pending_xfer_.off = off;
|
pending_xfer_.off = (unsigned int)off;
|
||||||
img->add_ref();
|
img->add_ref();
|
||||||
ret = success();
|
ret = success();
|
||||||
}
|
}
|
||||||
|
@ -1085,7 +1085,7 @@ Result huagao_ds::imageNativeXferGet(const Identity& id, ImageNativeXfer& data)
|
||||||
off += total;
|
off += total;
|
||||||
if (off >= img->bytes())
|
if (off >= img->bytes())
|
||||||
break;
|
break;
|
||||||
total = img->bytes() - off;
|
total = img->bytes() - (unsigned int)off;
|
||||||
src = img->data(off, &total);
|
src = img->data(off, &total);
|
||||||
}
|
}
|
||||||
img->release();
|
img->release();
|
||||||
|
@ -1131,7 +1131,7 @@ Twpp::Result huagao_ds::imageFileXferGet(const Twpp::Identity& origin)
|
||||||
ret = Result(ReturnCode::XferDone, ConditionCode::Success);
|
ret = Result(ReturnCode::XferDone, ConditionCode::Success);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
total = img->bytes() - off;
|
total = img->bytes() - (unsigned int)off;
|
||||||
src = img->data(off, &total);
|
src = img->data(off, &total);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1217,6 +1217,7 @@ Result huagao_ds::call(const Identity& origin, DataGroup dg, Dat dat, Msg msg, v
|
||||||
}
|
}
|
||||||
catch (const CapabilityException& e) {
|
catch (const CapabilityException& e) {
|
||||||
//FileTools::writelog(log_ERROR, e.what());
|
//FileTools::writelog(log_ERROR, e.what());
|
||||||
|
UNREFERENCED_PARAMETER(e);
|
||||||
return badValue();
|
return badValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1438,7 +1439,7 @@ void huagao_ds::init_support_caps(void)
|
||||||
case Msg::Get:
|
case Msg::Get:
|
||||||
if (limit == VAL_LIMIT_RANGE)
|
if (limit == VAL_LIMIT_RANGE)
|
||||||
{
|
{
|
||||||
data = Capability::createRange<CapType::IXResolution>(Fix32(values[0]), Fix32(values[1]), Fix32(50.0f), Fix32(now), Fix32(init));
|
data = Capability::createRange<CapType::IXResolution>(Fix32((float)values[0]), Fix32((float)values[1]), Fix32(50.0f), Fix32((float)now), Fix32((float)init));
|
||||||
return success();
|
return success();
|
||||||
}
|
}
|
||||||
else if (limit == VAL_LIMIT_ENUM)
|
else if (limit == VAL_LIMIT_ENUM)
|
||||||
|
@ -1449,11 +1450,11 @@ void huagao_ds::init_support_caps(void)
|
||||||
for (const auto& v : values)
|
for (const auto& v : values)
|
||||||
{
|
{
|
||||||
Fix32 f;
|
Fix32 f;
|
||||||
float vf = v;
|
float vf = (float)v;
|
||||||
copy_type(f, vf);
|
copy_type(f, vf);
|
||||||
vals.push_back(f);
|
vals.push_back(f);
|
||||||
}
|
}
|
||||||
float nowf = now, initf = init;
|
float nowf = (float)now, initf = (float)init;
|
||||||
copy_type(Now, nowf);
|
copy_type(Now, nowf);
|
||||||
copy_type(Init, initf);
|
copy_type(Init, initf);
|
||||||
ni = std::distance(vals.begin(), std::find(vals.begin(), vals.end(), Now));
|
ni = std::distance(vals.begin(), std::find(vals.begin(), vals.end(), Now));
|
||||||
|
@ -1461,18 +1462,18 @@ void huagao_ds::init_support_caps(void)
|
||||||
return cap_get_enum_values<Fix32, CapType::IXResolution>(msg, data, vals, Now, Init, ni, ii);
|
return cap_get_enum_values<Fix32, CapType::IXResolution>(msg, data, vals, Now, Init, ni, ii);
|
||||||
}
|
}
|
||||||
case Msg::GetCurrent:
|
case Msg::GetCurrent:
|
||||||
data = Capability::createOneValue<CapType::IXResolution>(Fix32(now));
|
data = Capability::createOneValue<CapType::IXResolution>(Fix32((float)now));
|
||||||
return success();
|
return success();
|
||||||
case Msg::GetDefault:
|
case Msg::GetDefault:
|
||||||
data = Capability::createOneValue<CapType::IXResolution>(Fix32(init));
|
data = Capability::createOneValue<CapType::IXResolution>(Fix32((float)init));
|
||||||
return success();
|
return success();
|
||||||
case Msg::Reset:
|
case Msg::Reset:
|
||||||
data = Capability::createOneValue<CapType::IXResolution>(Fix32(init));
|
data = Capability::createOneValue<CapType::IXResolution>(Fix32((float)init));
|
||||||
case Msg::Set: {
|
case Msg::Set: {
|
||||||
auto mech = data.currentItem<CapType::IXResolution>();
|
auto mech = data.currentItem<CapType::IXResolution>();
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
float resl = (float)mech;
|
float resl = (float)mech;
|
||||||
int resli = resl;
|
int resli = (int)resl;
|
||||||
SET_SANE_OPT(ret, scanner_, resolution, &resli);
|
SET_SANE_OPT(ret, scanner_, resolution, &resli);
|
||||||
return ret == SCANNER_ERR_OK ? success() : badValue();
|
return ret == SCANNER_ERR_OK ? success() : badValue();
|
||||||
}
|
}
|
||||||
|
@ -1948,9 +1949,9 @@ void huagao_ds::init_support_caps(void)
|
||||||
int init = 128, l = 1, u = 255, step = 1, now = 128;
|
int init = 128, l = 1, u = 255, step = 1, now = 128;
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
GET_SANE_OPT_RANGE(int, scanner_, bright, &now, &init, &l, &u, &step);
|
GET_SANE_OPT_RANGE(int, scanner_, bright, &now, &init, &l, &u, &step);
|
||||||
float sf = trans_range(step, l, u, -1000.0f, 1000.0f),
|
float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f),
|
||||||
nf = trans_range(now, l, u, -1000.0f, 1000.0f),
|
nf = trans_range((float)now, (float)l, (float)u, -1000.0f, 1000.0f),
|
||||||
initf = trans_range(init, l, u, -1000.0f, 1000.0f);
|
initf = trans_range((float)init, (float)l, (float)u, -1000.0f, 1000.0f);
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case Msg::Get:
|
case Msg::Get:
|
||||||
data = Capability::createRange<CapType::IBrightness>(Fix32(-1000.0f), Fix32(1000.0f), Fix32(sf), Fix32(nf), Fix32(initf));
|
data = Capability::createRange<CapType::IBrightness>(Fix32(-1000.0f), Fix32(1000.0f), Fix32(sf), Fix32(nf), Fix32(initf));
|
||||||
|
@ -1968,7 +1969,7 @@ void huagao_ds::init_support_caps(void)
|
||||||
if (mech > 1000.0f || mech < -1000.0f)
|
if (mech > 1000.0f || mech < -1000.0f)
|
||||||
return badValue();
|
return badValue();
|
||||||
sf = mech.toFloat();
|
sf = mech.toFloat();
|
||||||
now = trans_range(sf, -1000.0f, 1000.0f, l, u) + .5f;
|
now = (int)(trans_range(sf, -1000.0f, 1000.0f, (float)l, (float)u) + .5f);
|
||||||
SET_SANE_OPT(ret, scanner_, bright, &now);
|
SET_SANE_OPT(ret, scanner_, bright, &now);
|
||||||
return ret == SCANNER_ERR_OK ? success() : badValue();
|
return ret == SCANNER_ERR_OK ? success() : badValue();
|
||||||
}
|
}
|
||||||
|
@ -1982,9 +1983,9 @@ void huagao_ds::init_support_caps(void)
|
||||||
int init = 4, l = 1, u = 7, step = 1, now = 4;
|
int init = 4, l = 1, u = 7, step = 1, now = 4;
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
GET_SANE_OPT_RANGE(int, scanner_, contrast, &now, &init, &l, &u, &step);
|
GET_SANE_OPT_RANGE(int, scanner_, contrast, &now, &init, &l, &u, &step);
|
||||||
float sf = trans_range(step, l, u, -1000.0f, 1000.0f),
|
float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f),
|
||||||
nf = trans_range(now, l, u, -1000.0f, 1000.0f),
|
nf = trans_range((float)now, (float)l, (float)u, -1000.0f, 1000.0f),
|
||||||
initf = trans_range(init, l, u, -1000.0f, 1000.0f);
|
initf = trans_range((float)init, (float)l, (float)u, -1000.0f, 1000.0f);
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case Msg::Get:
|
case Msg::Get:
|
||||||
data = Capability::createRange<CapType::IContrast>(Fix32(-1000.0f), Fix32(1000.0f), Fix32(sf), Fix32(nf), Fix32(initf));
|
data = Capability::createRange<CapType::IContrast>(Fix32(-1000.0f), Fix32(1000.0f), Fix32(sf), Fix32(nf), Fix32(initf));
|
||||||
|
@ -2002,7 +2003,7 @@ void huagao_ds::init_support_caps(void)
|
||||||
if (mech > 1000.0f || mech < -1000.0f)
|
if (mech > 1000.0f || mech < -1000.0f)
|
||||||
return badValue();
|
return badValue();
|
||||||
sf = mech.toFloat();
|
sf = mech.toFloat();
|
||||||
now = trans_range(sf, -1000.0f, 1000.0f, l, u) + .5f;
|
now = (int)(trans_range(sf, -1000.0f, 1000.0f, (float)l, (float)u) + .5f);
|
||||||
SET_SANE_OPT(ret, scanner_, contrast, &now);
|
SET_SANE_OPT(ret, scanner_, contrast, &now);
|
||||||
return ret == SCANNER_ERR_OK ? success() : badValue();
|
return ret == SCANNER_ERR_OK ? success() : badValue();
|
||||||
}
|
}
|
||||||
|
@ -2037,7 +2038,7 @@ void huagao_ds::init_support_caps(void)
|
||||||
auto mech = data.currentItem<UInt32>();
|
auto mech = data.currentItem<UInt32>();
|
||||||
if (mech > u || mech < l)
|
if (mech > u || mech < l)
|
||||||
return badValue();
|
return badValue();
|
||||||
float v = mech;
|
float v = (float)mech;
|
||||||
v /= 100.0f;
|
v /= 100.0f;
|
||||||
SET_SANE_OPT(ret, scanner_, search_hole_range, &v);
|
SET_SANE_OPT(ret, scanner_, search_hole_range, &v);
|
||||||
return ret == SCANNER_ERR_OK ? success() : badValue();
|
return ret == SCANNER_ERR_OK ? success() : badValue();
|
||||||
|
@ -2137,12 +2138,12 @@ void huagao_ds::init_support_caps(void)
|
||||||
if (mech < 10 || mech > 300)
|
if (mech < 10 || mech > 300)
|
||||||
return badValue();
|
return badValue();
|
||||||
int ret = SCANNER_ERR_OK;
|
int ret = SCANNER_ERR_OK;
|
||||||
int val = trans_range(mech, 10, 300, l, u) + .5f;
|
int val = (int)(trans_range((float)mech, 10.0f, 300.0f, (float)l, (float)u) + .5f);
|
||||||
SET_SANE_OPT(ret, scanner_, dogear_size, &val);
|
SET_SANE_OPT(ret, scanner_, dogear_size, &val);
|
||||||
return ret == SCANNER_ERR_OK ? success() : badValue();
|
return ret == SCANNER_ERR_OK ? success() : badValue();
|
||||||
}
|
}
|
||||||
UInt32 Now = trans_range(now, l, u, 10, 300) + .5f,
|
UInt32 Now = UInt32(trans_range((float)now, (float)l, (float)u, 10.0f, 300.0f) + .5f),
|
||||||
Init = trans_range(init, l, u, 10, 300) + .5f;
|
Init = UInt32(trans_range((float)init, (float)l, (float)u, 10.0f, 300.0f) + .5f);
|
||||||
|
|
||||||
return CapSupGetAllResetEx<UInt32, UInt32, (CapType)CapTypeEx::CAP_TYPE_EX_DOGEAR_DIST>(msg, data, Now, Init);
|
return CapSupGetAllResetEx<UInt32, UInt32, (CapType)CapTypeEx::CAP_TYPE_EX_DOGEAR_DIST>(msg, data, Now, Init);
|
||||||
};
|
};
|
||||||
|
@ -2475,13 +2476,14 @@ void huagao_ds::init_support_caps_ex(void)
|
||||||
copy_type(Upper, upper); \
|
copy_type(Upper, upper); \
|
||||||
copy_type(Step, step); \
|
copy_type(Step, step); \
|
||||||
data = Capability::createRange<ttype>((CapType)CAP_EX_SANE_##name, Lower, Upper, Step, Now, Init);\
|
data = Capability::createRange<ttype>((CapType)CAP_EX_SANE_##name, Lower, Upper, Step, Now, Init);\
|
||||||
|
return { ReturnCode::Success, ConditionCode::Success }; \
|
||||||
} \
|
} \
|
||||||
}; \
|
}; \
|
||||||
|
|
||||||
#define SET_SANE_CAP(ctype, ttype, name) \
|
#define SET_SANE_CAP(ctype, ttype, name) \
|
||||||
m_query[(CapType)CAP_EX_SANE_##name] = msgSupportGetAllSetReset; \
|
m_query[(CapType)CAP_EX_SANE_##name] = msgSupportGetAllSetReset; \
|
||||||
m_caps[(CapType)CAP_EX_SANE_##name] = [this](Msg msg, Capability& data) -> Result { \
|
m_caps[(CapType)CAP_EX_SANE_##name] = [this](Msg msg, Capability& data) -> Result { \
|
||||||
ctype now, init, lower, upper, step; \
|
ctype now, init; \
|
||||||
GET_SANE_OPT(ctype, scanner_, name, &now, &init, NULL, NULL); \
|
GET_SANE_OPT(ctype, scanner_, name, &now, &init, NULL, NULL); \
|
||||||
if (msg == Msg::Set || msg == Msg::Reset) \
|
if (msg == Msg::Set || msg == Msg::Reset) \
|
||||||
{ \
|
{ \
|
||||||
|
|
Loading…
Reference in New Issue