Commit 108f37ce authored by Projects's avatar Projects Committed by Grzegorz Daniluk

GUI support for input errors

parent 5de76bf4
......@@ -51,6 +51,11 @@ DiotHardware::DiotHardware(int address, int slots_nr)
for(int i = 0; i < crate->GetCardCount(); ++i) {
emit InputChanged(i, crate->GetSlotInputs(i));
uint32_t inpError = crate->GetSlotInputErrs(i);
if (inpError) {
emit InputErrChanged(i, inpError);
}
}
for(unsigned int i = 0; i < crate->GetFanCount(); ++i) {
......@@ -86,9 +91,13 @@ DiotIOCard::DiotIOCard(QDialog* parent, DiotHardware& hw, int num, int idx)
outputs(num, false), slot_nr(idx), io_count(num)
{
QHBoxLayout *mainLayout = new QHBoxLayout();
QGridLayout *grid = new QGridLayout();
QGroupBox *groupBox = new QGroupBox(this);
grid->setColumnStretch(0, 0);
grid->setColumnStretch(1, 1);
grid->setColumnStretch(2, 1);
QGroupBox *groupBox = new QGroupBox(this);
groupBox->setTitle(QString("Slot %1").arg(idx + 1));
for(int i = 0; i < io_count; ++i) {
......@@ -98,21 +107,32 @@ DiotIOCard::DiotIOCard(QDialog* parent, DiotHardware& hw, int num, int idx)
grid->addWidget(state, i, 0);
lbl_state.push_back(state);
QPushButton* test = new QPushButton(groupBox);
test->setText("Test");
QPushButton* test = new QPushButton("Test", groupBox);
test->setFixedWidth(50);
grid->addWidget(test, i, 1);
QObject::connect(test, &QPushButton::clicked,
[=](){ action_click(idx, i); });
[=](){ testBtn_click(idx, i); });
QPushButton* clearErr = new QPushButton("", groupBox);
clearErr->setFixedWidth(70);
clearErr->setStyleSheet("color: red");
// "Clear Error" button is reenabled when an error occurs
clearErr->setEnabled(false);
grid->addWidget(clearErr, i, 2);
btn_clrerr.push_back(clearErr);
QObject::connect(clearErr, &QPushButton::clicked, [=](){
clearErr->setEnabled(false);
clearErr->setText("");
});
}
groupBox->setLayout(grid);
mainLayout->addWidget(groupBox);
setLayout(mainLayout);
update_inputs();
QObject::connect(this, &DiotIOCard::InputChanged, [=](){ update_inputs(); });
QObject::connect(this, &DiotIOCard::OutputChanged,
&hw, &DiotHardware::SetOutput);
update_inputs();
QObject::connect(this, &DiotIOCard::OutputChanged, &hw, &DiotHardware::SetOutput);
}
......@@ -122,13 +142,23 @@ void DiotIOCard::SetInput(unsigned int state) {
}
void DiotIOCard::SetInputErr(unsigned int state) {
for(unsigned int i = 0; i < btn_clrerr.size(); ++i) {
if(state & (1 << i)) {
btn_clrerr[i]->setEnabled(true);
btn_clrerr[i]->setText("Clear Error");
}
}
}
void DiotIOCard::SetOutput(unsigned int state) {
if(int_to_vec(state, outputs))
emit OutputChanged(slot_nr, state);
}
void DiotIOCard::action_click(int slot, int io) {
void DiotIOCard::testBtn_click(int slot, int io) {
qDebug() << "button test clicked - slot(" << slot << ") io(" << io << ")";
outputs[io] = !outputs[io];
emit OutputChanged(slot_nr, GetOutput());
......@@ -195,6 +225,8 @@ DiotIOController::DiotIOController(QDialog* dialog, DiotHardware& hw, int slots_
QObject::connect(&hw, &DiotHardware::InputChanged,
this, &DiotIOController::UpdateInput);
QObject::connect(&hw, &DiotHardware::InputErrChanged,
this, &DiotIOController::UpdateInputErr);
}
......@@ -205,6 +237,13 @@ void DiotIOController::UpdateInput(int slot, unsigned int state)
}
void DiotIOController::UpdateInputErr(int slot, unsigned int state)
{
qDebug() << "received input err update: slot " << slot << "=" << state;
io_slots[slot]->SetInputErr(state);
}
DiotDiag::DiotDiag(QDialog* parent, DiotHardware& hw)
: QFrame(parent)
{
......
......@@ -73,6 +73,13 @@ signals:
*/
void InputChanged(int slot, unsigned int state);
/**
* Signal emitted whenever an input error occurs.
* @param slot is the card number (indexing from 0).
* @param state is the inputs state.
*/
void InputErrChanged(int slot, unsigned int state);
/**
* Signal emitted on every macrocycle, provides information about fan state.
* @param fan is the fan number (indexing from 0).
......@@ -126,14 +133,16 @@ public:
public slots:
void SetInput(unsigned int state);
void SetInputErr(unsigned int state);
void SetOutput(unsigned int state);
signals:
void InputChanged(int slot, unsigned int state);
void InputErrChanged(int slot, unsigned int state);
void OutputChanged(int slot, unsigned int state);
protected:
void action_click(int slot, int io);
void testBtn_click(int slot, int io);
void update_inputs();
void update_outputs(int slot);
......@@ -142,6 +151,7 @@ protected:
std::vector<bool> inputs, outputs;
std::vector<QLabel*> lbl_state;
std::vector<QPushButton*> btn_clrerr;
const int slot_nr;
const int io_count;
};
......@@ -158,6 +168,7 @@ public:
public slots:
void UpdateInput(int slot, unsigned int state);
void UpdateInputErr(int slot, unsigned int state);
private:
std::vector<std::unique_ptr<DiotIOCard>> io_slots;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment