261 lines
6.7 KiB
C++
261 lines
6.7 KiB
C++
#include "testwidget.h"
|
|
#include "ui_testwidget.h"
|
|
#include "ThermalSDK.h"
|
|
#include <stdlib.h>
|
|
#include "elouvccameraconverter.h"
|
|
#include <QFileDialog>
|
|
#include <QMessageBox>
|
|
|
|
TestWidget::TestWidget(BaseWidget *parent) :
|
|
BaseWidget(parent),
|
|
ui(new Ui::TestWidget)
|
|
, _txOffset(nullptr)
|
|
, _txDistance(nullptr)
|
|
, _txTemp(nullptr)
|
|
, _txTCMVersion(nullptr)
|
|
, _txSDKVersion(nullptr)
|
|
, _txSerial(nullptr)
|
|
{
|
|
initUI();
|
|
|
|
connect(this, SIGNAL(updateLabel(QLabel*, QString)), this,
|
|
SLOT(onUpdateLabel(QLabel*, QString)));
|
|
connect(this, SIGNAL(updateEdit(QLineEdit*, QString)), this,
|
|
SLOT(onUpdateEdit(QLineEdit*, QString)));
|
|
connect(this, SIGNAL(updateImageView(ImageView*)), this,
|
|
SLOT(onUpdateImageView(ImageView*)));
|
|
|
|
int sdk = GetSDKVersion();
|
|
|
|
char buff[50] = {0};
|
|
GetTCMVersion(buff);
|
|
|
|
emit updateLabel(_txSDKVersion, QString::asprintf("SDK:%d", sdk));
|
|
emit updateLabel(_txTCMVersion, QString::asprintf("TCM:%s", buff));
|
|
|
|
int x, y;
|
|
bool hasPreset = HasPreset();
|
|
if (hasPreset) {
|
|
x = GetPresetOffsetX();
|
|
y = GetPresetOffsetY();
|
|
char serial[50] = {0};
|
|
GetPresetSerial(serial);
|
|
emit updateEdit(_txSerial, QString::asprintf("%s", serial));
|
|
|
|
}
|
|
else {
|
|
x = EloUVCCameraConverter::getOffsetX();
|
|
y = EloUVCCameraConverter::getOffsetY();
|
|
}
|
|
EloUVCCameraConverter::setOffset(x, y);
|
|
updateOffset();
|
|
}
|
|
|
|
TestWidget::~TestWidget()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
|
|
void TestWidget::initUI() {
|
|
ui->setupUi(this);
|
|
|
|
this->_RGBImageView = ui->rgbImage;
|
|
this->_IRImageView = ui->irImage;
|
|
|
|
this->_txOffset = ui->txOffset;
|
|
this->_txDistance = ui->txDistance;
|
|
this->_txTemp = ui->txTemp;
|
|
this->_txTCMVersion = ui->txTCMVersion;
|
|
this->_txSDKVersion = ui->txSDKVersion;
|
|
this->_txSerial = ui->txSerial;
|
|
|
|
}
|
|
void TestWidget::onUVCFrame(const unsigned char* buffer, int width, int height, int channel)
|
|
{
|
|
BaseWidget::onUVCFrame(buffer, width, height, channel);
|
|
|
|
if (_RGBImageView) {
|
|
emit updateImageView(_RGBImageView);
|
|
}
|
|
}
|
|
|
|
void TestWidget::onIRFrame(const unsigned char* buffer, int width, int height, int channel)
|
|
{
|
|
double inner = GetInnerIRCameraTemp();
|
|
emit updateLabel(_txTemp, QString::asprintf("IR:inner %.1f", inner));
|
|
|
|
if (true) {
|
|
TemperatureResult result;
|
|
ReadTemperatureAtPoint(80,40, (unsigned char *)&result);
|
|
|
|
_IRImageView->updateSingleResult(&result);
|
|
}
|
|
else {
|
|
TemperatureResult result;
|
|
RectF rect;
|
|
rect.x = 0;
|
|
rect.y = 0;
|
|
rect.width = 0.25;
|
|
rect.height = 0.25;
|
|
|
|
ReadTemperatureInRect(rect.x*IR_WIDTH, rect.y*IR_HEIGHT,
|
|
rect.width*IR_WIDTH, rect.height*IR_HEIGHT,
|
|
(unsigned char *)&result);
|
|
|
|
emit updateLabel(_txDistance, QString::asprintf("%.1f", result.tempArm));
|
|
|
|
std::vector<RectF> rects = {rect};
|
|
std::vector<TemperatureResult> results = {result};
|
|
_IRImageView->updateFacesAndResults(rects, results);
|
|
}
|
|
|
|
|
|
BaseWidget::onIRFrame(buffer, width, height, channel);
|
|
|
|
if (_IRImageView) {
|
|
emit updateImageView(_IRImageView);
|
|
}
|
|
}
|
|
void TestWidget::onDistance(float distance) {
|
|
if (_isUnitUS) {
|
|
emit updateLabel(_txDistance, QString::asprintf("%.0f inch", distance));
|
|
}
|
|
else {
|
|
emit updateLabel(_txDistance, QString::asprintf("%.0f mm", distance));
|
|
}
|
|
}
|
|
void TestWidget::onDistanceError() {
|
|
emit updateLabel(_txDistance, QString::asprintf("onDistanceError"));
|
|
}
|
|
void TestWidget::onLimitEvent(bool inplace) {
|
|
if (inplace) {
|
|
emit updateLabel(_txSDKVersion, QString::asprintf("Limit:true"));
|
|
}
|
|
else {
|
|
emit updateLabel(_txSDKVersion, QString::asprintf("Limit:false"));
|
|
}
|
|
}
|
|
void TestWidget::onUpdateCallback(bool isSuc, int prog) {
|
|
if (isSuc) {
|
|
emit updateLabel(_txTCMVersion, QString::asprintf("Update:%d Suc", prog));
|
|
}
|
|
else {
|
|
emit updateLabel(_txTCMVersion, QString::asprintf("Update:%d Fail", prog));
|
|
}
|
|
|
|
}
|
|
void TestWidget::onUpdateLabel(QLabel* label, QString str) {
|
|
label->setText(str);
|
|
}
|
|
void TestWidget::onUpdateEdit(QLineEdit* label, QString str) {
|
|
label->setText(str);
|
|
}
|
|
void TestWidget::on_btnUp_clicked()
|
|
{
|
|
rotate(10);
|
|
}
|
|
|
|
void TestWidget::on_btnDown_clicked()
|
|
{
|
|
rotate(-10);
|
|
}
|
|
|
|
void TestWidget::on_btnTrigger_clicked()
|
|
{
|
|
trigger();
|
|
}
|
|
void TestWidget::on_btnLimit_clicked()
|
|
{
|
|
LimitReset();
|
|
}
|
|
|
|
void TestWidget::on_btnFirmUpdate_clicked() {
|
|
QFileDialog *fileDialog = new QFileDialog(this);
|
|
fileDialog->setWindowTitle(tr("Open File"));
|
|
fileDialog->setDirectory(".");
|
|
fileDialog->setNameFilter(tr("Firmware Files(*.bin)"));
|
|
if(fileDialog->exec() == QDialog::Accepted) {
|
|
QString path = fileDialog->selectedFiles()[0];
|
|
if (path.isEmpty() == false) {
|
|
QFile file (path);
|
|
bool isOk = file.open(QIODevice::ReadOnly);
|
|
if (isOk)
|
|
{
|
|
QByteArray array = file.readAll();
|
|
int length = array.size();
|
|
char* firm = array.data();
|
|
SetFirmwareData((const unsigned char*)firm, length);
|
|
file.close();
|
|
|
|
StartUpdate();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void TestWidget::on_btnSavePreset_clicked()
|
|
{
|
|
QString serial = _txSerial->text();
|
|
if (serial.length() == 0) {
|
|
QMessageBox::information(NULL, tr("Warn"), tr("Serial empty!"));
|
|
return;
|
|
}
|
|
else if (serial.length() > 12) {
|
|
QMessageBox::information(NULL, tr("Warn"), tr("Serial too long!"));
|
|
return;
|
|
}
|
|
|
|
QByteArray arr;
|
|
arr.append(serial);
|
|
const char *str = arr.data();
|
|
bool isOK = UpdatePreset(EloUVCCameraConverter::getOffsetX(),
|
|
EloUVCCameraConverter::getOffsetY(),
|
|
str);
|
|
|
|
if (isOK) {
|
|
QMessageBox::information(NULL, tr("Warn"), tr("Save success!"));
|
|
}
|
|
else {
|
|
QMessageBox::information(NULL, tr("Warn"), tr("Save failed!"));
|
|
}
|
|
}
|
|
|
|
void TestWidget::on_btnTCMReset_clicked() {
|
|
SoftResetTCM();
|
|
}
|
|
void TestWidget::on_btnXPlus_clicked()
|
|
{
|
|
EloUVCCameraConverter::adjustX(1);
|
|
updateOffset();
|
|
}
|
|
|
|
void TestWidget::on_btnXMinus_clicked()
|
|
{
|
|
EloUVCCameraConverter::adjustX(-1);
|
|
updateOffset();
|
|
}
|
|
|
|
void TestWidget::on_btnYPlus_clicked()
|
|
{
|
|
EloUVCCameraConverter::adjustY(1);
|
|
updateOffset();
|
|
}
|
|
|
|
void TestWidget::on_btnYMinus_clicked()
|
|
{
|
|
EloUVCCameraConverter::adjustY(-1);
|
|
updateOffset();
|
|
}
|
|
void TestWidget::updateOffset() {
|
|
int x = EloUVCCameraConverter::getOffsetX();
|
|
int y = EloUVCCameraConverter::getOffsetY();
|
|
|
|
EloUVCCameraConverter::setDefaultX(x);
|
|
EloUVCCameraConverter::setDefaultY(y);
|
|
|
|
emit updateLabel(_txOffset, QString::asprintf("%d-%d", x, y));
|
|
}
|
|
|
|
|