#include "hgscanner.h" #include #include "form_maininterface.h" #include "form_burnmode.h" #include "dialog_inputserialnum.h" #include "dialog_userinput.h" #include hgscanner::hgscanner(Form_mainInterface *form, Form_BurnMode *burnMode, Dialog_InputSerialNum *inputSnDlg, SANE_Handle h) : m_interface(form) , m_burnMode(burnMode) , m_inputSnDlg(inputSnDlg) , devHandle_(h) , m_distortValue(0.0) , m_sleepTime(0) , m_speedMode(0) , m_devSn("") , m_devFw("") , m_devModel("") , m_cpu(0) , m_disk(0) { cb_ = nullptr; } hgscanner::~hgscanner() { } parameter* hgscanner::get_user_input(data_from from, value_type type, const wchar_t* title, const wchar_t* desc) { if (from == DATA_FROM_USER) { Dialog_UserInput dlg(type, QString::fromStdWString(title), desc, m_interface); if (wcscmp(L"SET_DISTORTION_VAL", title) == 0) { dlg.setDistortValue(m_distortValue); } if (dlg.exec()) { return dlg.getParam(); } } return nullptr; } void hgscanner::test_callback(const wchar_t* name, test_event ev, void* data, size_t flag) { if (ev == TEST_EVEB_GET_DEVICE_CONFIG_VIDPID) { int vidpid = *(int*)data; m_vidPid.Value = vidpid; } else if (ev == TEST_EVEB_GET_DEVICE_CONFIG_SP) { m_speedMode = *(int*)data; } else if (ev == TEST_EVEB_GET_DEVICE_CONFIG_SLEEPTIME) { m_sleepTime = *(int*)data; } else if (ev == TEST_EVEB_GET_DEVICE_CONFIG_SN) { m_devSn = QString::fromStdWString((const wchar_t*)data); } else if (ev == TEST_EVEB_GET_DEVICE_CONFIG_FW) { m_devFw = QString::fromStdWString((const wchar_t*)data); } else if (ev == TEST_EVEB_GET_DEVICE_CONFIG_DEVS_MODEL) { m_devModel = QString::fromStdWString((const wchar_t*)data); } if(ev == TEST_EVEB_GET_DEVICE_DEVS_CPU) { m_cpu = *(int*)data; } else if (ev == TEST_EVEB_GET_DEVICE_DEVS_DISK) { m_disk = *(int*)data; } if (ev == TEST_EVENT_TIPS) { } else if (ev == TEST_EVENT_NOT_FIND_TEST) { QString info = QObject::tr("Not find test item"); if (m_interface != nullptr) { emit m_interface->testResult(info); } else if (m_burnMode != nullptr) { emit m_burnMode->testResult(flag); } } else if (ev == TEST_EVENT_IO_FAIL) { QString info; if (data != nullptr) { info = QObject::tr("failed: ") + QString::fromStdWString((const wchar_t*)data); if (m_interface != nullptr) { emit m_interface->testResult(info); } else if (m_burnMode != nullptr) { emit m_burnMode->testResult(flag); } } } else if (ev == TEST_EVENT_MANUAL_CONFIRMATION) { if (data != nullptr) { if (m_inputSnDlg != nullptr) emit m_inputSnDlg->testResult(); } } else if (ev == TEST_EVENT_RESULT) { QString info; if (wcscmp(name, HGPDTTOOLDB_NAME_GET_DEVICE_CONFIG) == 0) { if (m_interface != nullptr) { emit m_interface->testGetDevCfgInfo((int)m_vidPid.VID, (int)m_vidPid.PID, m_sleepTime, m_speedMode, m_devSn, m_devFw, m_devModel); } } if (wcscmp(name, HGPDTTOOLDB_NAME_GET_DEVICE_CPU_DISK) == 0) { if (m_interface != nullptr) { emit m_interface->testGetDevCpuDisk(m_cpu, m_disk); } } bool isGetDevdistortion = false; if (wcscmp(name, HGPDTTOOLDB_NAME_CONFIRM_DISTORTION_VAL) == 0) { isGetDevdistortion = true; if (m_interface != nullptr) { float* value = (float*)data; float q = value[0]; float w = value[1]; float e = value[2]; emit m_interface->testGetDevdistortion(value[0], value[1], value[2]); } } if (data != nullptr && !isGetDevdistortion) { if (flag) info = QObject::tr("success: ") + QString::fromStdWString((const wchar_t*)data); else info = QObject::tr("failed: ") + QString::fromStdWString((const wchar_t*)data); } if (m_interface != nullptr) { emit m_interface->testResult(info); emit m_interface->testOpenCacheFile(QString::fromStdWString(name)); } else if (m_burnMode != nullptr) { emit m_burnMode->testResult(flag); } } else if (ev == TEST_EVENT_DISTORTION_VAL) { if (data != nullptr) { if (m_interface != nullptr) { emit m_interface->testDistortion(*((SANE_DISTORTION_VAL*)data)); } } } else if (ev == TEST_EVENT_FALT_INFO) { QString info; if (data != nullptr) { info = QString::fromStdWString((const wchar_t*)data); emit m_interface->testCorrectInfo(info); } } else if (ev == TEST_EVENT_HAVE_IMAGE) { SANE_Image *sane_img = (SANE_Image *)data; HGUInt imgType = 0; if (sane_img->header.format == SANE_FRAME_GRAY) { if (1 == sane_img->header.depth) imgType = HGBASE_IMGTYPE_BINARY; else if (8 == sane_img->header.depth) imgType = HGBASE_IMGTYPE_GRAY; } else if (sane_img->header.format == SANE_FRAME_RGB) { imgType = HGBASE_IMGTYPE_RGB; } HGByte *imgData = sane_img->data; HGImageInfo imgInfo = {(HGUInt)sane_img->header.pixels_per_line, (HGUInt)sane_img->header.lines, imgType, (HGUInt)sane_img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP}; HGImage img = nullptr; HGBase_CreateImageFromData(imgData, &imgInfo, nullptr, imgType, HGBASE_IMGORIGIN_TOP, &img); if (nullptr != img) { emit m_interface->testResultImg(img); } } } int hgscanner::register_sane_callback(sane_callback cb, void* param) { cb_ = cb; return 0; } int hgscanner::unregister_sane_callback(sane_callback cb) { return 0; } int hgscanner::io_control(unsigned long code, void* data, unsigned* len) { return sane_io_control(devHandle_, code, data, len); } void hgscanner::setDistortValue(double value) { m_distortValue = value; }