11 Commits
v0.1 ... master

Author SHA1 Message Date
Robin "Rogo" Goltermann
d7e1741833 possible fix for memory leak 2022-07-20 15:43:45 +02:00
Robin "Rogo" Goltermann
87261361b3 fixed missing include, added build folder to gitignore 2019-09-06 13:07:51 +02:00
082c061ac7 fixed recievcer state off after longer runtime 2018-12-23 18:37:56 +01:00
fde8b05754 saving window positioning 2018-11-18 00:34:50 +01:00
112090ab82 added persistent address 2018-11-17 23:06:09 +01:00
eafff377fd Merge branch 'master' of http://git.rogocloud.eu/rogo/yremote 2018-11-17 22:30:04 +01:00
4c473f5d07 added cyclic update 2018-11-17 22:29:57 +01:00
rogo
25da7e6b14 Update 'README.md' 2018-11-17 21:19:12 +00:00
rogo
d187ca69db Update 'README.md' 2018-11-17 21:17:11 +00:00
a347c3d965 layout rework 2018-11-17 22:11:01 +01:00
333dc87b75 dark mode 2018-11-17 21:56:15 +01:00
9 changed files with 274 additions and 130 deletions

3
.gitignore vendored
View File

@@ -34,3 +34,6 @@ Makefile*
*.qmlproject.user *.qmlproject.user
*.qmlproject.user.* *.qmlproject.user.*
# build
build*

View File

@@ -1,2 +1,8 @@
# yremote # yremote
Simple PC remote for yamaha recievers.
![](https://i.imgur.com/Nux4CNN.png)
Only tested with RX-V475.

View File

@@ -6,6 +6,9 @@ using namespace yremote;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
QApplication a(argc, argv); QApplication a(argc, argv);
QCoreApplication::setOrganizationName("RogoSoftware");
QCoreApplication::setOrganizationDomain("git.rogocloud.eu");
QCoreApplication::setApplicationName("yremote");
MainWindow w; MainWindow w;
w.show(); w.show();

View File

@@ -1,33 +1,53 @@
#include "mainwindow.h" #include "mainwindow.h"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QFile>
#include <QTimer> #include <QTimer>
#include <QtNetwork/QNetworkReply> #include <QtNetwork/QNetworkReply>
#include <QRegularExpression>
class QNetworkReply; class QNetworkReply;
namespace yremote { namespace yremote {
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{ {
QString DEFAULT_ADDRESS = "10.0.0.227";
ui->setupUi(this); ui->setupUi(this);
setFixedSize(size()); setFixedSize(size());
ui->txt_address->setText(DEFAULT_ADDRESS); #if defined(Q_OS_WIN)
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
#endif
mSettings = new QSettings(QSettings::IniFormat, QSettings::UserScope, "RogoSoftware", "yremote");
mNetworkManager = new QNetworkAccessManager(this);
restoreGeometry(mSettings->value("geometry", saveGeometry()).toByteArray());
move(mSettings->value("pos", pos()).toPoint());
ui->txt_address->setText(mSettings->value("av_address", "").toString());
mAddress = ui->txt_address->text(); mAddress = ui->txt_address->text();
connect(&mTimer, &QTimer::timeout, this, &MainWindow::sendVolume); // setup volume value collection
mTimer.setSingleShot(true); connect(&mTimerValCollect, &QTimer::timeout, this, &MainWindow::sendVolume);
mTimerValCollect.setSingleShot(true);
// load initial data connect(&mTimerUpdateAddress, &QTimer::timeout, this, &MainWindow::updateAVState);
sendCommand("<YAMAHA_AV cmd=\"GET\"><System><Power_Control><Power>GetParam</Power></Power_Control></System></YAMAHA_AV>"); mTimerUpdateAddress.setSingleShot(true);
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(&mTimerUpdateState, &QTimer::timeout, this, &MainWindow::updateAVState);
mTimerUpdateState.start(TIME_UPDATE_STATE);
QFile css(":style.css");
if (css.open(QFile::ReadOnly | QFile::Text))
this->setStyleSheet(css.readAll());
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
{ {
delete ui; delete ui;
delete mSettings;
delete mNetworkManager;
} }
void MainWindow::sendCommand(QString cmd) void MainWindow::sendCommand(QString cmd)
@@ -37,27 +57,25 @@ void MainWindow::sendCommand(QString cmd)
request.setRawHeader("Content-Type", "text/xml; charset=UTF-8"); request.setRawHeader("Content-Type", "text/xml; charset=UTF-8");
request.setRawHeader("Content-Length", QByteArray::number(cmd.size())); request.setRawHeader("Content-Length", QByteArray::number(cmd.size()));
QNetworkAccessManager *networkManager = new QNetworkAccessManager(this); mNetworkManager->post(request, cmd.toUtf8());
networkManager->post(request, cmd.toUtf8()); connect(mNetworkManager, &QNetworkAccessManager::finished, this, &MainWindow::replyFinished);
connect(networkManager, &QNetworkAccessManager::finished, this, &MainWindow::replyFinished);
} }
void MainWindow::replyFinished(QNetworkReply* reply) void MainWindow::replyFinished(QNetworkReply* reply)
{ {
QString ans;
if(reply->error() == QNetworkReply::NoError) { if(reply->error() == QNetworkReply::NoError) {
QByteArray data = reply->readAll(); QByteArray data = reply->readAll();
ans = QString(data); mAnswer = QString(data);
} else { } else {
qDebug() << reply->url(); qDebug() << reply->url();
qDebug() << reply->errorString(); qDebug() << reply->errorString();
return;
mPowered = false;
} }
// check power state // check power state
QRegularExpression regexPower("<Power_Control><Power>(.+)</Power></Power_Control>"); QRegularExpression regexPower("<Power_Control><Power>(.+)</Power></Power_Control>");
QRegularExpressionMatch matchPower = regexPower.match(ans); QRegularExpressionMatch matchPower = regexPower.match(mAnswer);
if (matchPower.hasMatch()) { if (matchPower.hasMatch()) {
if (matchPower.captured(1) == "On") mPowered = true; if (matchPower.captured(1) == "On") mPowered = true;
else if (matchPower.captured(1) == "Off") mPowered = false; else if (matchPower.captured(1) == "Off") mPowered = false;
@@ -65,14 +83,14 @@ void MainWindow::replyFinished(QNetworkReply* reply)
// check volume // check volume
QRegularExpression regexVolume("<Volume><Lvl><Val>(.+)</Val>"); QRegularExpression regexVolume("<Volume><Lvl><Val>(.+)</Val>");
QRegularExpressionMatch matchVolume = regexVolume.match(ans); QRegularExpressionMatch matchVolume = regexVolume.match(mAnswer);
if (matchVolume.hasMatch()) { if (matchVolume.hasMatch()) {
mVolume = matchVolume.captured(1).toInt(); mVolume = matchVolume.captured(1).toInt();
} }
// check input // check input
QRegularExpression regexInput("<Input><Input_Sel>(.+)</Input_Sel>"); QRegularExpression regexInput("<Input><Input_Sel>(.+)</Input_Sel>");
QRegularExpressionMatch matchInput = regexInput.match(ans); QRegularExpressionMatch matchInput = regexInput.match(mAnswer);
if (matchInput.hasMatch()) if (matchInput.hasMatch())
mInput = matchInput.captured(1); mInput = matchInput.captured(1);
@@ -92,15 +110,7 @@ void MainWindow::updateUi() {
ui->btn_audioin->setEnabled(mPowered); ui->btn_audioin->setEnabled(mPowered);
setActiveButton(mInput); setActiveButton(mInput);
setPowerState();
if (mPowered) {
ui->btn_onoff->setText("On");
ui->btn_onoff->setStyleSheet("background-color: SpringGreen");
} else {
ui->btn_onoff->setText("Off");
ui->btn_onoff->setStyleSheet("background-color: DarkRed");
setActiveButton("");
}
} }
void MainWindow::setActiveButton(QString prop) void MainWindow::setActiveButton(QString prop)
@@ -109,16 +119,34 @@ void MainWindow::setActiveButton(QString prop)
QPushButton *b = dynamic_cast<QPushButton*>(q); QPushButton *b = dynamic_cast<QPushButton*>(q);
if (b){ if (b){
if (b->property("input") == prop) if (b->property("input") == prop)
b->setStyleSheet("background-color: SpringGreen"); b->setStyleSheet("background-color: #24e895; color: #404040;");
else else
b->setStyleSheet(""); b->setStyleSheet("");
} }
} }
} }
void MainWindow::setPowerState()
{
if (mPowered) {
ui->btn_onoff->setText("On");
ui->btn_onoff->setStyleSheet("background-color: #24e895; color: #404040;");
ui->lbl_volume->setStyleSheet("color: #24e895");
ui->dial->setStyleSheet("background-color: #24e895");
} else {
ui->btn_onoff->setText("Off");
ui->btn_onoff->setStyleSheet("");
ui->lbl_volume->setStyleSheet("");
ui->dial->setStyleSheet("");
setActiveButton("");
}
}
void MainWindow::on_txt_address_textEdited(const QString &arg1) void MainWindow::on_txt_address_textEdited(const QString &arg1)
{ {
mAddress = arg1; mAddress = arg1;
mSettings->setValue("av_address", mAddress);
mTimerUpdateAddress.start(TIME_UPDATE_ADDRESS);
} }
void MainWindow::on_btn_onoff_clicked() void MainWindow::on_btn_onoff_clicked()
@@ -146,7 +174,7 @@ void MainWindow::on_dial_valueChanged(int value)
ui->lbl_volume->setText(QString::number(value)); ui->lbl_volume->setText(QString::number(value));
mVolume = value; mVolume = value;
mTimer.start(WAITTIME); mTimerValCollect.start(TIME_VOL_COLLECT);
} }
void MainWindow::sendVolume() void MainWindow::sendVolume()
@@ -156,6 +184,19 @@ void MainWindow::sendVolume()
+ "</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>"); + "</Val><Exp>1</Exp><Unit>dB</Unit></Lvl></Volume></Main_Zone></YAMAHA_AV>");
} }
void MainWindow::moveEvent(QMoveEvent *)
{
mSettings->setValue("geometry", geometry());
mSettings->setValue("pos", pos());
}
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() void MainWindow::on_btn_hdmi1_clicked()
{ {
sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>HDMI1</Input_Sel></Input></Main_Zone></YAMAHA_AV>"); sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>HDMI1</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
@@ -182,7 +223,6 @@ void MainWindow::on_btn_spotify_clicked()
void MainWindow::on_btn_airplay_clicked() 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>"); sendCommand("<YAMAHA_AV cmd=\"PUT\"><Main_Zone><Input><Input_Sel>IPOD</Input_Sel></Input></Main_Zone></YAMAHA_AV>");
mInput = "IPOD"; mInput = "IPOD";
} }

View File

@@ -2,6 +2,7 @@
#define MAINWINDOW_H #define MAINWINDOW_H
#include <QMainWindow> #include <QMainWindow>
#include <QSettings>
#include <QTimer> #include <QTimer>
#include "QtNetwork/QNetworkAccessManager" #include "QtNetwork/QNetworkAccessManager"
@@ -16,8 +17,11 @@ class MainWindow : public QMainWindow
Q_OBJECT Q_OBJECT
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow() override;
void setPowerState();
void updateAVState();
private slots: private slots:
void on_btn_onoff_clicked(); void on_btn_onoff_clicked();
@@ -35,18 +39,30 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
QString mAddress;
QTimer mTimer;
bool mPowered = false; bool mPowered = false;
int mVolume = 0; int mVolume = 0;
QString mInput; QString mInput;
const int WAITTIME = 400; const int TIME_VOL_COLLECT = 400;
const int TIME_UPDATE_STATE = 10000;
const int TIME_UPDATE_ADDRESS = 1000;
QString mAddress;
QTimer mTimerValCollect;
QTimer mTimerUpdateState;
QTimer mTimerUpdateAddress;
QSettings* mSettings = nullptr;
QNetworkAccessManager *mNetworkManager = nullptr;
QString mAnswer;
void sendCommand(QString cmd); void sendCommand(QString cmd);
void updateUi(); void updateUi();
void setActiveButton(QString prop);
void sendVolume(); void sendVolume();
void setActiveButton(QString prop); // QWidget interface
protected:
void moveEvent(QMoveEvent *) override;
}; };
} }

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>359</width> <width>359</width>
<height>161</height> <height>170</height>
</rect> </rect>
</property> </property>
<property name="contextMenuPolicy"> <property name="contextMenuPolicy">
@@ -16,105 +16,21 @@
<property name="windowTitle"> <property name="windowTitle">
<string>yremote</string> <string>yremote</string>
</property> </property>
<widget class="QWidget" name="centralWidget"> <property name="autoFillBackground">
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QPushButton" name="btn_onoff">
<property name="text">
<string>On</string>
</property>
</widget>
</item>
<item row="1" column="4">
<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="3" column="4">
<widget class="QLabel" name="lbl_volume">
<property name="font">
<font>
<family>Source Code Pro Medium</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>-400</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Address:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="4">
<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> <bool>false</bool>
</property> </property
<property name="notchTarget"> ><widget class="QWidget" name="centralWidget">
<double>10.000000000000000</double> <layout class="QGridLayout" name="gridLayout">
</property>
<property name="notchesVisible">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" rowspan="2" colspan="3"> <item row="2" column="0" rowspan="2" colspan="3">
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Input</string> <string>Input</string>
</property> </property>
<property name="alignment">
<set>Qt::AlignBottom|Qt::AlignHCenter</set>
</property>
<property name="flat"> <property name="flat">
<bool>true</bool> <bool>false</bool>
</property> </property>
<widget class="QPushButton" name="btn_hdmi1"> <widget class="QPushButton" name="btn_hdmi1">
<property name="geometry"> <property name="geometry">
@@ -125,9 +41,15 @@
<height>21</height> <height>21</height>
</rect> </rect>
</property> </property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text"> <property name="text">
<string>HDMI 1</string> <string>HDMI 1</string>
</property> </property>
<property name="flat">
<bool>false</bool>
</property>
<property name="input" stdset="0"> <property name="input" stdset="0">
<string>HDMI1</string> <string>HDMI1</string>
</property> </property>
@@ -214,6 +136,108 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item row="1" column="2">
<widget class="QLabel" name="label">
<property name="text">
<string>Address:</string>
</property>
</widget>
</item>
<item row="2" column="4">
<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="notchTarget">
<double>10.000000000000000</double>
</property>
<property name="notchesVisible">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="btn_onoff">
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string>On</string>
</property>
<property name="flat">
<bool>false</bool>
</property>
</widget>
</item>
<item row="1" column="4">
<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="3" column="4">
<widget class="QLabel" name="lbl_volume">
<property name="font">
<font>
<family>Source Code Pro Medium</family>
<pointsize>16</pointsize>
</font>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="text">
<string>-400</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</widget> </widget>
</widget> </widget>

5
resources.qrc Normal file
View File

@@ -0,0 +1,5 @@
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>style.css</file>
</qresource>
</RCC>

43
style.css Normal file
View File

@@ -0,0 +1,43 @@
QMainWindow {
background-color: #404040;
border-color: #edf2f4;
}
QPushButton {
background-color: #404040;
color: #edf2f4;
}
QPushButton:hover {
border: 1px solid #0077fd;
}
QLineEdit {
background-color: #404040;
color: #edf2f4;
border: 1px solid #0077fd;
}
QLineEdit:hover {
border: 1px solid #edf2f4;
}
QLabel {
color: #edf2f4;
}
QGroupBox {
color: #edf2f4;
border: 1px solid #0077fd;
margin-top: 5px;
}
QGroupBox::title {
subcontrol-origin: margin;
left: 5px;
padding: 0px 5px 0px 5px;
}
QLabel#lbl_volume:hover {
border: 1px solid #0077fd;
}

View File

@@ -33,3 +33,7 @@ HEADERS += \
FORMS += \ FORMS += \
mainwindow.ui mainwindow.ui
RESOURCES = resources.qrc \
resources.qrc