2022-12-15 06:12:53 +00:00
|
|
|
#include "hgscanner.h"
|
2022-12-26 08:24:20 +00:00
|
|
|
#include <QMessageBox>
|
2022-12-26 10:38:34 +00:00
|
|
|
#include "form_maininterface.h"
|
2023-01-04 06:28:44 +00:00
|
|
|
#include "form_burnmode.h"
|
2023-01-06 07:17:48 +00:00
|
|
|
#include "dialog_inputserialnum.h"
|
2022-12-27 08:25:47 +00:00
|
|
|
#include "dialog_userinput.h"
|
2022-12-28 13:03:01 +00:00
|
|
|
#include <QDebug>
|
2022-12-15 06:12:53 +00:00
|
|
|
|
2023-01-06 07:17:48 +00:00
|
|
|
hgscanner::hgscanner(Form_mainInterface *form, Form_BurnMode *burnMode, Dialog_InputSerialNum *inputSnDlg, SANE_Handle h)
|
2022-12-26 10:38:34 +00:00
|
|
|
: m_interface(form)
|
2023-01-04 06:28:44 +00:00
|
|
|
, m_burnMode(burnMode)
|
2023-01-06 07:17:48 +00:00
|
|
|
, m_inputSnDlg(inputSnDlg)
|
2022-12-26 10:38:34 +00:00
|
|
|
, devHandle_(h)
|
2022-12-15 06:12:53 +00:00
|
|
|
{
|
2022-12-27 11:46:31 +00:00
|
|
|
cb_ = nullptr;
|
2022-12-15 06:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hgscanner::~hgscanner()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
parameter* hgscanner::get_user_input(data_from from, value_type type, const wchar_t* title, const wchar_t* desc)
|
|
|
|
{
|
2022-12-27 08:25:47 +00:00
|
|
|
if (from == DATA_FROM_USER)
|
|
|
|
{
|
2022-12-28 13:03:01 +00:00
|
|
|
Dialog_UserInput dlg(type, QString::fromStdWString(title), desc, m_interface);
|
2022-12-27 08:25:47 +00:00
|
|
|
if (dlg.exec())
|
|
|
|
{
|
|
|
|
return dlg.getParam();
|
|
|
|
}
|
|
|
|
}
|
2022-12-15 06:12:53 +00:00
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void hgscanner::test_callback(const wchar_t* name, test_event ev, void* data, size_t flag)
|
|
|
|
{
|
2022-12-27 08:25:47 +00:00
|
|
|
if (ev == TEST_EVENT_TIPS)
|
|
|
|
{
|
2022-12-15 06:12:53 +00:00
|
|
|
|
2022-12-29 09:54:32 +00:00
|
|
|
}
|
|
|
|
else if (ev == TEST_EVENT_NOT_FIND_TEST)
|
|
|
|
{
|
|
|
|
QString info = QObject::tr("Not find test item");
|
2023-01-04 06:28:44 +00:00
|
|
|
|
|
|
|
if (m_interface != nullptr)
|
|
|
|
{
|
|
|
|
emit m_interface->testResult(info);
|
|
|
|
}
|
|
|
|
else if (m_burnMode != nullptr)
|
|
|
|
{
|
2023-01-04 14:24:41 +00:00
|
|
|
emit m_burnMode->testResult(flag);
|
2023-01-04 06:28:44 +00:00
|
|
|
}
|
2022-12-29 09:54:32 +00:00
|
|
|
}
|
|
|
|
else if (ev == TEST_EVENT_IO_FAIL)
|
|
|
|
{
|
2022-12-30 10:30:02 +00:00
|
|
|
QString info;
|
2022-12-30 02:43:17 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
{
|
2022-12-30 10:30:02 +00:00
|
|
|
info = QObject::tr("failed: ") + QString::fromStdWString((const wchar_t*)data);
|
2022-12-30 02:43:17 +00:00
|
|
|
}
|
2023-01-04 06:28:44 +00:00
|
|
|
|
|
|
|
if (m_interface != nullptr)
|
|
|
|
{
|
|
|
|
emit m_interface->testResult(info);
|
|
|
|
}
|
|
|
|
else if (m_burnMode != nullptr)
|
|
|
|
{
|
2023-01-04 14:24:41 +00:00
|
|
|
emit m_burnMode->testResult(flag);
|
2023-01-04 06:28:44 +00:00
|
|
|
}
|
2022-12-29 09:54:32 +00:00
|
|
|
}
|
|
|
|
else if (ev == TEST_EVENT_MANUAL_CONFIRMATION)
|
|
|
|
{
|
2022-12-30 10:30:02 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
{
|
2023-01-06 07:17:48 +00:00
|
|
|
if (m_inputSnDlg != nullptr)
|
|
|
|
emit m_inputSnDlg->testResult();
|
2023-01-04 06:28:44 +00:00
|
|
|
}
|
2022-12-27 08:25:47 +00:00
|
|
|
}
|
|
|
|
else if (ev == TEST_EVENT_RESULT)
|
|
|
|
{
|
2022-12-30 10:30:02 +00:00
|
|
|
QString info;
|
2022-12-30 02:43:17 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
{
|
|
|
|
if (flag)
|
2022-12-30 10:30:02 +00:00
|
|
|
info = QObject::tr("success: ") + QString::fromStdWString((const wchar_t*)data);
|
2022-12-30 02:43:17 +00:00
|
|
|
else
|
2022-12-30 10:30:02 +00:00
|
|
|
info = QObject::tr("failed: ") + QString::fromStdWString((const wchar_t*)data);
|
2022-12-30 02:43:17 +00:00
|
|
|
}
|
2023-01-04 06:28:44 +00:00
|
|
|
if (m_interface != nullptr)
|
|
|
|
{
|
|
|
|
emit m_interface->testResult(info);
|
|
|
|
}
|
|
|
|
else if (m_burnMode != nullptr)
|
|
|
|
{
|
2023-01-04 14:24:41 +00:00
|
|
|
emit m_burnMode->testResult(flag);
|
2023-01-04 06:28:44 +00:00
|
|
|
}
|
2022-12-27 08:25:47 +00:00
|
|
|
}
|
2023-01-05 09:46:52 +00:00
|
|
|
else if (ev == TEST_EVENT_DISTORTION_VAL)
|
2022-12-28 06:57:00 +00:00
|
|
|
{
|
2023-01-09 08:45:22 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
{
|
2023-01-09 10:48:00 +00:00
|
|
|
// qDebug() << ((SANE_DISTORTION_VAL*)data)->w;
|
|
|
|
// qDebug() << ((SANE_DISTORTION_VAL*)data)->h;
|
|
|
|
// qDebug() << ((SANE_DISTORTION_VAL*)data)->scaleXY;
|
|
|
|
|
|
|
|
if (m_interface != nullptr)
|
|
|
|
{
|
|
|
|
emit m_interface->testDistortion(*((SANE_DISTORTION_VAL*)data));
|
|
|
|
}
|
2023-01-09 08:45:22 +00:00
|
|
|
}
|
2022-12-28 06:57:00 +00:00
|
|
|
}
|
2022-12-29 16:07:01 +00:00
|
|
|
else if (ev == TEST_EVENT_FALT_INFO)
|
|
|
|
{
|
2022-12-30 10:30:02 +00:00
|
|
|
QString info;
|
2022-12-30 08:49:55 +00:00
|
|
|
if (data != nullptr)
|
|
|
|
{
|
2022-12-30 10:30:02 +00:00
|
|
|
info = QString::fromStdWString((const wchar_t*)data);
|
2022-12-30 08:49:55 +00:00
|
|
|
emit m_interface->testCorrectInfo(info);
|
|
|
|
}
|
2022-12-29 16:07:01 +00:00
|
|
|
}
|
2022-12-27 08:25:47 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2022-12-15 06:12:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int hgscanner::register_sane_callback(sane_callback cb, void* param)
|
|
|
|
{
|
2022-12-15 11:53:41 +00:00
|
|
|
cb_ = cb;
|
2022-12-15 06:12:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hgscanner::unregister_sane_callback(sane_callback cb)
|
|
|
|
{
|
2022-12-15 11:53:41 +00:00
|
|
|
|
2022-12-15 06:12:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int hgscanner::io_control(unsigned long code, void* data, unsigned* len)
|
|
|
|
{
|
|
|
|
sane_io_control(devHandle_, code, data, len);
|
|
|
|
return 0;
|
2022-12-26 08:24:20 +00:00
|
|
|
}
|