Bugfixes LibreCAL automatic calibration dialog
This commit is contained in:
parent
10e31356df
commit
8c1d2d1f06
@ -3,20 +3,59 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QDateTime>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
static QString getLocalDateTimeWithUtcOffset()
|
||||||
|
{
|
||||||
|
QDateTime currentDateTime = QDateTime::currentDateTime();
|
||||||
|
int year = currentDateTime.date().year();
|
||||||
|
int month = currentDateTime.date().month();
|
||||||
|
int day = currentDateTime.date().day();
|
||||||
|
int hour = currentDateTime.time().hour();
|
||||||
|
int minute = currentDateTime.time().minute();
|
||||||
|
int second = currentDateTime.time().second();
|
||||||
|
int utcOffset = currentDateTime.offsetFromUtc() / 3600;
|
||||||
|
int utcOffsetMinute = (currentDateTime.offsetFromUtc() % 3600) / 60;
|
||||||
|
QString dateTimeString = QString("%1/%2/%3 %4:%5:%6 UTC%7%8:%9")
|
||||||
|
.arg(year, 4, 10, QChar('0'))
|
||||||
|
.arg(month, 2, 10, QChar('0'))
|
||||||
|
.arg(day, 2, 10, QChar('0'))
|
||||||
|
.arg(hour, 2, 10, QChar('0'))
|
||||||
|
.arg(minute, 2, 10, QChar('0'))
|
||||||
|
.arg(second, 2, 10, QChar('0'))
|
||||||
|
.arg(utcOffset > 0 ? "+" : "-") // Add a plus sign for positive offsets
|
||||||
|
.arg(qAbs(utcOffset), 2, 10, QChar('0'))
|
||||||
|
.arg(utcOffsetMinute, 2, 10, QChar('0'));
|
||||||
|
return dateTimeString;
|
||||||
|
}
|
||||||
|
|
||||||
CalDevice::CalDevice(QString serial) :
|
CalDevice::CalDevice(QString serial) :
|
||||||
usb(new USBDevice(serial))
|
usb(new USBDevice(serial))
|
||||||
{
|
{
|
||||||
// Check device identification
|
// Check device identification
|
||||||
auto id = usb->Query("*IDN?");
|
auto id = usb->Query("*IDN?");
|
||||||
if(!id.startsWith("LibreCAL_")) {
|
if(!id.startsWith("LibreCAL,")) {
|
||||||
delete usb;
|
delete usb;
|
||||||
throw std::runtime_error("Invalid response to *IDN?: "+id.toStdString());
|
throw std::runtime_error("Invalid response to *IDN?: "+id.toStdString());
|
||||||
}
|
}
|
||||||
|
|
||||||
firmware = usb->Query(":FIRMWARE?");
|
firmware = usb->Query(":FIRMWARE?");
|
||||||
|
QList<QString> fw_version = firmware.split(".");
|
||||||
|
if (fw_version.size() == 3) {
|
||||||
|
int firmware_major = fw_version[0].toInt();
|
||||||
|
int firmware_minor = fw_version[1].toInt();
|
||||||
|
this->firmware_major_minor = firmware_major + ((float)firmware_minor/10.0f);
|
||||||
|
if(this->firmware_major_minor >= 0.2)
|
||||||
|
{
|
||||||
|
/* Set Date Time UTC */
|
||||||
|
QString LocalDateTimeWithUtcOffset = getLocalDateTimeWithUtcOffset();
|
||||||
|
QString ret = usb->Query(":DATE_TIME "+LocalDateTimeWithUtcOffset);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// fw_version invalid
|
||||||
|
this->firmware_major_minor = 0.0;
|
||||||
|
}
|
||||||
QString ports = usb->Query(":PORTS?");
|
QString ports = usb->Query(":PORTS?");
|
||||||
bool okay;
|
bool okay;
|
||||||
numPorts = ports.toInt(&okay);
|
numPorts = ports.toInt(&okay);
|
||||||
@ -119,6 +158,17 @@ bool CalDevice::enterBootloader()
|
|||||||
return usb->Cmd(":BOOTloader");
|
return usb->Cmd(":BOOTloader");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString CalDevice::getDateTimeUTC()
|
||||||
|
{
|
||||||
|
if(this->firmware_major_minor >= 0.2)
|
||||||
|
{
|
||||||
|
return usb->Query(":DATE_TIME?");
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
return ""; // Not available
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CalDevice::loadCoefficientSets(QStringList names)
|
void CalDevice::loadCoefficientSets(QStringList names)
|
||||||
{
|
{
|
||||||
coeffSets.clear();
|
coeffSets.clear();
|
||||||
|
@ -44,6 +44,8 @@ public:
|
|||||||
QString getFirmware() const;
|
QString getFirmware() const;
|
||||||
unsigned int getNumPorts() const;
|
unsigned int getNumPorts() const;
|
||||||
|
|
||||||
|
QString getDateTimeUTC();
|
||||||
|
|
||||||
bool enterBootloader();
|
bool enterBootloader();
|
||||||
|
|
||||||
class CoefficientSet {
|
class CoefficientSet {
|
||||||
@ -97,6 +99,8 @@ private:
|
|||||||
QString firmware;
|
QString firmware;
|
||||||
int numPorts;
|
int numPorts;
|
||||||
|
|
||||||
|
float firmware_major_minor;
|
||||||
|
|
||||||
std::vector<CoefficientSet> coeffSets;
|
std::vector<CoefficientSet> coeffSets;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,11 +33,12 @@ LibreCALDialog::LibreCALDialog(Calibration *cal) :
|
|||||||
device = new CalDevice(text);
|
device = new CalDevice(text);
|
||||||
} catch (exception &e) {
|
} catch (exception &e) {
|
||||||
device = nullptr;
|
device = nullptr;
|
||||||
|
InformationBox::ShowError("Failed to connect", e.what(), this);
|
||||||
}
|
}
|
||||||
if(device) {
|
if(device) {
|
||||||
createPortAssignmentUI();
|
createPortAssignmentUI();
|
||||||
connect(device, &CalDevice::updateCoefficientsPercent, ui->progressCoeff, &QProgressBar::setValue);
|
connect(device, &CalDevice::updateCoefficientsPercent, ui->progressCoeff, &QProgressBar::setValue);
|
||||||
connect(device, &CalDevice::updateCoefficientsDone, [=](bool success){
|
connect(device, &CalDevice::updateCoefficientsDone, this, [=](bool success){
|
||||||
busy = false;
|
busy = false;
|
||||||
if(success) {
|
if(success) {
|
||||||
ui->progressCoeff->setValue(100);
|
ui->progressCoeff->setValue(100);
|
||||||
@ -48,7 +49,7 @@ LibreCALDialog::LibreCALDialog(Calibration *cal) :
|
|||||||
ui->lCoefficientStatus->setText("Failed to load coefficients");
|
ui->lCoefficientStatus->setText("Failed to load coefficients");
|
||||||
}
|
}
|
||||||
updateCalibrationStartStatus();
|
updateCalibrationStartStatus();
|
||||||
});
|
}, Qt::QueuedConnection);
|
||||||
|
|
||||||
ui->cbCoefficients->clear();
|
ui->cbCoefficients->clear();
|
||||||
ui->cbCoefficients->addItem("Select...");
|
ui->cbCoefficients->addItem("Select...");
|
||||||
@ -389,7 +390,7 @@ void LibreCALDialog::startCalibration()
|
|||||||
}
|
}
|
||||||
setTerminationOnAllUsedPorts(CalDevice::Standard(CalDevice::Standard::Type::None));
|
setTerminationOnAllUsedPorts(CalDevice::Standard(CalDevice::Standard::Type::None));
|
||||||
auto m = throughMeasurements[throughIndex];
|
auto m = throughMeasurements[throughIndex];
|
||||||
device->setStandard(m->getPort1(), CalDevice::Standard(m->getPort2()));
|
device->setStandard(portAssignment[m->getPort1()-1], CalDevice::Standard(portAssignment[m->getPort2()-1]));
|
||||||
emit cal->startMeasurements({m});
|
emit cal->startMeasurements({m});
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user