diff --git a/huagao/Device/GScan.h b/huagao/Device/GScan.h index f6613481..6a5d0830 100644 --- a/huagao/Device/GScan.h +++ b/huagao/Device/GScan.h @@ -61,7 +61,9 @@ typedef enum tagUsbSupported { // PC繁忙或出错 PC_SCAN_BUSY_or_ERROR = 73, //USB 未连接 - USB_DISCONNECTED = 200 + USB_DISCONNECTED = 200, + //用户点击停止 + USER_STOP = 201 } UsbSupported, * PUsbSupported; @@ -71,10 +73,10 @@ enum tagEventIndex EVENT_NUM }; -class DiscardBlank; class CImageApply; class IUsb; class ImageMatQueue; +typedef void(*deviceevent_callback)(int eventID, void* userdata); class IScanner { @@ -82,7 +84,8 @@ public: IScanner() { bFilterMsg = false; } virtual ~IScanner() { bFilterMsg = true; } void ResetMsgFiter() { bFilterMsg = true; } - virtual void open(int vid, int pid) = 0;; + virtual void open(int vid, int pid) = 0; + virtual void regist_deviceevent_callback(deviceevent_callback callback, void* usrdata = 0) = 0; virtual int aquire_bmpdata(std::vector& bmpdata) = 0; virtual BOOL IsConnected() = 0; virtual std::string GetFWVersion() = 0; diff --git a/huagao/Device/GScan200.cpp b/huagao/Device/GScan200.cpp index 894f92a9..2a0238d3 100644 --- a/huagao/Device/GScan200.cpp +++ b/huagao/Device/GScan200.cpp @@ -27,6 +27,10 @@ void GScan200::open(int vid, int pid) } } +void GScan200::regist_deviceevent_callback(deviceevent_callback callback, void* usrdata) +{ +} + int GScan200::aquire_bmpdata(std::vector& bmpdata) { return 0; diff --git a/huagao/Device/GScan200.h b/huagao/Device/GScan200.h index 12aa2adb..76866098 100644 --- a/huagao/Device/GScan200.h +++ b/huagao/Device/GScan200.h @@ -11,6 +11,7 @@ public: GScan200(); virtual ~GScan200(); virtual void open(int vid, int pid) override; + virtual void regist_deviceevent_callback(deviceevent_callback callback, void* usrdata = 0) override; virtual int aquire_bmpdata(std::vector& bmpdata) override; virtual BOOL IsConnected() override; virtual std::string GetFWVersion() override; diff --git a/huagao/Device/GScanO200.cpp b/huagao/Device/GScanO200.cpp index 39f79518..e93185a7 100644 --- a/huagao/Device/GScanO200.cpp +++ b/huagao/Device/GScanO200.cpp @@ -143,6 +143,7 @@ typedef enum tagUsbKeyWords : UINT32 } UsbKeyWords, * PUsbKeyWords; GScanO200::GScanO200() : + huagods(NULL), m_bread_fixed_ratio_fromDSP(false) { m_pImages.reset(new ImageMatQueue()); @@ -192,11 +193,22 @@ void GScanO200::open(int vid, int pid) { m_usb = *usbs.begin(); bool ret = m_usb->open(); + USBCB status = { GET_DSP_STATUS ,0,0 }; + if (m_usb.get() && m_usb->is_connected()) + m_usb->write_bulk(&status, sizeof(status)); + + if (m_usb.get() && m_usb->is_connected()) + m_usb->read_bulk(&status, sizeof(status)); if (ret) { m_usb->set_usbhotplug_callback(usbhotplug_callback, this); } } } +void GScanO200::regist_deviceevent_callback(deviceevent_callback callback, void* usrdata) +{ + huagods = usrdata; + dev_callback = callback; +} #ifdef LOG_NORMAL fstream fsaquire; static int aquiretimes = 1; @@ -368,12 +380,14 @@ void GScanO200::Scanner_StartScan(UINT16 count) m_pImages->setscanflags(false); devState = DEV_WRONG; Set_ErrorCode(status.u32_Data); + if (huagods) + dev_callback(status.u32_Data, huagods); return; default: break; } -#ifndef G200 +//#ifndef G200 USBCB paperstatus = { GET_PAPER_STATUS ,0,0 }; if (m_usb.get() && m_usb->is_connected()) m_usb->write_bulk(&paperstatus, sizeof(paperstatus)); @@ -383,9 +397,11 @@ void GScanO200::Scanner_StartScan(UINT16 count) m_pImages->setscanflags(false); devState = DEV_WRONG; Set_ErrorCode(NO_FEED); + if (huagods) + dev_callback(NO_FEED, huagods); return; } -#endif // !G200 +//#endif // !G200 if (gcap.is_duplex) count = count == 65535 ? 65535 : count / 2; @@ -484,6 +500,9 @@ void GScanO200::usbhotplug(bool isleft) m_pImages->setscanflags(false); if (m_usb.get()) m_usb.reset(); + + if (huagods) + dev_callback(USB_DISCONNECTED, huagods); } } @@ -529,6 +548,7 @@ void GScanO200::usbmain() // continue; // } //} + if (sw.elapsed_ms() > 10000) { m_pImages->setscanflags(false); @@ -590,11 +610,15 @@ void GScanO200::usbmain() Set_ErrorCode(usbcb.u32_Data); m_pImages->setscanflags(false); devState = DEV_WRONG; + if (huagods) + dev_callback(usbcb.u32_Data, huagods); #else if (!haveError) { haveError = true; Set_ErrorCode(usbcb.u32_Data); + if (huagods) + dev_callback(usbcb.u32_Data, huagods); } #endif diff --git a/huagao/Device/GScanO200.h b/huagao/Device/GScanO200.h index a68df294..ff9af24c 100644 --- a/huagao/Device/GScanO200.h +++ b/huagao/Device/GScanO200.h @@ -16,6 +16,7 @@ public: virtual ~GScanO200(); // 通过 IGScan 继承 virtual void open(int vid, int pid) override; + virtual void regist_deviceevent_callback(deviceevent_callback callback, void* usrdata = 0) override; virtual int aquire_bmpdata(std::vector& bmpdata) override; virtual BOOL IsConnected() override; virtual std::string GetFWVersion() override; @@ -47,5 +48,7 @@ private: std::shared_ptr m_usb; std::unique_ptr m_threadUsb; GScanCap gcap; + void* huagods; + deviceevent_callback dev_callback; }; diff --git a/huagao/Device/GScanVirtual.cpp b/huagao/Device/GScanVirtual.cpp index b3692c6c..8281e48d 100644 --- a/huagao/Device/GScanVirtual.cpp +++ b/huagao/Device/GScanVirtual.cpp @@ -28,6 +28,10 @@ void GScanVirtual::open(int vid, int pid) fs.close(); } +void GScanVirtual::regist_deviceevent_callback(deviceevent_callback callback, void* usrdata) +{ +} + int GScanVirtual::aquire_bmpdata(std::vector& bmpdata) { StopWatch sw; diff --git a/huagao/Device/GScanVirtual.h b/huagao/Device/GScanVirtual.h index 559f3fdf..b9e81a42 100644 --- a/huagao/Device/GScanVirtual.h +++ b/huagao/Device/GScanVirtual.h @@ -10,6 +10,7 @@ public: virtual ~GScanVirtual(); // 通过 IGScan 继承 virtual void open(int vid, int pid) override; + virtual void regist_deviceevent_callback(deviceevent_callback callback, void* usrdata = 0) override; virtual int aquire_bmpdata(std::vector& bmpdata) override; virtual BOOL IsConnected() override; virtual std::string GetFWVersion() override;