summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAndrew O'Doherty <andrew.odoherty@qt.io>2018-03-12 15:59:46 +0100
committerKarsten Heimrich <karsten.heimrich@qt.io>2018-04-17 08:52:56 +0000
commitb1fe34fb7f21e71e748958e05e78982417fc8971 (patch)
tree66be94871675907c70e65cfcd22053d60441e7ae /examples
parent842cab0b75d2a29c94ad9d47ca0859cdc6480484 (diff)
Apply fix after refactoring and small code cleanup
Change-Id: I20a0ea1814f2c084c0782cfbb4e734b06cb49bea Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/knx/demo/demo.pro20
-rw-r--r--examples/knx/demo/demodatapoint.cpp12
-rw-r--r--examples/knx/demo/demodatapoint.h3
-rw-r--r--examples/knx/demo/qmlknxdemo.cpp98
-rw-r--r--examples/knx/demo/qmlknxdemo.h3
5 files changed, 54 insertions, 82 deletions
diff --git a/examples/knx/demo/demo.pro b/examples/knx/demo/demo.pro
index d69cb4d..c1e5401 100644
--- a/examples/knx/demo/demo.pro
+++ b/examples/knx/demo/demo.pro
@@ -30,15 +30,17 @@ QML_DESIGNER_IMPORT_PATH =
target.path = $$[QT_INSTALL_EXAMPLES]/knx/demo
INSTALLS += target
-DISTFILES += \
- android/AndroidManifest.xml \
- android/gradle/wrapper/gradle-wrapper.jar \
- android/gradlew \
- android/res/values/libs.xml \
- android/build.gradle \
- android/gradle/wrapper/gradle-wrapper.properties \
- android/gradlew.bat \
- boardModel.qml
+android {
+ DISTFILES += \
+ android/AndroidManifest.xml \
+ android/gradle/wrapper/gradle-wrapper.jar \
+ android/gradlew \
+ android/res/values/libs.xml \
+ android/build.gradle \
+ android/gradle/wrapper/gradle-wrapper.properties \
+ android/gradlew.bat \
+ boardModel.qml
+}
HEADERS += \
qmlknxdemo.h \
diff --git a/examples/knx/demo/demodatapoint.cpp b/examples/knx/demo/demodatapoint.cpp
index 21a1d05..25aa618 100644
--- a/examples/knx/demo/demodatapoint.cpp
+++ b/examples/knx/demo/demodatapoint.cpp
@@ -52,7 +52,6 @@
#include <QtCore/QTimer>
#include <QtGui/QColor>
-#include <QtKnx/QKnx1Bit>
#include <QtKnx/QKnxTpdu>
#include <QtKnx/QKnxTpduFactory>
#include <QtKnx/QKnxLinkLayerFrame>
@@ -62,23 +61,26 @@ const QKnxByteArray DemoDataPoint::BytesOff { 0x00 };
bool DemoSwitchDataPoint::updateDataPointState(const QKnxLinkLayerFrame &frame)
{
- m_state = frame.serviceInformation().endsWith(1);
+ m_switch.setBytes(frame.tpdu().data(), 0, 1);
return true;
}
void DemoSwitchDataPoint::uiToggle()
{
- m_state = !m_state;
+ if (isOn())
+ m_switch.setValue(QKnxSwitch::State::Off);
+ else
+ m_switch.setValue(QKnxSwitch::State::On);
}
bool DemoSwitchDataPoint::isOn() const
{
- return m_state;
+ return m_switch.value() == QKnxSwitch::State::On;
}
QKnxByteArray DemoSwitchDataPoint::bytes() const
{
- if (m_state)
+ if (isOn())
return DemoDataPoint::BytesOn;
return DemoDataPoint::BytesOff;
}
diff --git a/examples/knx/demo/demodatapoint.h b/examples/knx/demo/demodatapoint.h
index 62c19d6..1810203 100644
--- a/examples/knx/demo/demodatapoint.h
+++ b/examples/knx/demo/demodatapoint.h
@@ -54,6 +54,7 @@
#include <QtCore/QTimer>
#include <QtGui/QColor>
#include <QtKnx/QKnxLinkLayerFrame>
+#include <QtKnx/QKnx1Bit>
class DemoDataPoint
{
@@ -86,7 +87,7 @@ public:
bool isOn() const;
private:
- bool m_state;
+ QKnxSwitch m_switch;
};
class DemoColorLed : public QObject, public DemoDataPoint
diff --git a/examples/knx/demo/qmlknxdemo.cpp b/examples/knx/demo/qmlknxdemo.cpp
index 368ae32..af046e5 100644
--- a/examples/knx/demo/qmlknxdemo.cpp
+++ b/examples/knx/demo/qmlknxdemo.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -53,9 +53,7 @@
#include "utils.h"
#include <QtCore/QString>
-#include <QtGui/QColor>
#include <QtKnx/QKnxAddress>
-#include <QtNetwork/QNetworkAddressEntry>
#include <QtNetwork/QNetworkInterface>
namespace {
@@ -92,43 +90,36 @@ void QmlKnxDemo::toggleLight(int light)
void QmlKnxDemo::colorSwitch(double value)
{
QColor colorAtStart = colorState;
- if (value < (sliderSectionSize / 2)
- && colorState != Qt::black)
+ if (value < (sliderSectionSize / 2) && colorState != Qt::black) {
colorState = Qt::black;
-
- else if ((value > (sliderSectionSize / 2))
- && value < (3 * sliderSectionSize / 2)
- && (colorState != Qt::white))
- colorState = Qt::white;
-
- else if ((value > (3 * sliderSectionSize / 2))
- && value < (5 * sliderSectionSize / 2)
- && (colorState != Qt::red))
- colorState = Qt::red;
-
- else if ((value > (5 * sliderSectionSize / 2))
- && value < (7 * sliderSectionSize / 2)
- && (colorState != Qt::magenta))
- colorState = Qt::magenta;
-
- else if ((value > (7 * sliderSectionSize / 2))
- && value < (9 * sliderSectionSize / 2)
- && (colorState != Qt::blue))
- colorState = Qt::blue;
-
- else if ((value > (9 * sliderSectionSize / 2))
- && value < (11 * sliderSectionSize / 2)
- && (colorState != Qt::cyan))
- colorState = Qt::cyan;
-
- else if (value > (11 * sliderSectionSize / 2)
- && value < (13 * sliderSectionSize / 2)
- && (colorState != Qt::green))
- colorState = Qt::green;
-
- else if (value > ((6 * sliderSectionSize) + (sliderSectionSize / 2))
- && (colorState != Qt::yellow))
- colorState = Qt::yellow;
+ } else if ((value > (sliderSectionSize / 2))
+ && value < (3 * sliderSectionSize / 2)
+ && (colorState != Qt::white)) {
+ colorState = Qt::white;
+ } else if ((value > (3 * sliderSectionSize / 2))
+ && value < (5 * sliderSectionSize / 2)
+ && (colorState != Qt::red)) {
+ colorState = Qt::red;
+ } else if ((value > (5 * sliderSectionSize / 2))
+ && value < (7 * sliderSectionSize / 2)
+ && (colorState != Qt::magenta)) {
+ colorState = Qt::magenta;
+ } else if ((value > (7 * sliderSectionSize / 2))
+ && value < (9 * sliderSectionSize / 2)
+ && (colorState != Qt::blue)) {
+ colorState = Qt::blue;
+ } else if ((value > (9 * sliderSectionSize / 2))
+ && value < (11 * sliderSectionSize / 2)
+ && (colorState != Qt::cyan)) {
+ colorState = Qt::cyan;
+ } else if (value > (11 * sliderSectionSize / 2)
+ && value < (13 * sliderSectionSize / 2)
+ && (colorState != Qt::green)) {
+ colorState = Qt::green;
+ } else if (value > ((6 * sliderSectionSize) + (sliderSectionSize / 2))
+ && (colorState != Qt::yellow)) {
+ colorState = Qt::yellow;
+ }
if (colorAtStart != colorState) {
if (auto led = m_etsBoard.getColorLed()) {
@@ -149,17 +140,9 @@ void QmlKnxDemo::toggleMiddleRight()
void QmlKnxDemo::toggleMiddleLeft()
{
- auto led = m_etsBoard.getColorLed();
- if (!led)
- return;
-
- if (!led->isOn()) {
+ if (auto led = m_etsBoard.getColorLed()) {
// set green color in dpt by default...
- led->setCurrentColor(QColor(0, 255, 0));
- // send request to ets board
- sendColorLedGroupValueWriteFrames(m_tunnel, led);
- } else {
- led->setCurrentColor(QColor(0, 0, 0));
+ led->setCurrentColor(QColor(0, (!led->isOn() ? 255 : 0), 0));
sendColorLedGroupValueWriteFrames(m_tunnel, led);
}
}
@@ -294,7 +277,7 @@ void QmlKnxTunnel::autoDiscoverKnxServers()
void QmlKnxTunnel::changeIp(const QString &ip, quint16 port)
{
- m_ip = ip;
+ m_ip = QHostAddress(ip);
m_port = port;
m_connection.disconnectFromHost();
}
@@ -326,18 +309,3 @@ void QmlKnxDemo::checkLightStatusOn()
{
initBoard(m_etsBoard, m_tunnel);
}
-
-void QmlKnxDemo::test()
-{
- // red
- QKnxByteArray data { 00, 0xbc, 0xe0, 11, 05, 00, 0x0c, 01, 00, 81 };
- handleFrame(QKnxLinkLayerFrame::fromBytes(data, 0, data.size()));
-
- // blue
- data = { 00, 0xbc, 0xe0, 11, 05, 00, 0x0e, 01, 00, 81 };
- handleFrame(QKnxLinkLayerFrame::fromBytes(data, 0, data.size()));
-
- // green
- data = { 00, 0xbc, 0xe0, 11, 05, 00, 0x0d, 01, 00, 81 };
- handleFrame(QKnxLinkLayerFrame::fromBytes(data, 0, data.size()));
-}
diff --git a/examples/knx/demo/qmlknxdemo.h b/examples/knx/demo/qmlknxdemo.h
index bec2f7f..67e27b2 100644
--- a/examples/knx/demo/qmlknxdemo.h
+++ b/examples/knx/demo/qmlknxdemo.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the Qt Toolkit.
@@ -112,7 +112,6 @@ public:
Q_INVOKABLE void colorSwitch(double value);
Q_INVOKABLE void toggleLight(int light);
- Q_INVOKABLE void test();
Q_INVOKABLE void changeTunnelIp(const QString &ipStr, quint16 port = 3671);
Q_SIGNALS: