added cyclic update
This commit is contained in:
@@ -20,13 +20,14 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
||||
ui->txt_address->setText(DEFAULT_ADDRESS);
|
||||
mAddress = ui->txt_address->text();
|
||||
|
||||
connect(&mTimer, &QTimer::timeout, this, &MainWindow::sendVolume);
|
||||
mTimer.setSingleShot(true);
|
||||
// setup volume value collection
|
||||
connect(&mTimerValCollect, &QTimer::timeout, this, &MainWindow::sendVolume);
|
||||
mTimerValCollect.setSingleShot(true);
|
||||
|
||||
// load initial data
|
||||
sendCommand("<YAMAHA_AV cmd=\"GET\"><System><Power_Control><Power>GetParam</Power></Power_Control></System></YAMAHA_AV>");
|
||||
sendCommand("<YAMAHA_AV cmd=\"GET\"><Main_Zone><Volume><Lvl>GetParam</Lvl></Volume></Main_Zone></YAMAHA_AV>");
|
||||
sendCommand("<YAMAHA_AV cmd=\"GET\"><Main_Zone><Input><Input_Sel>GetParam</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
|
||||
// load initial data and set update rate
|
||||
updateAVState();
|
||||
connect(&mTimerUpdate, &QTimer::timeout, this, &MainWindow::updateAVState);
|
||||
mTimerUpdate.start(UPDATETIME);
|
||||
|
||||
QFile css(":style.css");
|
||||
if (css.open(QFile::ReadOnly | QFile::Text))
|
||||
@@ -130,10 +131,8 @@ void MainWindow::setPowerState()
|
||||
ui->dial->setStyleSheet("");
|
||||
setActiveButton("");
|
||||
}
|
||||
qDebug() << ui->btn_onoff->isEnabled(); // rogo: delete
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_txt_address_textEdited(const QString &arg1)
|
||||
{
|
||||
mAddress = arg1;
|
||||
@@ -164,7 +163,7 @@ void MainWindow::on_dial_valueChanged(int value)
|
||||
|
||||
ui->lbl_volume->setText(QString::number(value));
|
||||
mVolume = value;
|
||||
mTimer.start(WAITTIME);
|
||||
mTimerValCollect.start(COLLECTTIME);
|
||||
}
|
||||
|
||||
void MainWindow::sendVolume()
|
||||
@@ -174,6 +173,13 @@ void MainWindow::sendVolume()
|
||||
+ "</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>");
|
||||
}
|
||||
|
||||
void MainWindow::updateAVState()
|
||||
{
|
||||
sendCommand("<YAMAHA_AV cmd=\"GET\"><System><Power_Control><Power>GetParam</Power></Power_Control></System></YAMAHA_AV>");
|
||||
sendCommand("<YAMAHA_AV cmd=\"GET\"><Main_Zone><Volume><Lvl>GetParam</Lvl></Volume></Main_Zone></YAMAHA_AV>");
|
||||
sendCommand("<YAMAHA_AV cmd=\"GET\"><Main_Zone><Input><Input_Sel>GetParam</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
|
||||
}
|
||||
|
||||
void MainWindow::on_btn_hdmi1_clicked()
|
||||
{
|
||||
sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>HDMI1</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
|
||||
|
||||
11
mainwindow.h
11
mainwindow.h
@@ -16,11 +16,13 @@ class MainWindow : public QMainWindow
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = 0);
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
void setPowerState();
|
||||
|
||||
void updateAVState();
|
||||
|
||||
private slots:
|
||||
void on_btn_onoff_clicked();
|
||||
void replyFinished(QNetworkReply *reply);
|
||||
@@ -38,11 +40,14 @@ private:
|
||||
Ui::MainWindow *ui;
|
||||
|
||||
QString mAddress;
|
||||
QTimer mTimer;
|
||||
QTimer mTimerValCollect;
|
||||
QTimer mTimerUpdate;
|
||||
|
||||
bool mPowered = false;
|
||||
int mVolume = 0;
|
||||
QString mInput;
|
||||
const int WAITTIME = 400;
|
||||
const int COLLECTTIME = 400;
|
||||
const int UPDATETIME = 20000;
|
||||
|
||||
void sendCommand(QString cmd);
|
||||
void updateUi();
|
||||
|
||||
Reference in New Issue
Block a user