Skip to content

Commit

Permalink
Add support for automatic temperature reports
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Rizzitello <rizzitello@kde.org>
  • Loading branch information
sithlord48 committed Feb 11, 2019
1 parent b5e90eb commit e0720a1
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
39 changes: 35 additions & 4 deletions testclient/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(core, &AtCore::stateChanged, this, &MainWindow::printerStateChanged);
connect(core, &AtCore::portsChanged, this, &MainWindow::locateSerialPort);
connect(core, &AtCore::sdCardFileListChanged, sdWidget, &SdWidget::updateFilelist);
connect(core, &AtCore::autoTemperatureReportChanged, this, &MainWindow::updateAutoTemperatureReport);
comboPort->setFocus(Qt::OtherFocusReason);
}

Expand Down Expand Up @@ -203,14 +204,12 @@ void MainWindow::makeTempTimelineDock()

auto timerLayout = new QHBoxLayout;
auto lblTimer = new QLabel(tr("Seconds Between Temperature Checks"), this);
auto sbTemperatureTimer = new QSpinBox(this);
sbTemperatureTimer = new QSpinBox(this);
sbTemperatureTimer->setRange(0, 90);

connect(sbTemperatureTimer, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int value) {
core->setTemperatureTimerInterval(value * 1000);
});

connect(core, &AtCore::temperatureTimerIntervalChanged, this, [sbTemperatureTimer](int value) {
connect(core, &AtCore::temperatureTimerIntervalChanged, this, [this](int value) {
if (value != sbTemperatureTimer->value()) {
sbTemperatureTimer->blockSignals(true);
sbTemperatureTimer->setValue(value / 1000);
Expand Down Expand Up @@ -556,6 +555,7 @@ void MainWindow::printerStateChanged(AtCore::STATES state)
if (connectionTimer->isActive()) {
connectionTimer->stop();
}
sbTemperatureTimer->setValue(0);
stateString = QStringLiteral("Not Connected");
buttonConnect->setText(tr("Connect"));
setConnectionWidgetsEnabled(true);
Expand Down Expand Up @@ -627,3 +627,34 @@ void MainWindow::setConnectionWidgetsEnabled(bool enabled)
comboPlugin->setEnabled(enabled);
comboPort->setEnabled(enabled);
}

void MainWindow::updateAutoTemperatureReport(bool autoReport)
{
disconnect(sbTemperatureTimer, QOverload<int>::of(&QSpinBox::valueChanged), this, {});
disconnect(core, &AtCore::temperatureTimerIntervalChanged, this, {});
disconnect(core, &AtCore::autoCheckTemperatureIntervalChanged, this, {});

if (autoReport) {
connect(sbTemperatureTimer, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int value) {
core->setAutoCheckTemperatureInterval(value);
});
connect(core, &AtCore::autoCheckTemperatureIntervalChanged, this, [this](int value) {
if (value != sbTemperatureTimer->value()) {
sbTemperatureTimer->blockSignals(true);
sbTemperatureTimer->setValue(value);
sbTemperatureTimer->blockSignals(false);
}
});
} else {
connect(sbTemperatureTimer, QOverload<int>::of(&QSpinBox::valueChanged), this, [this](int value) {
core->setTemperatureTimerInterval(value * 1000);
});
connect(core, &AtCore::temperatureTimerIntervalChanged, this, [this](int value) {
if (value != sbTemperatureTimer->value()) {
sbTemperatureTimer->blockSignals(true);
sbTemperatureTimer->setValue(value / 1000);
sbTemperatureTimer->blockSignals(false);
}
});
}
}
8 changes: 6 additions & 2 deletions testclient/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ private slots:
* @param disabled: True if items are disabled.
*/
void setDangeriousDocksDisabled(bool disabled);

/**
* @brief Called when atcore changes it temperature reporting mode
* @param autoReport: True if using temperature auto reporting
*/
void updateAutoTemperatureReport(bool autoReport);
private:
AtCore *core;
// Define max number of fans
Expand Down Expand Up @@ -165,7 +169,7 @@ private slots:
QPushButton *buttonConnect = nullptr;
QCheckBox *cbReset = nullptr;
QTimer *connectionTimer = nullptr;

QSpinBox *sbTemperatureTimer = nullptr;
void makeMoveDock();
QDockWidget *moveDock = nullptr;
MovementWidget *movementWidget = nullptr;
Expand Down

0 comments on commit e0720a1

Please sign in to comment.