diff --git a/slsDetectorGui/forms/form_tab_settings.ui b/slsDetectorGui/forms/form_tab_settings.ui index 7f44f601a..2f20a5edb 100755 --- a/slsDetectorGui/forms/form_tab_settings.ui +++ b/slsDetectorGui/forms/form_tab_settings.ui @@ -32,8 +32,85 @@ Form - - + + + + false + + + + 50 + 16777215 + + + + 2 + + + true + + + + + + + false + + + + 50 + 16777215 + + + + 3 + + + true + + + + + + + false + + + + 140 + 25 + + + + + 140 + 16777215 + + + + + 1.67772e+07 + + + + + 65535 + + + + + 255 + + + + + 7 + + + + + + false @@ -69,8 +146,8 @@ - - + + false @@ -128,7 +205,7 @@ - + Qt::Vertical @@ -144,46 +221,7 @@ - - - - false - - - - 140 - 25 - - - - - 140 - 16777215 - - - - - 1.67772e+07 - - - - - 65535 - - - - - 255 - - - - - 7 - - - - - + true @@ -280,7 +318,139 @@ - + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 20 + 20 + + + + + + + + false + + + + 110 + 0 + + + + + 110 + 16777215 + + + + Threshold: + + + + + + + false + + + + 140 + 25 + + + + + 140 + 16777215 + + + + false + + + eV + + + -100000 + + + 100000 + + + 100 + + + -1 + + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 20 + 20 + + + + + + + + false + + + + 110 + 0 + + + + + 110 + 16777215 + + + + Counters: + + + + + + + false + + + + 50 + 16777215 + + + + 1 + + + true + + + + true @@ -424,97 +594,6 @@ - - - - Qt::Horizontal - - - QSizePolicy::Fixed - - - - 20 - 20 - - - - - - - - false - - - - 110 - 0 - - - - - 110 - 16777215 - - - - Threshold: - - - - - - - false - - - - 140 - 25 - - - - - 140 - 16777215 - - - - false - - - eV - - - -100000 - - - 100000 - - - 100 - - - -1 - - - - - - - Qt::Horizontal - - - QSizePolicy::Expanding - - - - 20 - 20 - - - - @@ -523,7 +602,6 @@ spinThreshold2 spinThreshold3 btnSetThreshold - comboDynamicRange diff --git a/slsDetectorGui/include/qTabSettings.h b/slsDetectorGui/include/qTabSettings.h index 2effd00bb..52915747e 100644 --- a/slsDetectorGui/include/qTabSettings.h +++ b/slsDetectorGui/include/qTabSettings.h @@ -1,6 +1,7 @@ #pragma once #include "sls/Detector.h" #include "ui_form_tab_settings.h" +#include class qTabSettings : public QWidget, private Ui::TabSettingsObject { Q_OBJECT @@ -15,6 +16,7 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void SetDynamicRange(int index); void SetThresholdEnergy(int index); void SetThresholdEnergies(); + void SetCounterMask(); private: void SetupWidgetWindow(); @@ -25,8 +27,11 @@ class qTabSettings : public QWidget, private Ui::TabSettingsObject { void GetDynamicRange(); void GetThresholdEnergy(); void GetThresholdEnergies(); + void GetCounterMask(); sls::Detector *det; + std::vector counters; + enum { STANDARD, FAST, diff --git a/slsDetectorGui/src/qTabSettings.cpp b/slsDetectorGui/src/qTabSettings.cpp index 504f80b71..81c7ad0e4 100644 --- a/slsDetectorGui/src/qTabSettings.cpp +++ b/slsDetectorGui/src/qTabSettings.cpp @@ -1,6 +1,7 @@ #include "qTabSettings.h" #include "qDefs.h" #include "sls/ToString.h" +#include "sls/bit_utils.h" #include qTabSettings::qTabSettings(QWidget *parent, sls::Detector *detector) @@ -14,10 +15,21 @@ qTabSettings::~qTabSettings() {} void qTabSettings::SetupWidgetWindow() { + counters = std::vector{chkCounter1, chkCounter2, chkCounter3}; + spinThreshold2->hide(); spinThreshold3->hide(); btnSetThreshold->hide(); btnSetThreshold->setEnabled(false); + lblCounter->hide(); + lblCounter->setEnabled(false); + chkCounter1->setEnabled(false); + chkCounter2->setEnabled(false); + chkCounter3->setEnabled(false); + chkCounter1->hide(); + chkCounter2->hide(); + chkCounter3->hide(); + // enabling according to det type slsDetectorDefs::detectorType detType = det->getDetectorType().squash(); if (detType == slsDetectorDefs::MYTHEN3) { @@ -32,6 +44,16 @@ void qTabSettings::SetupWidgetWindow() { spinThreshold3->setEnabled(true); btnSetThreshold->setEnabled(true); btnSetThreshold->show(); + + lblCounter->show(); + lblCounter->setEnabled(true); + chkCounter1->setEnabled(true); + chkCounter2->setEnabled(true); + chkCounter3->setEnabled(true); + chkCounter1->show(); + chkCounter2->show(); + chkCounter3->show(); + // disable dr QStandardItemModel *model = qobject_cast(comboDynamicRange->model()); @@ -153,6 +175,16 @@ void qTabSettings::Initialization() { else if (spinThreshold->isEnabled()) connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int))); + + // counters + if (lblCounter->isEnabled()) { + connect(chkCounter1, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + connect(chkCounter2, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + connect(chkCounter3, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + } } void qTabSettings::GetSettings() { @@ -269,7 +301,7 @@ void qTabSettings::GetThresholdEnergies() { spinThreshold3->setValue(retval[2]); } CATCH_DISPLAY("Could not get threshold energy.", - "qTabDataOutput::GetThresholdEnergies") + "qTabSettings::GetThresholdEnergies") connect(btnSetThreshold, SIGNAL(clicked()), this, SLOT(SetThresholdEnergies())); } @@ -284,7 +316,7 @@ void qTabSettings::GetThresholdEnergy() { spinThreshold->setValue(retval); } CATCH_DISPLAY("Could not get threshold energy.", - "qTabDataOutput::GetThresholdEnergy") + "qTabSettings::GetThresholdEnergy") connect(spinThreshold, SIGNAL(valueChanged(int)), this, SLOT(SetThresholdEnergy(int))); } @@ -317,6 +349,51 @@ void qTabSettings::SetThresholdEnergy(int index) { GetThresholdEnergy(); } +void qTabSettings::GetCounterMask() { + LOG(logDEBUG) << "Getting counter mask"; + disconnect(chkCounter1, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + disconnect(chkCounter2, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + disconnect(chkCounter3, SIGNAL(toggled(bool)), this, + SLOT(SetCounterMask())); + try { + auto retval = sls::getSetBits(det->getCounterMask().tsquash( + "Counter mask is inconsistent for all detectors.")); + // default to unchecked + std::for_each(counters, [](auto &i) { i.setChecked(false); }); + // std::for_each(counters.begin(), counters.end(), ) + // if retval[i] = 2, chkCounter2 is checked + for (auto i : retval) { + if (i > 3) { + throw sls::RuntimeError( + std::string("Unknown counter index : ") + + std::to_string(static_cast(i))); + } + counters[i]->setChecked(true); + } + } + CATCH_DISPLAY("Could not get counter mask.", "qTabSettings::GetCounterMask") + connect(chkCounter1, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); + connect(chkCounter2, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); + connect(chkCounter3, SIGNAL(toggled(bool)), this, SLOT(SetCounterMask())); +} + +void qTabSettings::SetCounterMask() { + uint32_t mask = 0; + for (unsigned int i = 0; i < counters.size(); ++i) { + if (counters[i]->isChecked()) { + mask |= (1 << i); + } + } + LOG(logINFO) << "Setting counter mask to " << mask; + try { + det->setCounterMask(mask); + } + CATCH_HANDLE("Could not set counter mask.", "qTabSettings::SetCounterMask", + this, &qTabSettings::GetCounterMask) +} + void qTabSettings::Refresh() { LOG(logDEBUG) << "**Updating Settings Tab"; @@ -337,5 +414,9 @@ void qTabSettings::Refresh() { GetThresholdEnergy(); } + if (lblCounter->isEnabled()) { + GetCounterMask(); + } + LOG(logDEBUG) << "**Updated Settings Tab"; }