Compare commits

...

2 commits

Author SHA1 Message Date
Jan Käberich 64791e6d4e option to restore default values of device configuration
Some checks failed
Build / PC_Application_Ubuntu (push) Has been cancelled
Build / PC_Application_RPi5 (push) Has been cancelled
Build / PC_Application_Windows (push) Has been cancelled
Build / PC_Application_OSX (push) Has been cancelled
Build / PC_Application_OSX_13 (push) Has been cancelled
Build / Embedded_Firmware (push) Has been cancelled
HIL_Tests / Get_Repository (push) Has been cancelled
Unit_Tests / Tests (push) Has been cancelled
HIL_Tests / PC_Application_RPi5 (push) Has been cancelled
HIL_Tests / Embedded_Firmware (push) Has been cancelled
HIL_Tests / HIL (push) Has been cancelled
2025-11-15 19:22:15 +01:00
Jan Käberich b6718c57b2 Improve marker handling when at the edge of a graph 2025-11-15 19:03:41 +01:00
10 changed files with 71 additions and 28 deletions

View file

@ -1,6 +1,9 @@
#include "deviceconfigurationdialogv1.h"
#include "ui_deviceconfigurationdialogv1.h"
#include <QPushButton>
#include "CustomWidgets/informationbox.h"
DeviceConfigurationDialogV1::DeviceConfigurationDialogV1(LibreVNADriver &dev, QWidget *parent) :
QDialog(parent),
ui(new Ui::DeviceConfigurationDialogV1),
@ -56,6 +59,10 @@ DeviceConfigurationDialogV1::DeviceConfigurationDialogV1(LibreVNADriver &dev, QW
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=](){
reject();
});
connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::clicked, this, [=](){
resetDevice();
this->dev.sendWithoutPayload(Protocol::PacketType::RequestDeviceConfiguration);
});
}
DeviceConfigurationDialogV1::~DeviceConfigurationDialogV1()
@ -84,3 +91,12 @@ void DeviceConfigurationDialogV1::updateDevice()
p.deviceConfig.V1.PLLSettlingDelay = ui->PLLSettlingDelay->value();
dev.SendPacket(p);
}
void DeviceConfigurationDialogV1::resetDevice()
{
dev.sendWithoutPayload(Protocol::PacketType::ResetDeviceConfiguration, [=](LibreVNADriver::TransmissionResult res){
if(res != LibreVNADriver::TransmissionResult::Ack) {
InformationBox::ShowError("Error", "Failed to reset device configuration");
}
});
}

View file

@ -20,6 +20,7 @@ public:
private:
void updateGUI(const Protocol::DeviceConfig &c);
void updateDevice();
void resetDevice();
Ui::DeviceConfigurationDialogV1 *ui;
LibreVNADriver &dev;

View file

@ -164,7 +164,7 @@
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok</set>
<set>QDialogButtonBox::StandardButton::Cancel|QDialogButtonBox::StandardButton::Ok|QDialogButtonBox::StandardButton::RestoreDefaults</set>
</property>
</widget>
</item>

View file

@ -562,6 +562,10 @@ Marker *TracePlot::markerAtPosition(QPoint p, bool onlyMovable)
// invalid, skip
continue;
}
if(!positionWithinGraphArea(markerPoint) && !Preferences::getInstance().Marker.clipToYAxis) {
// this marker is currently not visible on the graph, do not accept it as a valid choice
continue;
}
auto diff = markerPoint - p;
unsigned int distance = diff.x() * diff.x() + diff.y() * diff.y();
if(distance < closestDistance) {

View file

@ -130,7 +130,7 @@ bool TracePolar::positionWithinGraphArea(const QPoint &p)
QPoint TracePolar::dataToPixel(std::complex<double> d)
{
return transform.map(QPoint(d.real() * polarCoordMax * (1.0 / edgeReflection), -d.imag() * polarCoordMax * (1.0 / edgeReflection)));
return transform.map(QPoint(round(d.real() * polarCoordMax * (1.0 / edgeReflection)), round(-d.imag() * polarCoordMax * (1.0 / edgeReflection))));
}
QPoint TracePolar:: dataToPixel(Trace::Data d)
@ -165,13 +165,22 @@ std::complex<double> TracePolar::pixelToData(QPoint p)
QPoint TracePolar::markerToPixel(Marker *m)
{
QPoint ret = QPoint();
// if(!m->isTimeDomain()) {
if(m->getPosition() >= sweep_fmin && m->getPosition() <= sweep_fmax) {
auto d = m->getData();
d = dataAddOffset(d);
ret = dataToPixel(d);
if(m->getPosition() >= sweep_fmin && m->getPosition() <= sweep_fmax) {
auto d = m->getData();
d = dataAddOffset(d);
if(abs(d) > edgeReflection && limitToEdge) {
// marker position is outside of the graph
auto &pref = Preferences::getInstance();
if(pref.Marker.clipToYAxis) {
// we still want to show the marker but at the edge of the graph
d /= (abs(d) / edgeReflection);
} else {
// we do not show the marker
return ret;
}
}
// }
ret = dataToPixel(d);
}
return ret;
}
@ -188,6 +197,10 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
continue;
}
data = dataAddOffset(data);
if(limitToEdge && abs(data.y) > edgeReflection) {
// this trace point is outside of the visible range, clip to circle
data.y /= (abs(data.y) / edgeReflection);
}
auto plotPoint = dataToPixel(data);
if (plotPoint.isNull()) {
// destination point outside of currently displayed range

View file

@ -367,14 +367,16 @@ void TraceSmithChart::draw(QPainter &p) {
// marker not in trace range
continue;
}
auto coords = m->getData();
coords = dataAddOffset(coords);
if (limitToEdge && abs(coords) > edgeReflection) {
// outside of visible area
auto point = markerToPixel(m);
if(point.isNull()) {
// marker point is invalid
continue;
}
auto point = dataToPixel(coords);
// if (limitToEdge && abs(pixelToData(point)) > edgeReflection) {
// // outside of visible area
// continue;
// }
auto symbol = m->getSymbol();
p.drawPixmap(point.x() - symbol.width()/2, point.y() - symbol.height(), symbol);
}

View file

@ -452,8 +452,8 @@ void TraceXYPlot::draw(QPainter &p)
plotAreaWidth -= yAxisDisabledSpace;
}
auto plotRect = QRect(plotAreaLeft, plotAreaTop, plotAreaWidth + 1, plotAreaBottom-plotAreaTop);
p.drawRect(plotRect);
auto plotRect = QRect(plotAreaLeft, plotAreaTop, plotAreaWidth + 1, plotAreaBottom-plotAreaTop + 1);
p.drawRect(QRect(plotAreaLeft, plotAreaTop, plotAreaWidth, plotAreaBottom-plotAreaTop));
// draw axis types
auto font = p.font();
@ -490,7 +490,7 @@ void TraceXYPlot::draw(QPainter &p)
int lastTickLabelEnd = std::numeric_limits<int>::max();
for(unsigned int j = 0; j < yAxis[i].getTicks().size(); j++) {
auto yCoord = yAxis[i].transform(yAxis[i].getTicks()[j], w.height() - xAxisSpace, plotAreaTop);
auto yCoord = yAxis[i].transform(yAxis[i].getTicks()[j], plotAreaBottom, plotAreaTop);
p.setPen(QPen(pref.Graphs.Color.axis, 1));
// draw tickmark on axis
auto tickStart = i == 0 ? plotAreaLeft : plotAreaLeft + plotAreaWidth;
@ -630,15 +630,6 @@ void TraceXYPlot::draw(QPainter &p)
p.drawLine(p1, p2);
}
if(pref.Marker.clipToYAxis) {
// clip Y coordinate of markers to visible area (always show markers, even when out of range)
if(point.y() < plotRect.top()) {
point.ry() = plotRect.top();
} else if(point.y() > plotRect.bottom()) {
point.ry() = plotRect.bottom();
}
}
if(!plotRect.contains(point)) {
// out of screen
continue;
@ -1116,8 +1107,8 @@ QPointF TraceXYPlot::traceToCoordinate(Trace *t, unsigned int sample, YAxis &yax
QPoint TraceXYPlot::plotValueToPixel(QPointF plotValue, int Yaxis)
{
QPoint p;
p.setX(xAxis.transform(plotValue.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth));
p.setY(yAxis[Yaxis].transform(plotValue.y(), plotAreaBottom, plotAreaTop));
p.setX(round(xAxis.transform(plotValue.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth)));
p.setY(round(yAxis[Yaxis].transform(plotValue.y(), plotAreaBottom, plotAreaTop)));
return p;
}
@ -1156,6 +1147,14 @@ QPoint TraceXYPlot::markerToPixel(Marker *m)
} else {
markerPoint = traceToCoordinate(t, t->index(xPosition), yAxis[0]);
}
auto &pref = Preferences::getInstance();
if(pref.Marker.clipToYAxis) {
if(markerPoint.y() > yAxis[0].getRangeMax()) {
markerPoint.setY(yAxis[0].getRangeMax());
} else if(markerPoint.y() < yAxis[0].getRangeMin()) {
markerPoint.setY(yAxis[0].getRangeMin());
}
}
return plotValueToPixel(markerPoint, 0);
}
@ -1175,6 +1174,8 @@ double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel, double *distance)
continue;
}
auto plotPoint = plotValueToPixel(point, 0);
// constrain to the visible Y axis range
Util::constrain(plotPoint.ry(), plotAreaTop, plotAreaBottom);
QPointF diff = plotPoint - pixel;
auto distance = diff.x() * diff.x() + diff.y() * diff.y();
if(distance < closestDistance) {

View file

@ -276,6 +276,10 @@ inline void App_Process() {
HW::setDeviceConfig(recv_packet.deviceConfig);
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break;
case Protocol::PacketType::ResetDeviceConfiguration:
HW::SetDefaultDeviceConfig();
Communication::SendWithoutPayload(Protocol::PacketType::Ack);
break;
case Protocol::PacketType::SetTrigger:
if(Trigger::GetMode() == Trigger::Mode::USB_GUI) {
Trigger::SetInput(true);

View file

@ -127,6 +127,7 @@ uint16_t Protocol::EncodePacket(const PacketInfo &packet, uint8_t *dest, uint16_
case PacketType::StopStatusUpdates:
case PacketType::StartStatusUpdates:
case PacketType::InitiateSweep:
case PacketType::ResetDeviceConfiguration:
// no payload
break;
case PacketType::VNADatapoint: payload_size = packet.VNAdatapoint->requiredBufferSize(); break;

View file

@ -605,6 +605,7 @@ enum class PacketType : uint8_t {
StartStatusUpdates = 31,
InitiateSweep = 32,
PerformAction = 33,
ResetDeviceConfiguration = 34,
};
using PacketInfo = struct _packetinfo {