• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

gui/nxyterwidget.cpp (r4864/r1198)

Go to the documentation of this file.
00001 #include "nxyterwidget.h"
00002 
00003 #include <QGridLayout>
00004 #include <QHBoxLayout>
00005 #include <QLabel>
00006 #include <QSignalMapper>
00007 #include <QPushButton>
00008 
00009 const int OtherRegsId[] = { 38, 39, 43, 44, 45 };
00010 
00011 NxyterWidget::NxyterWidget(QWidget* parent, nxyter::NxChip* chip) :
00012    SubWidget(parent),
00013    fChip(chip)
00014 {
00015    setupUi(this);
00016 
00017    fIgnore = false;
00018 
00019    //     =============== Bias registers =====================
00020 
00021    QGridLayout* grid = new QGridLayout(BiasGroup);
00022    grid->setMargin(3);
00023    grid->setSpacing(3);
00024 
00025    QSignalMapper* map = new QSignalMapper(this);
00026 
00027    for (int n=0;n<NumBias;n++) {
00028       // first column - label
00029       grid->addWidget(new QLabel(QString("#%1: %2").arg(BiasShift+n).arg(nxyter::NxI2c::registerName(BiasShift+n)), this), n, 0);
00030 
00031       fBiasSlider[n] = new QSlider(Qt::Horizontal, this);
00032       fBiasSlider[n]->setMinimum(0);
00033       fBiasSlider[n]->setMaximum(255);
00034       fBiasSlider[n]->setPageStep(16);
00035       //QObject::connect(fBiasSlider[n], SIGNAL(sliderReleased()), map, SLOT(map()));
00036       QObject::connect(fBiasSlider[n], SIGNAL(valueChanged(int)), map, SLOT(map()));
00037       map->setMapping(fBiasSlider[n], n);
00038 
00039       grid->addWidget(fBiasSlider[n], n, 1);
00040 
00041       fBiasSpins[n] = new QSpinBox(this);
00042       fBiasSpins[n]->setMinimum(0);
00043       fBiasSpins[n]->setMaximum(255);
00044       fBiasSpins[n]->setMinimumWidth(70);
00045       QObject::connect(fBiasSpins[n], SIGNAL(valueChanged(int)), map, SLOT(map()));
00046       map->setMapping(fBiasSpins[n], 100+n);
00047 
00048       grid->addWidget(fBiasSpins[n], n, 2);
00049    }
00050 
00051    QObject::connect(map, SIGNAL(mapped(int)), this, SLOT(biasRegChanged(int)));
00052 
00053    //  ================ channel masks ======================
00054 
00055    map = new QSignalMapper(this);
00056 
00057    grid = new QGridLayout(MaskGroup);
00058    grid->setMargin(3);
00059    grid->setSpacing(3);
00060 
00061    QPushButton* btn = new QPushButton("all", this);
00062    btn->setMaximumHeight(20);
00063    grid->addWidget(btn, 0, 0);
00064    QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00065    map->setMapping(btn, 999);
00066 
00067    for (int y=0;y<8;y++) {
00068       btn = new QPushButton("o", this);
00069       btn->setMaximumHeight(20);
00070       btn->setMaximumWidth(20);
00071       grid->addWidget(btn, 0, y+2);
00072 
00073       QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00074       map->setMapping(btn, 700+y);
00075    }
00076 
00077    for (int x=0;x<16;x++) {
00078       btn = new QPushButton(QString("Chls %1-%2").arg(x*8, 2, 16, QLatin1Char('0')).arg(x*8+7, 2, 16, QLatin1Char('0')), this);
00079       btn->setMaximumHeight(20);
00080       grid->addWidget(btn, x+1, 0);
00081 
00082       QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00083       map->setMapping(btn, 500+x);
00084 
00085       for (int y=0;y<8;y++) {
00086          int nch = x*8 + y;
00087          fMaskChks[nch] = new QCheckBox(this);
00088          grid->addWidget(fMaskChks[nch], x+1, y+2);
00089 
00090          QObject::connect(fMaskChks[nch], SIGNAL(clicked(bool)), map, SLOT(map()));
00091          map->setMapping(fMaskChks[nch], nch);
00092       }
00093    }
00094 
00095    QObject::connect(map, SIGNAL(mapped(int)), this, SLOT(maskRowColumn(int)));
00096 
00097    MaskGroup->adjustSize();
00098 
00099    // ================ channel thresholds =================
00100 
00101    grid = new QGridLayout(ThresholdsGroup);
00102    grid->setMargin(3);
00103    grid->setSpacing(3);
00104    map = new QSignalMapper(this);
00105 
00106    btn = new QPushButton("all", this);
00107    btn->setMaximumHeight(20);
00108    grid->addWidget(btn, 0, 0);
00109    QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00110    map->setMapping(btn, 999);
00111 
00112    btn = new QPushButton("+", this);
00113    btn->setMaximumHeight(16);
00114    btn->setMaximumWidth(16);
00115    grid->addWidget(btn, 0, 1);
00116    QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00117    map->setMapping(btn, 888);
00118 
00119 
00120    for (int y=0;y<8;y++) {
00121       QHBoxLayout* hbox = new QHBoxLayout();
00122       hbox->setMargin(0);
00123       hbox->setSpacing(1);
00124 
00125       btn = new QPushButton("v", this);
00126       btn->setMaximumHeight(16);
00127       btn->setMaximumWidth(16);
00128       hbox->addWidget(btn);
00129 
00130       QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00131       map->setMapping(btn, 700+y);
00132 
00133       btn = new QPushButton("+", this);
00134       btn->setMaximumHeight(16);
00135       btn->setMaximumWidth(16);
00136       hbox->addWidget(btn);
00137 
00138       QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00139       map->setMapping(btn, 800+y);
00140 
00141       grid->addLayout(hbox, 0, y+2);
00142    }
00143 
00144    for (int x=0;x<17;x++) {
00145       QString lbl = QString("Chls %1-%2").arg(x*8, 2, 16, QLatin1Char('0')).arg(x*8+7, 2, 16, QLatin1Char('0'));
00146       if (x==16) lbl = "Test chl";
00147 
00148       btn = new QPushButton(lbl, this);
00149       btn->setMaximumHeight(20);
00150       grid->addWidget(btn, x+1, 0);
00151 
00152       QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00153       map->setMapping(btn, 500+x);
00154 
00155       btn = new QPushButton("+", this);
00156       btn->setMaximumHeight(16);
00157       btn->setMaximumWidth(16);
00158       grid->addWidget(btn, x+1, 1);
00159 
00160       QObject::connect(btn, SIGNAL(clicked()), map, SLOT(map()));
00161       map->setMapping(btn, 600+x);
00162 
00163       for (int y=0;y<8;y++) {
00164          int nch = x*8 + y;
00165 
00166          fThrdSpins[nch] = new QSpinBox(this);
00167          fThrdSpins[nch]->setMinimum(-1);
00168          fThrdSpins[nch]->setMaximum(32);
00169 
00170          grid->addWidget(fThrdSpins[nch], x+1, y+2);
00171 
00172          QObject::connect(fThrdSpins[nch], SIGNAL(valueChanged(int)), map, SLOT(map()));
00173          map->setMapping(fThrdSpins[nch], nch);
00174 
00175          if (x==16) break;
00176       }
00177    }
00178 
00179    ThresholdsGroup->adjustSize();
00180 
00181    QObject::connect(map, SIGNAL(mapped(int)), this, SLOT(thresholdRowColumn(int)));
00182 
00183    // I2C configuration bits 32-33
00184 
00185    grid = new QGridLayout(I2CRegsGroup);
00186    grid->setMargin(3);
00187    grid->setSpacing(3);
00188    map = new QSignalMapper(this);
00189 
00190    for (int n=0;n<NumConfigBits;n++) {
00191       fConfigChks[n] = new QCheckBox(this);
00192       fConfigChks[n]->setText(nxyter::NxI2c::configurationBitName(n));
00193       grid->addWidget(fConfigChks[n], n, 0);
00194 
00195       QObject::connect(fConfigChks[n], SIGNAL(clicked(bool)), map, SLOT(map()));
00196       map->setMapping(fConfigChks[n], n);
00197    }
00198 
00199    QObject::connect(map, SIGNAL(mapped(int)), this, SLOT(configBitChanged(int)));
00200 
00201    // other registers
00202 
00203    grid = new QGridLayout(OtherRegsGroup);
00204    grid->setMargin(3);
00205    grid->setSpacing(3);
00206    map = new QSignalMapper(this);
00207 
00208    for (int n=0;n<NumOtherRegs;n++) {
00209       grid->addWidget(new QLabel(QString("#%1: %2").arg(OtherRegsId[n]).arg(nxyter::NxI2c::registerName(OtherRegsId[n])), this), n, 0);
00210 
00211       fOtherSpins[n] = new QSpinBox(this);
00212       fOtherSpins[n]->setMinimum(0);
00213       fOtherSpins[n]->setMaximum(255);
00214       fOtherSpins[n]->setMinimumWidth(70);
00215       grid->addWidget(fOtherSpins[n], n, 1);
00216 
00217       QObject::connect(fOtherSpins[n], SIGNAL(valueChanged(int)), map, SLOT(map()));
00218       map->setMapping(fOtherSpins[n], n);
00219    }
00220    QObject::connect(map, SIGNAL(mapped(int)), this, SLOT(otherRegsChanged(int)));
00221 
00222    getSubConfig();
00223 }
00224 
00225 
00226 bool NxyterWidget::getSubConfig()
00227 {
00228    int res = fChip->i2c().getContext(fContext);
00229 
00230    showContext();
00231 
00232    return res==0;
00233 }
00234 
00235 bool NxyterWidget::setSubConfig()
00236 {
00237    return fChip->i2c().setContext(fContext) == 0;
00238 }
00239 
00240 bool NxyterWidget::fillCmdFile(FILE* f)
00241 {
00242    fprintf(f, "\n// NXYTER relevant settings\n");
00243 
00244    return fContext.fillCmdFile(f, 0 /*fChip->getNxNumber()*/);
00245 }
00246 
00247 bool NxyterWidget::setSubToDefault()
00248 {
00249    fContext.setToDefault();
00250 
00251    showContext();
00252 
00253    setSubChangedOn();
00254 
00255    return true;
00256 }
00257 
00258 
00259 void NxyterWidget::showContext()
00260 {
00261    fIgnore = true;
00262 
00263    for (int n=0;n<NumBias;n++) {
00264       fBiasSpins[n]->setValue(fContext.getRegister(BiasShift+n));
00265       fBiasSlider[n]->setValue(fContext.getRegister(BiasShift+n));
00266    }
00267 
00268    for (int n=0;n<NumConfigBits;n++) {
00269       bool on = fContext.getConfigurationBit(n);
00270       fConfigChks[n]->setCheckState(on ? Qt::Checked : Qt::Unchecked);
00271    }
00272 
00273    for (int n=0;n<NumOtherRegs;n++)
00274       fOtherSpins[n]->setValue(fContext.getRegister(OtherRegsId[n]));
00275 
00276    fIgnore = false;
00277 
00278    showMask();
00279 
00280    showThreshold();
00281 }
00282 
00283 
00284 void NxyterWidget::showMask()
00285 {
00286    fIgnore = true;
00287    for (int n=0;n<MaskSize;n++) {
00288       bool off = fContext.getChannelMaskBit(n);
00289       fMaskChks[n]->setCheckState(off ? Qt::Unchecked : Qt::Checked);
00290    }
00291    fIgnore = false;
00292 }
00293 
00294 void NxyterWidget::showThreshold(int select)
00295 {
00296    fIgnore = true;
00297 
00298    for (int n=0;n<MaskSize+1;n++) {
00299       if ((select>=0) && (n!=select)) continue;
00300 
00301       uint8_t value = fContext.getThresholdTrim(n);
00302 
00303       fThrdSpins[n]->setValue(value);
00304 
00305       bool off = fContext.getPowerOffMaskBit(n);
00306 
00307       fThrdSpins[n]->setStyleSheet(off ? "QWidget { background-color:red; }" : "QWidget { background-color:0; }");
00308    }
00309 
00310    fIgnore = false;
00311 
00312 }
00313 
00314 void NxyterWidget::biasRegChanged(int nreg)
00315 {
00316    if (fIgnore) return;
00317    fIgnore = true;
00318 
00319    int value = 0;
00320 
00321    if (nreg>=100) {
00322       nreg -= 100;
00323       value = fBiasSpins[nreg]->value();
00324       fBiasSlider[nreg]->setValue(value);
00325    } else {
00326       value = fBiasSlider[nreg]->value();
00327       fBiasSpins[nreg]->setValue(value);
00328    }
00329 
00330    fContext.setRegister(BiasShift+nreg, value);
00331 
00332    fChip->i2c().setRegister(BiasShift+nreg, value);
00333 
00334    fIgnore = false;
00335 }
00336 
00337 void NxyterWidget::maskRowColumn(int pos)
00338 {
00339    if (fIgnore) return;
00340 
00341    setSubChangedOn();
00342 
00343    if (pos==999) {
00344       for (int n=0;n<MaskSize;n++) {
00345          bool off = fContext.getChannelMaskBit(n);
00346          fContext.setChannelMaskBit(n, !off);
00347       }
00348    } else
00349    if (pos >= 700) {
00350       pos-=700;
00351       for (int n=0;n<16;n++) {
00352          bool off = fContext.getChannelMaskBit(n*8+pos);
00353          fContext.setChannelMaskBit(n*8+pos, !off);
00354       }
00355    } else
00356    if (pos >= 500) {
00357       pos-=500;
00358       for (int n=0;n<8;n++) {
00359          bool off = fContext.getChannelMaskBit(pos*8+n);
00360          fContext.setChannelMaskBit(pos*8+n, !off);
00361       }
00362    } else
00363    if (pos<MaskSize) {
00364       bool off = fMaskChks[pos]->checkState() == Qt::Unchecked;
00365       fContext.setChannelMaskBit(pos, off);
00366       return;
00367    }
00368 
00369    showMask();
00370 }
00371 
00372 void NxyterWidget::thresholdRowColumn(int pos)
00373 {
00374    if (fIgnore) return;
00375 
00376    setSubChangedOn();
00377 
00378    if (pos==999) {
00379       for (int n=0;n<MaskSize;n++) {
00380          bool off = fContext.getPowerOffMaskBit(n);
00381          fContext.setPowerOffMaskBit(n, !off);
00382       }
00383    } else
00384    if (pos==888) {
00385       for (int n=0;n<MaskSize;n++) {
00386          uint8_t trim = fContext.getThresholdTrim(n);
00387          fContext.setThresholdTrim(n, (trim+1) % 0x20);
00388       }
00389    } else
00390    if (pos >= 800) {  // vertical +
00391       pos-=800;
00392       for (int n=0;n<16;n++) {
00393          uint8_t trim = fContext.getThresholdTrim(n*8+pos);
00394          fContext.setThresholdTrim(n*8+pos, (trim+1) % 0x20);
00395       }
00396    } else
00397    if (pos >= 700) { // vertical v
00398       pos-=700;
00399       for (int n=0;n<16;n++) {
00400          bool off = fContext.getPowerOffMaskBit(n*8+pos);
00401          fContext.setPowerOffMaskBit(n*8+pos, !off);
00402       }
00403    } else
00404    if (pos == 616) {
00405       uint8_t trim = fContext.getThresholdTrim(MaskSize);
00406       fContext.setThresholdTrim(MaskSize, (trim+1) % 0x20);
00407    } else
00408    if (pos >= 600) { // vertical v
00409       pos-=600;
00410       for (int n=0;n<8;n++) {
00411          uint8_t trim = fContext.getThresholdTrim(pos*8+n);
00412          fContext.setThresholdTrim(pos*8+n, (trim+1) % 0x20);
00413       }
00414    } else
00415    if (pos==516) {
00416       bool off = fContext.getPowerOffMaskBit(MaskSize);
00417       fContext.setPowerOffMaskBit(MaskSize, !off);
00418    } else
00419 
00420    if (pos >= 500) {
00421       pos-=500;
00422       for (int n=0;n<8;n++) {
00423          bool off = fContext.getPowerOffMaskBit(pos*8+n);
00424          fContext.setPowerOffMaskBit(pos*8+n, !off);
00425       }
00426    } else
00427    if (pos<=MaskSize) {
00428       int value = fThrdSpins[pos]->value();
00429       if (value==-1) {
00430          fContext.setThresholdTrim(pos, 31);
00431          fContext.setPowerOffMaskBit(pos, !fContext.getPowerOffMaskBit(pos));
00432          showThreshold(pos);
00433       } else
00434       if (value==32) {
00435          fContext.setThresholdTrim(pos, 0);
00436          fContext.setPowerOffMaskBit(pos, !fContext.getPowerOffMaskBit(pos));
00437          showThreshold(pos);
00438       } else {
00439          fContext.setThresholdTrim(pos, value);
00440       }
00441 
00442       return;
00443    }
00444 
00445    showThreshold();
00446 }
00447 
00448 void NxyterWidget::configBitChanged(int nbit)
00449 {
00450    if (fIgnore) return;
00451 
00452    bool on = fConfigChks[nbit]->checkState() == Qt::Checked;
00453 
00454    fContext.setConfigurationBit(nbit, on);
00455 
00456    setSubChangedOn();
00457 }
00458 
00459 void NxyterWidget::otherRegsChanged(int n)
00460 {
00461    if (fIgnore) return;
00462 
00463    int nreg = OtherRegsId[n];
00464 
00465    int value = fOtherSpins[n]->value();
00466 
00467    fContext.setRegister(nreg, value);
00468 
00469    setSubChangedOn();
00470 }
00471 

Generated on Tue Dec 10 2013 04:52:22 for ROCsoft by  doxygen 1.7.1