| 22 | using namespace SigDigger; |
| 23 | |
| 24 | DeviceGain::DeviceGain( |
| 25 | QWidget *parent, |
| 26 | Suscan::Source::GainDescription const &desc) : |
| 27 | QWidget(parent), |
| 28 | ui(new Ui_DeviceGain) |
| 29 | { |
| 30 | this->ui->setupUi(this); |
| 31 | |
| 32 | this->name = desc.getName(); |
| 33 | this->min = static_cast<float>(desc.getMin()); |
| 34 | this->max = static_cast<float>(desc.getMax()); |
| 35 | this->step = static_cast<float>(desc.getStep()); |
| 36 | |
| 37 | if (this->step < 1) |
| 38 | this->step = 1; |
| 39 | |
| 40 | this->defl = static_cast<float>(desc.getDefault()); |
| 41 | |
| 42 | // The slider must be configured as follows |
| 43 | // Min value: 0 |
| 44 | // Max value: (this->max - this->min) / this->step |
| 45 | // Tick interval: 1 |
| 46 | // Single step: 1 |
| 47 | |
| 48 | // Gain to value: |
| 49 | // value = (gain - this->min) / this->step |
| 50 | |
| 51 | // Value to gain |
| 52 | // gain = this->min + this->step * value |
| 53 | |
| 54 | this->ui->gainSlider->setMinimum(0); |
| 55 | this->ui->gainSlider->setMaximum(static_cast<int>((this->max - this->min) / this->step)); |
| 56 | this->ui->gainSlider->setTickInterval(1); |
| 57 | this->ui->gainSlider->setSingleStep(1); |
| 58 | |
| 59 | this->ui->nameLabel->setText(QString::fromStdString(this->name)); |
| 60 | |
| 61 | connect( |
| 62 | this->ui->gainSlider, |
| 63 | SIGNAL(valueChanged(int)), |
| 64 | this, |
| 65 | SLOT(onValueChanged(int))); |
| 66 | |
| 67 | connect( |
| 68 | this->ui->resetButton, |
| 69 | SIGNAL(clicked(bool)), |
| 70 | this, |
| 71 | SLOT(onResetClicked(void))); |
| 72 | |
| 73 | this->setGain(this->defl); |
| 74 | } |
| 75 | |
| 76 | float |
| 77 | DeviceGain::getGain(void) const |