mirror of https://github.com/nymea/nymea.git
working on add device and syncing the devices
parent
a37f282f6f
commit
ea11aae5c9
|
|
@ -3,7 +3,7 @@ folder_01.source = qml/hive_client
|
|||
folder_01.target = qml
|
||||
DEPLOYMENTFOLDERS = folder_01
|
||||
|
||||
QT += core qml quick
|
||||
QT += core qml quick declarative
|
||||
|
||||
|
||||
# Additional import path used to resolve QML modules in Creator's code model
|
||||
|
|
|
|||
|
|
@ -1,29 +1,28 @@
|
|||
#include "hiveclientcore.h"
|
||||
#include <QtQml>
|
||||
#include <QQmlEngine>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickWindow>
|
||||
|
||||
HiveClientCore::HiveClientCore(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
m_id = 0;
|
||||
|
||||
m_settings = new Settings(this);
|
||||
m_client = new Client(this);
|
||||
|
||||
// QML Typs
|
||||
qmlRegisterType<Settings>("hive",1,0,"Settings");
|
||||
|
||||
// QML application window
|
||||
m_engine = new QQmlApplicationEngine(this);
|
||||
m_engine->load(QUrl("qml/hive_client/main.qml"));
|
||||
|
||||
m_engine->rootContext()->setContextProperty("client", m_client);
|
||||
m_engine->rootContext()->setContextProperty("settings", m_settings);
|
||||
|
||||
topLevel = m_engine->rootObjects().value(0);
|
||||
QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
|
||||
window->show();
|
||||
|
||||
connect(m_client,SIGNAL(connected()),this,SLOT(onConnected()));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QQmlApplicationEngine>
|
||||
#include <QQuickWindow>
|
||||
|
||||
#include "client.h"
|
||||
#include "settings.h"
|
||||
|
|
@ -16,7 +15,7 @@ public:
|
|||
|
||||
private:
|
||||
Client *m_client;
|
||||
Settings *m_settings;
|
||||
//Settings *m_settings;
|
||||
|
||||
QQmlApplicationEngine *m_engine;
|
||||
QObject *topLevel;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,115 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Layouts 1.0
|
||||
|
||||
Component {
|
||||
|
||||
Rectangle{
|
||||
anchors.fill: parent
|
||||
|
||||
ColumnLayout{
|
||||
id: addDeviceColumn
|
||||
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
|
||||
GroupBox{
|
||||
id: nameGroupBox
|
||||
title: "Name"
|
||||
|
||||
Row{
|
||||
spacing: 5
|
||||
Text{
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
text: "Name:"
|
||||
}
|
||||
|
||||
TextField{
|
||||
id: nameText
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
placeholderText: "Device Name"
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
GroupBox{
|
||||
id: deviceTypeGroupBox
|
||||
title: "Device Type"
|
||||
|
||||
ComboBox {
|
||||
id: deviceComboBox
|
||||
model: ["actor","sensor"]
|
||||
}
|
||||
}
|
||||
GroupBox{
|
||||
id: communicationTypeGroupBox
|
||||
title: "Communication Type"
|
||||
|
||||
ComboBox {
|
||||
id: communicationTypeComboBox
|
||||
model: ["RC433","RC868","ZigBee"]
|
||||
}
|
||||
}
|
||||
GroupBox{
|
||||
id: linecodeGroupBox
|
||||
title: "Linecode"
|
||||
visible: communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433" ? true : false
|
||||
|
||||
ComboBox {
|
||||
id: linecodeComboBox
|
||||
model: ["Switch","Light","Unicode","Manchester","Differential Manchester"]
|
||||
}
|
||||
}
|
||||
GroupBox{
|
||||
id: switchGroupBox
|
||||
title: "Switchsettings"
|
||||
visible: (linecodeComboBox.currentText == "Switch") && (communicationTypeComboBox.currentText == "RC868" || communicationTypeComboBox.currentText == "RC433") ? true : false
|
||||
|
||||
RowLayout{
|
||||
GridLayout{
|
||||
columns: 6
|
||||
Label{
|
||||
text: "1"
|
||||
}
|
||||
Label{
|
||||
text: "2"
|
||||
}
|
||||
Label{
|
||||
text: "3"
|
||||
}
|
||||
Label{
|
||||
text: "4"
|
||||
}
|
||||
Label{
|
||||
text: "5"
|
||||
}
|
||||
Label{
|
||||
text: "6"
|
||||
}
|
||||
CheckBox{
|
||||
id: channel1
|
||||
}
|
||||
CheckBox{
|
||||
id: channel2
|
||||
}
|
||||
CheckBox{
|
||||
id: channel3
|
||||
}
|
||||
CheckBox{
|
||||
id: channel4
|
||||
}
|
||||
CheckBox{
|
||||
id: channel5
|
||||
}
|
||||
CheckBox{
|
||||
id: channel6
|
||||
}
|
||||
}
|
||||
ComboBox {
|
||||
id: switchComboBox
|
||||
model: ["A","B","C","D","E"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Layouts 1.0
|
||||
|
||||
Component {
|
||||
Rectangle{
|
||||
anchors.fill: parent
|
||||
|
||||
GroupBox {
|
||||
id: connectionGroupBox
|
||||
anchors.centerIn: parent
|
||||
|
||||
title: "Connection"
|
||||
|
||||
RowLayout{
|
||||
anchors.fill: parent
|
||||
Button{
|
||||
id: connectButton
|
||||
text: "Connect"
|
||||
onClicked: {
|
||||
settings.ipaddress = ipTextInput.text
|
||||
settings.port = portTextInput.text
|
||||
client.connectToHost(ipTextInput.text,portTextInput.text)
|
||||
}
|
||||
}
|
||||
Text {
|
||||
id: ipLable
|
||||
text: "IP:"
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
TextField {
|
||||
id: ipTextInput
|
||||
text: settings.ipaddress
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
font.pointSize: 9
|
||||
}
|
||||
Text {
|
||||
id: portLable
|
||||
text: "Port:"
|
||||
wrapMode: Text.NoWrap
|
||||
verticalAlignment: Text.AlignTop
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
TextField {
|
||||
id: portTextInput
|
||||
text: settings.port
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
font.pointSize: 9
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
import QtQuick 2.0
|
||||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Layouts 1.0
|
||||
|
||||
Component {
|
||||
|
||||
Rectangle{
|
||||
anchors.fill: parent
|
||||
|
||||
Column{
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: 30
|
||||
|
||||
Rectangle{
|
||||
id: addDeviceButton
|
||||
width: 150
|
||||
height: 70
|
||||
color: "#c8c8c8"
|
||||
border.color: "black"
|
||||
radius: 10
|
||||
Text{
|
||||
anchors.centerIn: parent
|
||||
text: "Add Device"
|
||||
}
|
||||
MouseArea{
|
||||
id: addDeviceButtonMousArea
|
||||
anchors.fill: parent
|
||||
onPressed: addDeviceButton.color = "steelblue"
|
||||
onReleased: addDeviceButton.color = "#c8c8c8"
|
||||
onClicked: stackView.push(addDevicePage)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -2,6 +2,8 @@ import QtQuick 2.0
|
|||
import QtQuick.Controls 1.0
|
||||
import QtQuick.Layouts 1.0
|
||||
|
||||
import hive 1.0
|
||||
|
||||
ApplicationWindow{
|
||||
id: mainWindow
|
||||
menuBar: MenuBar{
|
||||
|
|
@ -13,6 +15,11 @@ ApplicationWindow{
|
|||
shortcut: "Ctrl+Q"
|
||||
onTriggered: mainWindow.close()
|
||||
}
|
||||
MenuItem {
|
||||
text: "Disconnect"
|
||||
shortcut: "Ctrl+D"
|
||||
onTriggered: client.disconnectFromHost()
|
||||
}
|
||||
}
|
||||
}
|
||||
statusBar: StatusBar {
|
||||
|
|
@ -25,79 +32,41 @@ ApplicationWindow{
|
|||
width: 600
|
||||
height: 500
|
||||
|
||||
StackView {
|
||||
id: stackView
|
||||
anchors.fill: parent
|
||||
initialItem: connectionPage
|
||||
}
|
||||
|
||||
GroupBox {
|
||||
id: connectionGroupBox
|
||||
anchors.right: parent.right
|
||||
anchors.left: parent.left
|
||||
anchors.margins: 20
|
||||
title: "Connection"
|
||||
|
||||
RowLayout{
|
||||
anchors.fill: parent
|
||||
Button{
|
||||
id: connectButton
|
||||
text: "Connect"
|
||||
onClicked: {
|
||||
settings.setIPaddress(ipTextInput.text)
|
||||
settings.setPort(portTextInput.text)
|
||||
client.connectToHost(ipTextInput.text,portTextInput.text)
|
||||
}
|
||||
}
|
||||
Text {
|
||||
id: ipLable
|
||||
text: "IP:"
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
TextField {
|
||||
id: ipTextInput
|
||||
text: "10.10.10.40"
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
font.pointSize: 9
|
||||
}
|
||||
Text {
|
||||
id: portLable
|
||||
text: "Port:"
|
||||
wrapMode: Text.NoWrap
|
||||
verticalAlignment: Text.AlignTop
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
}
|
||||
TextField {
|
||||
id: portTextInput
|
||||
text: "1234"
|
||||
horizontalAlignment: TextInput.AlignHCenter
|
||||
font.pointSize: 9
|
||||
Connections{
|
||||
target: client
|
||||
onConnectionChanged:{
|
||||
print("connection changed",client.isConnected)
|
||||
if(client.isConnected){
|
||||
stackView.push(mainPage)
|
||||
}else{
|
||||
stackView.clear()
|
||||
stackView.push(connectionPage)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TabView{
|
||||
id: tabView
|
||||
anchors.right: parent.right
|
||||
anchors.rightMargin: 20
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 20
|
||||
anchors.top: connectionGroupBox.bottom
|
||||
anchors.bottom: statusBar.top
|
||||
|
||||
Tab{
|
||||
id: actorTab
|
||||
title: "Actor"
|
||||
|
||||
}
|
||||
Tab{
|
||||
id: sensorTab
|
||||
title: "Sensor"
|
||||
}
|
||||
Tab{
|
||||
id: ruleTab
|
||||
title: "Rules"
|
||||
}
|
||||
Tab{
|
||||
id: settingsTab
|
||||
title: "Settings"
|
||||
}
|
||||
Settings{
|
||||
id: settings
|
||||
}
|
||||
|
||||
ConnectionPage{
|
||||
id: connectionPage
|
||||
}
|
||||
|
||||
MainPage{
|
||||
id: mainPage
|
||||
}
|
||||
|
||||
AddDevicePage{
|
||||
id: addDevicePage
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -4,28 +4,31 @@
|
|||
Settings::Settings(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
m_settings = new QSettings(QString(),"hiveClient",this);
|
||||
}
|
||||
|
||||
QString Settings::ipaddress()
|
||||
QString Settings::ipaddress() const
|
||||
{
|
||||
return m_settings->value("server","10.10.10.40").toString();
|
||||
QSettings settings("hive");
|
||||
return settings.value("server","10.10.10.40").toString();
|
||||
}
|
||||
|
||||
void Settings::setIPaddress(QString ipaddress)
|
||||
{
|
||||
m_settings->setValue("server",ipaddress);
|
||||
QSettings settings("hive");
|
||||
settings.setValue("server",ipaddress);
|
||||
emit ipaddressChanged();
|
||||
}
|
||||
|
||||
QString Settings::port()
|
||||
int Settings::port() const
|
||||
{
|
||||
return m_settings->value("port","1234").toString();
|
||||
QSettings settings("hive");
|
||||
return settings.value("port","1234").toInt();
|
||||
}
|
||||
|
||||
void Settings::setPort(QString port)
|
||||
void Settings::setPort(int port)
|
||||
{
|
||||
m_settings->setValue("port",port);
|
||||
QSettings settings("hive");
|
||||
settings.setValue("port",port);
|
||||
emit ipaddressChanged();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,25 +7,26 @@
|
|||
class Settings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString ipaddress READ ipaddress WRITE setIPaddress NOTIFY ipaddressChanged)
|
||||
Q_PROPERTY(int port READ port WRITE setPort NOTIFY portChanged)
|
||||
|
||||
public:
|
||||
explicit Settings(QObject *parent = 0);
|
||||
|
||||
QString ipaddress() const;
|
||||
void setIPaddress(QString ipaddress);
|
||||
|
||||
int port() const;
|
||||
void setPort(int port);
|
||||
|
||||
private:
|
||||
QSettings* m_settings;
|
||||
|
||||
signals:
|
||||
void ipaddressChanged();
|
||||
void portChanged();
|
||||
|
||||
public slots:
|
||||
QString ipaddress();
|
||||
QString port();
|
||||
|
||||
void setIPaddress(QString ipaddress);
|
||||
void setPort(QString port);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,10 +6,15 @@ Client::Client(QObject *parent) :
|
|||
QObject(parent)
|
||||
{
|
||||
m_tcpSocket = new QTcpSocket(this);
|
||||
|
||||
m_connectionStatus = false;
|
||||
connect(m_tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(connectionError(QAbstractSocket::SocketError)));
|
||||
connect(m_tcpSocket, SIGNAL(connected()),this, SLOT(connectedToHost()));
|
||||
connect(m_tcpSocket, SIGNAL(connected()),this, SLOT(connected()));
|
||||
connect(m_tcpSocket, SIGNAL(disconnected()),this, SLOT(disconneted()));
|
||||
}
|
||||
|
||||
bool Client::isConnected()
|
||||
{
|
||||
return m_connectionStatus;
|
||||
}
|
||||
|
||||
void Client::connectionError(QAbstractSocket::SocketError error)
|
||||
|
|
@ -30,10 +35,18 @@ void Client::readData()
|
|||
}
|
||||
}
|
||||
|
||||
void Client::connectedToHost()
|
||||
void Client::connected()
|
||||
{
|
||||
qDebug() << "connected to hive server";
|
||||
emit connected();
|
||||
m_connectionStatus = true;
|
||||
emit connectionChanged();
|
||||
}
|
||||
|
||||
void Client::disconneted()
|
||||
{
|
||||
qDebug() << "disconnect from hive server";
|
||||
m_connectionStatus = false;
|
||||
emit connectionChanged();
|
||||
}
|
||||
|
||||
void Client::connectToHost(QString ipAddress, QString port)
|
||||
|
|
|
|||
|
|
@ -8,26 +8,32 @@
|
|||
class Client : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(bool isConnected READ isConnected NOTIFY connectionChanged)
|
||||
|
||||
|
||||
public:
|
||||
explicit Client(QObject *parent = 0);
|
||||
|
||||
bool isConnected();
|
||||
|
||||
|
||||
private:
|
||||
QTcpSocket *m_tcpSocket;
|
||||
QString m_tcpBuffer;
|
||||
|
||||
bool m_connectionStatus;
|
||||
|
||||
|
||||
signals:
|
||||
void connected();
|
||||
void jsonDataAvailable(const QByteArray &data);
|
||||
void connectionChanged();
|
||||
|
||||
|
||||
private slots:
|
||||
void connectionError(QAbstractSocket::SocketError error);
|
||||
void readData();
|
||||
void connectedToHost();
|
||||
|
||||
void connected();
|
||||
void disconneted();
|
||||
|
||||
public slots:
|
||||
void connectToHost(QString ipAddress, QString port);
|
||||
void disconnectFromHost();
|
||||
|
|
|
|||
|
|
@ -20,8 +20,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
public slots:
|
||||
|
|
|
|||
|
|
@ -8,8 +8,7 @@ HiveCore::HiveCore(QObject *parent) :
|
|||
m_server = new Server(this);
|
||||
m_server->startServer();
|
||||
|
||||
m_deviceManager = new DeviceManager(this);
|
||||
m_deviceManager->getDevices();
|
||||
//m_deviceManager = new DeviceManager(this);
|
||||
|
||||
m_jsonHandler = new JsonHandler(this);
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ private:
|
|||
Server *m_server;
|
||||
//RadioReciver *m_reciver;
|
||||
//RadioSender *m_sender;
|
||||
//DeviceManager *m_deviceManager;
|
||||
DeviceManager *m_deviceManager;
|
||||
JsonHandler *m_jsonHandler;
|
||||
|
||||
signals:
|
||||
|
|
|
|||
Loading…
Reference in New Issue