added functioning input change and read
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
mainwindow.h
12
mainwindow.h
@@ -22,9 +22,15 @@ public:
|
||||
private slots:
|
||||
void on_btn_onoff_clicked();
|
||||
void replyFinished(QNetworkReply *reply);
|
||||
void on_txt_address_textEdited(const QString &arg1);
|
||||
|
||||
void on_txt_address_textEdited(const QString &arg1);
|
||||
void on_dial_valueChanged(int value);
|
||||
void on_btn_hdmi1_clicked();
|
||||
void on_btn_hdmi2_clicked();
|
||||
void on_btn_hdmi3_clicked();
|
||||
void on_btn_spotify_clicked();
|
||||
void on_btn_airplay_clicked();
|
||||
void on_btn_audioin_clicked();
|
||||
|
||||
private:
|
||||
Ui::MainWindow *ui;
|
||||
@@ -33,8 +39,8 @@ private:
|
||||
QTimer mTimer;
|
||||
bool mPowered = false;
|
||||
int mVolume = 0;
|
||||
const int WAITTIME = 300;
|
||||
|
||||
QString mInput;
|
||||
const int WAITTIME = 400;
|
||||
|
||||
void sendCommand(QString cmd);
|
||||
void updateUi();
|
||||
|
||||
115
mainwindow.ui
115
mainwindow.ui
@@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>500</width>
|
||||
<height>168</height>
|
||||
<width>528</width>
|
||||
<height>199</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="contextMenuPolicy">
|
||||
@@ -18,51 +18,14 @@
|
||||
</property>
|
||||
<widget class="QWidget" name="centralWidget">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="btn_onoff">
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Address:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="txt_address">
|
||||
<property name="text">
|
||||
<string>10.0.0.227</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3" rowspan="2">
|
||||
<widget class="QDial" name="dial">
|
||||
<property name="minimum">
|
||||
<number>-805</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>-165</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0" rowspan="2" colspan="3">
|
||||
<item row="2" column="0" rowspan="2" colspan="3">
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Input</string>
|
||||
</property>
|
||||
<property name="flat">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QPushButton" name="btn_hdmi1">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
@@ -143,7 +106,7 @@
|
||||
</widget>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<item row="3" column="3">
|
||||
<widget class="QLabel" name="lbl_volume">
|
||||
<property name="font">
|
||||
<font>
|
||||
@@ -158,7 +121,69 @@
|
||||
<enum>QFrame::Sunken</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>-666</string>
|
||||
<string>-400</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="btn_onoff">
|
||||
<property name="text">
|
||||
<string>On</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3" rowspan="3">
|
||||
<widget class="QDial" name="dial">
|
||||
<property name="minimum">
|
||||
<number>-805</number>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>-200</number>
|
||||
</property>
|
||||
<property name="singleStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="pageStep">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>-400</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="invertedAppearance">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="notchesVisible">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Address:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="txt_address">
|
||||
<property name="text">
|
||||
<string>10.0.0.227</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="lbl_input">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
|
||||
Reference in New Issue
Block a user