-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
96 lines (84 loc) · 2.5 KB
/
Copy pathmainwindow.cpp
File metadata and controls
96 lines (84 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <iostream>
#include <chrono>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->state = new TempState();
ui->settings->hide();
// ui->menubar->triggered
this->tostatus = ui->menubar->addAction("Status");
this->tosettings = ui->menubar->addAction("Settings");
connect(tostatus, SIGNAL(triggered(bool)), this, SLOT(status_selected()));
connect(tosettings, SIGNAL(triggered(bool)), this, SLOT(settings_selected()));
}
MainWindow::~MainWindow()
{
ui->menubar->removeAction(tostatus);
ui->menubar->removeAction(tosettings);
delete ui;
if (this->timerid > 0) {
killTimer(this->timerid);
}
}
void MainWindow::timerEvent(QTimerEvent *event) {
if (counter % 2 == 0) {
this->state->update();
}
if (counter % 5 == 0) {
std::cout << "{\"temp\": " << this->state->get() << ", \"led\": \"" << (this->state->moreThreshold() ? "ON" : "OFF") << "\"}" << std::endl;
}
if (this->state->moreThreshold()) this->ledon++;
else ledon = 0;
updateFields(this->state->moreThreshold());
counter++;
counter %= 10;
}
void MainWindow::updateFields(bool isledon) {
if (isledon) {
ui->led->setStyleSheet("#led {background-color: rgb(255, 255, 255);}");
}
else {
ui->led->setStyleSheet("");
}
ui->ledtimer->setText(QVariant::fromValue(ledon).toString());
ui->tempDisplay->setText(QVariant::fromValue(round(this->state->get() * 100) / 100).toString());
}
void MainWindow::on_applyButton_clicked()
{
this->state->updateMin((float) ui->min_range->value());
this->state->updateMax((float) ui->max_range->value());
this->state->updateThreshold((float) ui->threshold->value());
std::cout << "Applied" << std::endl;
}
void MainWindow::status_selected() {
ui->status->show();
ui->settings->hide();
}
void MainWindow::settings_selected() {
ui->status->hide();
ui->settings->show();
}
void MainWindow::on_startButton_clicked()
{
if (this->timerid != 0) {
ui->startButton->setText("Start");
killTimer(this->timerid);
this->timerid = this->counter = 0;
}
else {
ui->startButton->setText("Stop");
this->timerid = startTimer(std::chrono::milliseconds(1000), Qt::VeryCoarseTimer);
}
}
void MainWindow::on_pushButton_clicked()
{
updateFields(true);
}
void MainWindow::on_pushButton_2_clicked()
{
updateFields(false);
}