Skip to content

Commit

Permalink
bugfixes from LibreCAL repo
Browse files Browse the repository at this point in the history
  • Loading branch information
jankae committed Sep 26, 2024
1 parent 6d6ffc6 commit fc717a8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ void CalDevice::loadCoefficientSets(QStringList names, QList<int> ports, bool fa
coeffSets.clear();

if(ports.isEmpty()) {
for(int i=1;i<=ports.size();i++) {
for(unsigned int i=1;i<=getNumPorts();i++) {
ports.append(i);
}
} else {
Expand Down Expand Up @@ -331,7 +331,7 @@ void CalDevice::loadCoefficientSetsThreadFast(QStringList names, QList<int> port
coeffList = names;
}

int total_coeffs = (ports.size() * 3 + ports.size() * (ports.size() - 1) / 2) * names.size();
int total_coeffs = (ports.size() * 3 + ports.size() * (ports.size() - 1) / 2) * coeffList.size();
int read_coeffs = 0;

for(auto name : coeffList) {
Expand Down Expand Up @@ -538,6 +538,15 @@ void CalDevice::saveCoefficientSetsThread()
}
}
}
// prune empty coefficient sets
auto i = coeffSets.begin();
while(i != coeffSets.end()) {
if(i->isEmpty()) {
i = coeffSets.erase(i);
} else {
i++;
}
}
emit updateCoefficientsDone(success);
}

Expand All @@ -551,10 +560,7 @@ void CalDevice::addCoefficientSet(QString name)
CoefficientSet set;
set.name = name;
set.ports = numPorts;
set.loads.clear();
set.shorts.clear();
set.opens.clear();
set.throughs.clear();
set.createEmptyCoefficients();
coeffSets.push_back(set);
}

Expand Down Expand Up @@ -650,3 +656,45 @@ void CalDevice::CoefficientSet::portsFromThroughIndex(int &port1, int &port2, in
port2 = -1;
}
}

void CalDevice::CoefficientSet::createEmptyCoefficients()
{
loads.clear();
shorts.clear();
opens.clear();
throughs.clear();
for(int i=1;i<=ports;i++) {
opens[i] = new Coefficient();
shorts[i] = new Coefficient();
loads[i] = new Coefficient();
for(int j=i+1;j<=ports;j++) {
throughs[portsToThroughIndex(i,j)] = new Coefficient();
}
}
}

bool CalDevice::CoefficientSet::isEmpty()
{
for(auto o : opens) {
if(o.second->t.points() > 0) {
return false;
}
}
for(auto s : shorts) {
if(s.second->t.points() > 0) {
return false;
}
}
for(auto l : loads) {
if(l.second->t.points() > 0) {
return false;
}
}
for(auto t : throughs) {
if(t.second->t.points() > 0) {
return false;
}
}
// no coefficients or all coefficients empty
return true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class CalDevice : public QObject

int portsToThroughIndex(int port1, int port2);
void portsFromThroughIndex(int &port1, int &port2, int index);

void createEmptyCoefficients();
bool isEmpty();
};

// Extracts the coefficients from the device. This is done with a dedicated thread.
Expand Down

0 comments on commit fc717a8

Please sign in to comment.