code_twain/sln/usb_tools/DlgScanner.h

137 lines
3.5 KiB
C++

#pragma once
// CDlgScanner 对话框
#include "../../../code_device/hgdriver/hgdev/hg_scanner.h"
#include <libusb-1.0/libusb.h>
#include "opt_ui/DlgSetting.h"
#include <huagao/brand.h>
#include <base/utils.h>
class CDlgScanner;
namespace usb
{
typedef struct _end_point
{
BYTE iface = -1;
BYTE type = -1;
BYTE addr = -1;
size_t packet = 0;
}USBEP;
typedef struct _usb_pnp
{
libusb_context* ctx = NULL;
libusb_device* device = NULL;
libusb_device_handle* handle = NULL;
CDlgScanner* dlg = NULL;
WORD vid = 0;
WORD pid = 0;
bool arrive = true;
std::vector<USBEP> eps;
}USBPNP, * LPUSBPNP;
std::wstring now(void);
const wchar_t* error_name(int err, wchar_t* unk = NULL);
std::wstring a2u(const char* ansi);
std::string u2a(const wchar_t* unic);
void enum_endpoints(libusb_device* device, std::vector<USBEP>& eps);
const wchar_t* ep_type(BYTE type);
BYTE ep_type(const wchar_t* str);
}
enum
{
WM_USB_PNP = WM_USER + 1001,
WM_RCV_MSG,
WM_OPENNING_DLG_CLOSED,
WM_TRAY_MSG,
WM_TIMER_CANCEL_TOPMOST,
};
class CDlgScanner : public CDialogEx
{
DECLARE_DYNAMIC(CDlgScanner)
enum
{
FILE_TX_RECEIVE = 1 << 0,
FILE_TX_SEND = 1 << 1,
};
HWND parent_;
hg_scanner* scanner_;
volatile int auto_tx_ = 0;
uint32_t auto_tx_file_;
HANDLE auto_wait_;
dlg_setting *setting_ui_;
SANEAPI sane_api_;
std::wstring img_root_;
uint32_t img_cnt_;
uint32_t paper_cnt_;
uint32_t max_sent_;
uint32_t max_cmd_;
uint32_t bulk_statu_tick_ = 0;
safe_thread threads_;
public:
CDlgScanner(CWnd* pParent = nullptr); // 标准构造函数
virtual ~CDlgScanner();
// 对话框数据
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_SCANNER };
#endif
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
virtual BOOL OnInitDialog();
virtual BOOL PreTranslateMessage(MSG* pMsg);
DECLARE_MESSAGE_MAP()
int refresh_bulk_status(bool en_dev_log = false);
void thread_auto_tx_file(void);
void enable_buttons(bool enable);
void set_text(UINT id, const wchar_t* text);
bool is_checked(UINT id);
void set_check(UINT id, bool checked);
void click_repeat(bool enable_buttons = false, bool enable = true);
public:
void set_device(ONLNSCANNER* pnp);
bool is_online(void);
void get_option(const char* name, void* value, size_t size);
int get_all_option(std::string& opts_json);
int set_option(const char* name, void* value, int type, size_t len, size_t max_len, int* after);
public:
CTabCtrl tab_opt_;
CTabCtrl tab_oper_;
afx_msg void OnTcnSelchangeTabOper(NMHDR* pNMHDR, LRESULT* pResult);
afx_msg void OnBnClickedOk();
afx_msg void OnBnClickedButtonResetBulk();
afx_msg void OnBnClickedButtonBrowseSavingPath();
afx_msg void OnBnClickedButtonScan();
afx_msg void OnBnClickedButtonBrowseFile();
afx_msg void OnBnClickedButtonSendFile();
afx_msg void OnBnClickedButtonRecvFile();
afx_msg void OnBnClickedButtonStartProgram();
afx_msg void OnBnClickedButtonSendEp0();
afx_msg void OnTimer(UINT_PTR nIDEvent);
afx_msg void OnBnClickedCheckAuto();
afx_msg void OnBnClickedButtonRefresh();
afx_msg void OnBnClickedCheckRepeat();
afx_msg LRESULT OnSetText(WPARAM wp, LPARAM lp);
afx_msg LRESULT OnIsButtonChecked(WPARAM wp, LPARAM lp);
afx_msg LRESULT OnSetButtonChecked(WPARAM wp, LPARAM lp);
afx_msg LRESULT OnEnableCtrls(WPARAM wp, LPARAM lp);
afx_msg LRESULT OnDeviceStatus(WPARAM wp, LPARAM lp);
afx_msg LRESULT OnTransDiretion(WPARAM wp, LPARAM lp);
afx_msg LRESULT OnTransProgress(WPARAM wp, LPARAM lp);
afx_msg void OnCbnSelchangeComboBufSize();
CComboBox buf_;
afx_msg void OnDestroy();
CProgressCtrl tx_prog_;
};