修改libusb_control_transfer返回值为字节数;消除编译警告

This commit is contained in:
gb 2022-07-15 17:56:00 +08:00
parent 6712499fee
commit 287c7f2154
4 changed files with 43 additions and 37 deletions

View File

@ -77,9 +77,12 @@ set OEM=%4
echo oem=%OEM%
echo cpu=%CPU%
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%
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\MSBuild.exe" "%~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\sane\sane.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
if %COMPILE_RANGE%=="" (
%BUILD_CMD% "%~dp0\device\scanner.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

View File

@ -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)
{
// return transfer bytes ...
int ret = LIBUSB_ERROR_NOT_FOUND;
_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.uOffset = val;
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)
{
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
ret = LIBUSB_ERROR_PIPE;

View File

@ -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
__declspec(novtable) struct IRef
struct __declspec(novtable) IRef
{
COM_API_DECLARE(long, add_ref(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, 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, 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, stop(void));

View File

@ -439,7 +439,7 @@ static void copy_type(int& to, UInt32 from)
}
static void copy_type(Fix32& to, double from)
{
to = from;
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);
int res = 200;
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL, NULL);
data.setXResolution(res);
data.setYResolution(res);
GET_SANE_OPT(int, scanner_, resolution, &res, NULL, NULL, NULL);
data.setXResolution((float)res);
data.setYResolution((float)res);
data.compression(m_compression);
}
@ -963,7 +963,7 @@ Result huagao_ds::imageLayoutGet(const Identity&, ImageLayout& data)
return seqError();
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);
data.setDocumentNumber(1);
@ -1028,7 +1028,7 @@ Result huagao_ds::imageMemXferGet(const Identity& origin, ImageMemXfer& data)
data.setColumns(img->width());
data.setRows(rows);
data.setXOffset(0);
data.setYOffset(off / line_l);
data.setYOffset(UInt32(off / line_l));
data.setCompression(m_compression);
if (m_compression != Compression::None)
{
@ -1048,7 +1048,7 @@ Result huagao_ds::imageMemXferGet(const Identity& origin, ImageMemXfer& data)
if (off < img->bytes())
{
pending_xfer_.img = img;
pending_xfer_.off = off;
pending_xfer_.off = (unsigned int)off;
img->add_ref();
ret = success();
}
@ -1085,7 +1085,7 @@ Result huagao_ds::imageNativeXferGet(const Identity& id, ImageNativeXfer& data)
off += total;
if (off >= img->bytes())
break;
total = img->bytes() - off;
total = img->bytes() - (unsigned int)off;
src = img->data(off, &total);
}
img->release();
@ -1131,7 +1131,7 @@ Twpp::Result huagao_ds::imageFileXferGet(const Twpp::Identity& origin)
ret = Result(ReturnCode::XferDone, ConditionCode::Success);
break;
}
total = img->bytes() - off;
total = img->bytes() - (unsigned int)off;
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) {
//FileTools::writelog(log_ERROR, e.what());
UNREFERENCED_PARAMETER(e);
return badValue();
}
}
@ -1438,7 +1439,7 @@ void huagao_ds::init_support_caps(void)
case Msg::Get:
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();
}
else if (limit == VAL_LIMIT_ENUM)
@ -1449,11 +1450,11 @@ void huagao_ds::init_support_caps(void)
for (const auto& v : values)
{
Fix32 f;
float vf = v;
float vf = (float)v;
copy_type(f, vf);
vals.push_back(f);
}
float nowf = now, initf = init;
float nowf = (float)now, initf = (float)init;
copy_type(Now, nowf);
copy_type(Init, initf);
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);
}
case Msg::GetCurrent:
data = Capability::createOneValue<CapType::IXResolution>(Fix32(now));
data = Capability::createOneValue<CapType::IXResolution>(Fix32((float)now));
return success();
case Msg::GetDefault:
data = Capability::createOneValue<CapType::IXResolution>(Fix32(init));
data = Capability::createOneValue<CapType::IXResolution>(Fix32((float)init));
return success();
case Msg::Reset:
data = Capability::createOneValue<CapType::IXResolution>(Fix32(init));
data = Capability::createOneValue<CapType::IXResolution>(Fix32((float)init));
case Msg::Set: {
auto mech = data.currentItem<CapType::IXResolution>();
int ret = SCANNER_ERR_OK;
float resl = (float)mech;
int resli = resl;
int resli = (int)resl;
SET_SANE_OPT(ret, scanner_, resolution, &resli);
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 ret = SCANNER_ERR_OK;
GET_SANE_OPT_RANGE(int, scanner_, bright, &now, &init, &l, &u, &step);
float sf = trans_range(step, l, u, -1000.0f, 1000.0f),
nf = trans_range(now, l, u, -1000.0f, 1000.0f),
initf = trans_range(init, l, u, -1000.0f, 1000.0f);
float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f),
nf = trans_range((float)now, (float)l, (float)u, -1000.0f, 1000.0f),
initf = trans_range((float)init, (float)l, (float)u, -1000.0f, 1000.0f);
switch (msg) {
case Msg::Get:
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)
return badValue();
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);
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 ret = SCANNER_ERR_OK;
GET_SANE_OPT_RANGE(int, scanner_, contrast, &now, &init, &l, &u, &step);
float sf = trans_range(step, l, u, -1000.0f, 1000.0f),
nf = trans_range(now, l, u, -1000.0f, 1000.0f),
initf = trans_range(init, l, u, -1000.0f, 1000.0f);
float sf = trans_range((float)step, (float)l, (float)u, -1000.0f, 1000.0f),
nf = trans_range((float)now, (float)l, (float)u, -1000.0f, 1000.0f),
initf = trans_range((float)init, (float)l, (float)u, -1000.0f, 1000.0f);
switch (msg) {
case Msg::Get:
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)
return badValue();
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);
return ret == SCANNER_ERR_OK ? success() : badValue();
}
@ -2037,7 +2038,7 @@ void huagao_ds::init_support_caps(void)
auto mech = data.currentItem<UInt32>();
if (mech > u || mech < l)
return badValue();
float v = mech;
float v = (float)mech;
v /= 100.0f;
SET_SANE_OPT(ret, scanner_, search_hole_range, &v);
return ret == SCANNER_ERR_OK ? success() : badValue();
@ -2137,12 +2138,12 @@ void huagao_ds::init_support_caps(void)
if (mech < 10 || mech > 300)
return badValue();
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);
return ret == SCANNER_ERR_OK ? success() : badValue();
}
UInt32 Now = trans_range(now, l, u, 10, 300) + .5f,
Init = trans_range(init, l, u, 10, 300) + .5f;
UInt32 Now = UInt32(trans_range((float)now, (float)l, (float)u, 10.0f, 300.0f) + .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);
};
@ -2475,13 +2476,14 @@ void huagao_ds::init_support_caps_ex(void)
copy_type(Upper, upper); \
copy_type(Step, step); \
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) \
m_query[(CapType)CAP_EX_SANE_##name] = msgSupportGetAllSetReset; \
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); \
if (msg == Msg::Set || msg == Msg::Reset) \
{ \