Merge lp:~vicamo/qtubuntu-sensors/add-test-haptics into lp:qtubuntu-sensors

Proposed by You-Sheng Yang
Status: Needs review
Proposed branch: lp:~vicamo/qtubuntu-sensors/add-test-haptics
Merge into: lp:qtubuntu-sensors
Diff against target: 194 lines (+162/-1)
5 files modified
debian/control (+9/-0)
debian/qtubuntu-sensors-tests.install (+1/-0)
debian/qtubuntu-sensors.install (+1/-0)
plugins/feedback/CMakeLists.txt (+19/-1)
plugins/feedback/test_haptics.cpp (+132/-0)
To merge this branch: bzr merge lp:~vicamo/qtubuntu-sensors/add-test-haptics
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+301030@code.launchpad.net

Commit message

feedback: add test tool test_haptics

* add new package qtubuntu-sensors-tests, which contains test tool test_haptics for testing QFeedbackHapticsEffect.

Description of the change

Add test tool test_haptics. This tool depends only QtCore/QtFeedback module and is a convenient tool to verify if the vibration software stack really works during the porting process.

To post a comment you must log in.

Unmerged revisions

93. By You-Sheng Yang

feedback: add test tool test_haptics

* add new package qtubuntu-sensors-tests, which contains test tool
  test_haptics for testing QFeedbackHapticsEffect.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2016-05-17 16:22:12 +0000
3+++ debian/control 2016-07-25 03:22:27 +0000
4@@ -32,3 +32,12 @@
5 Replaces: libqt5location5-plugins (<< 5.0~git20130805-0ubuntu4)
6 Description: QtSensors plugins for Android sensors
7 QtSensors plugins for the qtubuntu (hybris) sensors backend
8+
9+Package: qtubuntu-sensors-tests
10+Architecture: i386 amd64 armhf arm64
11+Pre-Depends: ${misc:Pre-Depends},
12+Multi-Arch: same
13+Depends: ${misc:Depends},
14+ ${shlibs:Depends},
15+Description: QtSensors test utilities
16+ QtSensors test utilities for the qtubuntu (hybris) sensors backend
17
18=== added file 'debian/qtubuntu-sensors-tests.install'
19--- debian/qtubuntu-sensors-tests.install 1970-01-01 00:00:00 +0000
20+++ debian/qtubuntu-sensors-tests.install 2016-07-25 03:22:27 +0000
21@@ -0,0 +1,1 @@
22+usr/bin/test_haptics
23
24=== modified file 'debian/qtubuntu-sensors.install'
25--- debian/qtubuntu-sensors.install 2014-01-07 12:45:47 +0000
26+++ debian/qtubuntu-sensors.install 2016-07-25 03:22:27 +0000
27@@ -1,1 +1,2 @@
28+usr/lib/*
29 data/Sensors.conf /etc/xdg/QtProject
30
31=== modified file 'plugins/feedback/CMakeLists.txt'
32--- plugins/feedback/CMakeLists.txt 2014-06-24 12:17:06 +0000
33+++ plugins/feedback/CMakeLists.txt 2016-07-25 03:22:27 +0000
34@@ -39,4 +39,22 @@
35 TARGETS qtfeedback_ubuntu
36 LIBRARY DESTINATION ${PLUGIN_INSTALL_LOCATION})
37
38-
39+add_executable(
40+ test_haptics
41+
42+ test_haptics.cpp
43+)
44+
45+qt5_use_modules(test_haptics Core Feedback)
46+
47+target_link_libraries(
48+ test_haptics
49+
50+ Qt5::Core
51+ Qt5::Feedback
52+)
53+
54+install(
55+ TARGETS test_haptics
56+ RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
57+)
58
59=== added file 'plugins/feedback/test_haptics.cpp'
60--- plugins/feedback/test_haptics.cpp 1970-01-01 00:00:00 +0000
61+++ plugins/feedback/test_haptics.cpp 2016-07-25 03:22:27 +0000
62@@ -0,0 +1,132 @@
63+/*
64+ * Copyright 2016 Canonical Ltd.
65+ *
66+ * This program is free software; you can redistribute it and/or modify
67+ * it under the terms of the GNU Lesser General Public License as published by
68+ * the Free Software Foundation; version 3.
69+ *
70+ * This program is distributed in the hope that it will be useful,
71+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
72+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73+ * GNU Lesser General Public License for more details.
74+ *
75+ * You should have received a copy of the GNU Lesser General Public License
76+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
77+ *
78+ * Author: Christian Dywan <christian.dywan@canonical.com>
79+ */
80+
81+#include <QCommandLineParser>
82+#include <QCoreApplication>
83+#include <QDebug>
84+#include <QFeedbackHapticsEffect>
85+#include <QTimer>
86+
87+void dumpEffect(const QFeedbackHapticsEffect &effect)
88+{
89+ qDebug() << "\tstate: " << effect.state();
90+ qDebug() << "\tduration: " << effect.duration();
91+ qDebug() << "\tintensity: " << effect.intensity();
92+ qDebug() << "\tattack time: " << effect.attackTime();
93+ qDebug() << "\tattack intensity: " << effect.attackIntensity();
94+ qDebug() << "\tfade time: " << effect.fadeTime();
95+ qDebug() << "\tfade intensity: " << effect.fadeIntensity();
96+ qDebug() << "\tperiod: " << effect.period();
97+}
98+
99+int main(int argc, char *argv[])
100+{
101+ QCoreApplication app(argc, argv);
102+ QCoreApplication::setApplicationName("test_haptics");
103+
104+ QCommandLineParser parser;
105+ parser.setApplicationDescription("Test QtFeedbackHaptics");
106+ parser.addHelpOption();
107+
108+ // QFeedbackHapticsEffect::Duration
109+ QCommandLineOption durationOption(QStringList() << "d" << "duration",
110+ QCoreApplication::translate("main", "Set effect duration <duration>."),
111+ QCoreApplication::translate("main", "duration"));
112+ parser.addOption(durationOption);
113+
114+ // QFeedbackHapticsEffect::Intensity
115+ QCommandLineOption intensityOption(QStringList() << "i" << "intensity",
116+ QCoreApplication::translate("main", "Set effect intensity <intensity>."),
117+ QCoreApplication::translate("main", "intensity"));
118+ parser.addOption(intensityOption);
119+
120+ // QFeedbackHapticsEffect::attackTime
121+ QCommandLineOption attackTimeOption(QStringList() << "a" << "attack-time",
122+ QCoreApplication::translate("main", "Set effect attack time <attacktime>."),
123+ QCoreApplication::translate("main", "attacktime"));
124+ parser.addOption(attackTimeOption);
125+
126+ // QFeedbackHapticsEffect::attackIntensity
127+ QCommandLineOption attackIntensityOption(QStringList() << "n" << "attack-intensity",
128+ QCoreApplication::translate("main", "Set effect attack intensity <attackintensity>."),
129+ QCoreApplication::translate("main", "attackintensity"));
130+ parser.addOption(attackIntensityOption);
131+
132+ // QFeedbackHapticsEffect::fadeTime
133+ QCommandLineOption fadeTimeOption(QStringList() << "f" << "fade-time",
134+ QCoreApplication::translate("main", "Set effect fade time <fadetime>."),
135+ QCoreApplication::translate("main", "fadetime"));
136+ parser.addOption(fadeTimeOption);
137+
138+ // QFeedbackHapticsEffect::fadeIntensity
139+ QCommandLineOption fadeIntensityOption(QStringList() << "t" << "fade-intensity",
140+ QCoreApplication::translate("main", "Set effect fade intensity <fadeintensity>."),
141+ QCoreApplication::translate("main", "fadeintensity"));
142+ parser.addOption(fadeIntensityOption);
143+
144+ // QFeedbackHapticsEffect::period
145+ QCommandLineOption periodOption(QStringList() << "p" << "period",
146+ QCoreApplication::translate("main", "Set effect period <period>."),
147+ QCoreApplication::translate("main", "period"));
148+ parser.addOption(periodOption);
149+
150+ parser.process(app);
151+
152+ QFeedbackHapticsEffect effect;
153+ QObject::connect(&effect, &QFeedbackEffect::error, [&](QFeedbackEffect::ErrorType error) {
154+ qDebug() << "Receiving QFeedbackEffect error: " << error;
155+ app.quit();
156+ });
157+ QObject::connect(&effect, &QFeedbackEffect::stateChanged, [&]() {
158+ qDebug() << "QFeedbackEffect state changed: " << effect.state();
159+ });
160+
161+ qDebug() << "QFeedbackHapticsEffect default values:";
162+ dumpEffect(effect);
163+
164+ if (parser.isSet(durationOption))
165+ effect.setDuration(parser.value(durationOption).toInt());
166+ if (parser.isSet(intensityOption))
167+ effect.setIntensity(parser.value(intensityOption).toFloat());
168+ if (parser.isSet(attackTimeOption))
169+ effect.setAttackTime(parser.value(attackTimeOption).toInt());
170+ if (parser.isSet(attackIntensityOption))
171+ effect.setAttackIntensity(parser.value(attackIntensityOption).toFloat());
172+ if (parser.isSet(fadeTimeOption))
173+ effect.setFadeTime(parser.value(fadeTimeOption).toInt());
174+ if (parser.isSet(fadeIntensityOption))
175+ effect.setFadeIntensity(parser.value(fadeIntensityOption).toFloat());
176+ if (parser.isSet(periodOption))
177+ effect.setPeriod(parser.value(periodOption).toInt());
178+
179+ qDebug() << "QFeedbackHapticsEffect current values:";
180+ dumpEffect(effect);
181+
182+ effect.start();
183+
184+ // Periodical timer to quit program when state transits to STOPPED.
185+ QTimer timer;
186+ QObject::connect(&timer, &QTimer::timeout, [&]() {
187+ if (effect.state() == QFeedbackEffect::Stopped)
188+ app.quit();
189+ });
190+ timer.setInterval(100);
191+ timer.start();
192+
193+ return app.exec();
194+}

Subscribers

People subscribed via source and target branches