added functioning input change and read

This commit is contained in:
2018-10-13 13:04:08 +02:00
parent 5a454e327c
commit f1d9a08a84
3 changed files with 126 additions and 54 deletions

View File

@@ -2,7 +2,6 @@
#include "ui_mainwindow.h"
#include <QTimer>
#include <qnetwork.h>
#include <QtNetwork/QNetworkReply>
class QNetworkReply;
@@ -23,6 +22,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
// 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>");
}
MainWindow::~MainWindow()
@@ -56,22 +56,26 @@ void MainWindow::replyFinished(QNetworkReply* reply)
}
// check power state
QRegularExpression regexPower("<Power_Control><Power>(.*)</Power></Power_Control>");
QRegularExpression regexPower("<Power_Control><Power>(.+)</Power></Power_Control>");
QRegularExpressionMatch matchPower = regexPower.match(ans);
if (matchPower.hasMatch()) {
if (matchPower.captured(1) == "On") mPowered = true;
else if (matchPower.captured(1) == "Off") mPowered = false;
}
// check volume
QRegularExpression regexVolume("<Volume><Lvl><Val>(.*)</Val>");
QRegularExpression regexVolume("<Volume><Lvl><Val>(.+)</Val>");
QRegularExpressionMatch matchVolume = regexVolume.match(ans);
if (matchVolume.hasMatch()) {
mVolume = matchVolume.captured(1).toInt();
}
// check input
QRegularExpression regexInput("<Input><Input_Sel>(.+)</Input_Sel>");
QRegularExpressionMatch matchInput = regexInput.match(ans);
if (matchInput.hasMatch())
mInput = matchInput.captured(1);
reply->deleteLater();
updateUi();
}
@@ -87,6 +91,7 @@ void MainWindow::updateUi() {
ui->btn_spotify->setEnabled(mPowered);
ui->btn_airplay->setEnabled(mPowered);
ui->btn_audioin->setEnabled(mPowered);
ui->lbl_input->setText(mInput);
}
void MainWindow::on_txt_address_textEdited(const QString &arg1)
@@ -118,7 +123,6 @@ void MainWindow::on_dial_valueChanged(int value)
value -= d;
ui->lbl_volume->setText(QString::number(value));
ui->dial->setValue(value);
mVolume = value;
mTimer.start(WAITTIME);
}
@@ -130,4 +134,41 @@ void MainWindow::sendVolume()
+ "</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></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>");
mInput = "HDMI1";
}
void MainWindow::on_btn_hdmi2_clicked()
{
sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>HDMI2</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
mInput = "HDMI2";
}
void MainWindow::on_btn_hdmi3_clicked()
{
sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>HDMI3</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
mInput = "HDMI3";
}
void MainWindow::on_btn_spotify_clicked()
{
sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>Spotify</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
mInput = "Spotify";
}
void MainWindow::on_btn_airplay_clicked()
{
// TODO
sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>IPOD</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
mInput = "IPOD";
}
void MainWindow::on_btn_audioin_clicked()
{
sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>AUDIO</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
mInput = "AUDIO";
}
}