qtubuntu-sensors-0.6+16.04.20151127/ 0000755 0000153 0000161 00000000000 12626127552 017304 5 ustar pbuser pbgroup 0000000 0000000 qtubuntu-sensors-0.6+16.04.20151127/data/ 0000755 0000153 0000161 00000000000 12626127552 020215 5 ustar pbuser pbgroup 0000000 0000000 qtubuntu-sensors-0.6+16.04.20151127/data/Sensors.conf 0000644 0000153 0000161 00000000132 12626127204 022506 0 ustar pbuser pbgroup 0000000 0000000 [Default]
QAccelerometer = core.accelerometer
QOrientationSensor = core.orientationsensor
qtubuntu-sensors-0.6+16.04.20151127/CMakeLists.txt 0000644 0000153 0000161 00000002026 12626127204 022036 0 ustar pbuser pbgroup 0000000 0000000 cmake_minimum_required(VERSION 2.8)
project(qtubuntu-sensors)
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
include(GNUInstallDirs)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -Wextra -fPIC -fvisibility=hidden")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -fno-strict-aliasing -fvisibility=hidden -fvisibility-inlines-hidden -pedantic -Wextra")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
option(QTUBUNTU_SENSORS_WERROR "Treat warnings as errors" ON)
if (QTUBUNTU_SENSORS_WERROR)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif(QTUBUNTU_SENSORS_WERROR)
# enable tests with gtest
include(CTest)
set(GTEST_ROOT /usr/src/gtest)
add_subdirectory(${GTEST_ROOT} ${CMAKE_CURRENT_BINARY_DIR}/gtest)
find_package(Threads REQUIRED)
add_definitions(-DQT_PLUGIN)
add_subdirectory(plugins)
add_subdirectory(tests)
qtubuntu-sensors-0.6+16.04.20151127/COPYING 0000644 0000153 0000161 00000016743 12626127204 020344 0 ustar pbuser pbgroup 0000000 0000000 GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007
Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
This version of the GNU Lesser General Public License incorporates
the terms and conditions of version 3 of the GNU General Public
License, supplemented by the additional permissions listed below.
0. Additional Definitions.
As used herein, "this License" refers to version 3 of the GNU Lesser
General Public License, and the "GNU GPL" refers to version 3 of the GNU
General Public License.
"The Library" refers to a covered work governed by this License,
other than an Application or a Combined Work as defined below.
An "Application" is any work that makes use of an interface provided
by the Library, but which is not otherwise based on the Library.
Defining a subclass of a class defined by the Library is deemed a mode
of using an interface provided by the Library.
A "Combined Work" is a work produced by combining or linking an
Application with the Library. The particular version of the Library
with which the Combined Work was made is also called the "Linked
Version".
The "Minimal Corresponding Source" for a Combined Work means the
Corresponding Source for the Combined Work, excluding any source code
for portions of the Combined Work that, considered in isolation, are
based on the Application, and not on the Linked Version.
The "Corresponding Application Code" for a Combined Work means the
object code and/or source code for the Application, including any data
and utility programs needed for reproducing the Combined Work from the
Application, but excluding the System Libraries of the Combined Work.
1. Exception to Section 3 of the GNU GPL.
You may convey a covered work under sections 3 and 4 of this License
without being bound by section 3 of the GNU GPL.
2. Conveying Modified Versions.
If you modify a copy of the Library, and, in your modifications, a
facility refers to a function or data to be supplied by an Application
that uses the facility (other than as an argument passed when the
facility is invoked), then you may convey a copy of the modified
version:
a) under this License, provided that you make a good faith effort to
ensure that, in the event an Application does not supply the
function or data, the facility still operates, and performs
whatever part of its purpose remains meaningful, or
b) under the GNU GPL, with none of the additional permissions of
this License applicable to that copy.
3. Object Code Incorporating Material from Library Header Files.
The object code form of an Application may incorporate material from
a header file that is part of the Library. You may convey such object
code under terms of your choice, provided that, if the incorporated
material is not limited to numerical parameters, data structure
layouts and accessors, or small macros, inline functions and templates
(ten or fewer lines in length), you do both of the following:
a) Give prominent notice with each copy of the object code that the
Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the object code with a copy of the GNU GPL and this license
document.
4. Combined Works.
You may convey a Combined Work under terms of your choice that,
taken together, effectively do not restrict modification of the
portions of the Library contained in the Combined Work and reverse
engineering for debugging such modifications, if you also do each of
the following:
a) Give prominent notice with each copy of the Combined Work that
the Library is used in it and that the Library and its use are
covered by this License.
b) Accompany the Combined Work with a copy of the GNU GPL and this license
document.
c) For a Combined Work that displays copyright notices during
execution, include the copyright notice for the Library among
these notices, as well as a reference directing the user to the
copies of the GNU GPL and this license document.
d) Do one of the following:
0) Convey the Minimal Corresponding Source under the terms of this
License, and the Corresponding Application Code in a form
suitable for, and under terms that permit, the user to
recombine or relink the Application with a modified version of
the Linked Version to produce a modified Combined Work, in the
manner specified by section 6 of the GNU GPL for conveying
Corresponding Source.
1) Use a suitable shared library mechanism for linking with the
Library. A suitable mechanism is one that (a) uses at run time
a copy of the Library already present on the user's computer
system, and (b) will operate properly with a modified version
of the Library that is interface-compatible with the Linked
Version.
e) Provide Installation Information, but only if you would otherwise
be required to provide such information under section 6 of the
GNU GPL, and only to the extent that such information is
necessary to install and execute a modified version of the
Combined Work produced by recombining or relinking the
Application with a modified version of the Linked Version. (If
you use option 4d0, the Installation Information must accompany
the Minimal Corresponding Source and Corresponding Application
Code. If you use option 4d1, you must provide the Installation
Information in the manner specified by section 6 of the GNU GPL
for conveying Corresponding Source.)
5. Combined Libraries.
You may place library facilities that are a work based on the
Library side by side in a single library together with other library
facilities that are not Applications and are not covered by this
License, and convey such a combined library under terms of your
choice, if you do both of the following:
a) Accompany the combined library with a copy of the same work based
on the Library, uncombined with any other library facilities,
conveyed under the terms of this License.
b) Give prominent notice with the combined library that part of it
is a work based on the Library, and explaining where to find the
accompanying uncombined form of the same work.
6. Revised Versions of the GNU Lesser General Public License.
The Free Software Foundation may publish revised and/or new versions
of the GNU Lesser General Public License from time to time. Such new
versions will be similar in spirit to the present version, but may
differ in detail to address new problems or concerns.
Each version is given a distinguishing version number. If the
Library as you received it specifies that a certain numbered version
of the GNU Lesser General Public License "or any later version"
applies to it, you have the option of following the terms and
conditions either of that published version or of any later version
published by the Free Software Foundation. If the Library as you
received it does not specify a version number of the GNU Lesser
General Public License, you may choose any version of the GNU Lesser
General Public License ever published by the Free Software Foundation.
If the Library as you received it specifies that a proxy can decide
whether future versions of the GNU Lesser General Public License shall
apply, that proxy's public statement of acceptance of any version is
permanent authorization for you to choose that version for the
Library.
qtubuntu-sensors-0.6+16.04.20151127/tests/ 0000755 0000153 0000161 00000000000 12626127552 020446 5 ustar pbuser pbgroup 0000000 0000000 qtubuntu-sensors-0.6+16.04.20151127/tests/test_sensor_api.cpp 0000644 0000153 0000161 00000010765 12626127204 024356 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright (C) 2014 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Martin Pitt
*
* This test suite uses the simulated sensor test backend from
* libubuntu-application-api-test1. Please see
* /usr/share/doc/libubuntu-application-api-test1/README.md for how to use it
* and the format of the sensor data files.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
// structures for logging received events from signals
struct AccelEvent {
qreal x, y, z;
chrono::time_point time;
};
struct OrientationEvent {
QOrientationReading::Orientation orientation;
chrono::time_point time;
};
/*******************************************
*
* Tests with real sensor backend
*
*******************************************/
class RealBackendTest : public testing::Test
{
virtual void SetUp()
{
}
};
TESTP_F(RealBackendTest, CreateAccelerometer, {
QAccelerometer sensor;
// connect to the qtubuntu-sensors backend; default is dummy, and there
// does not seem to be a way to use data/Sensors.conf
sensor.setIdentifier("core.accelerometer");
// this can succeed for fail depending on whether the hardware we run this
// on actually exists; but it should never crash
if (sensor.start()) {
EXPECT_EQ(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), true);
EXPECT_EQ(sensor.accelerationMode(), QAccelerometer::Combined);
} else {
EXPECT_NE(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), false);
}
EXPECT_EQ(sensor.identifier(), "core.accelerometer");
})
TESTP_F(RealBackendTest, CreateOrientation, {
QOrientationSensor sensor;
// connect to the qtubuntu-sensors backend; default is dummy, and there
// does not seem to be a way to use data/Sensors.conf
sensor.setIdentifier("core.orientation");
// this can succeed for fail depending on whether the hardware we run this
// on actually exists; but it should never crash
if (sensor.start()) {
EXPECT_EQ(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), true);
} else {
EXPECT_NE(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), false);
}
EXPECT_EQ(sensor.identifier(), "core.orientation");
})
/*******************************************
*
* Tests with default sensor backend
*
*******************************************/
class DefaultBackendTest : public testing::Test
{
virtual void SetUp()
{
}
};
TESTP_F(DefaultBackendTest, CreateAccelerometer, {
QAccelerometer sensor;
// don't set any particular identifier here
// this can succeed for fail depending on whether the hardware we run this
// on actually exists; but it should never crash
if (sensor.start()) {
EXPECT_EQ(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), true);
} else {
EXPECT_NE(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), false);
}
cout << "default backend connected to " << sensor.identifier().constData() << endl;
})
TESTP_F(DefaultBackendTest, CreateOrientation, {
QOrientationSensor sensor;
// don't set any particular identifier here
// this can succeed for fail depending on whether the hardware we run this
// on actually exists; but it should never crash
if (sensor.start()) {
EXPECT_EQ(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), true);
} else {
EXPECT_NE(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), false);
}
cout << "default backend connected to " << sensor.identifier().constData() << endl;
})
qtubuntu-sensors-0.6+16.04.20151127/tests/CMakeLists.txt 0000644 0000153 0000161 00000002240 12626127204 023176 0 ustar pbuser pbgroup 0000000 0000000 find_package(Qt5Core REQUIRED)
find_package(Qt5Sensors REQUIRED)
find_package(PkgConfig REQUIRED)
pkg_check_modules(PROCESS_CPP process-cpp REQUIRED)
#include_directories(${GTEST_ROOT}/src)
include_directories(${PROCESS_CPP_INCLUDE_DIRS})
add_executable(
test_sensor_api
test_sensor_api.cpp
)
target_link_libraries(
test_sensor_api
gtest
gtest_main
${PROCESS_CPP_LIBRARIES}
)
qt5_use_modules(
test_sensor_api
Core
Sensors
)
add_executable(
test_sensor_api_mock
test_sensor_api_mock.cpp
)
target_link_libraries(
test_sensor_api_mock
gtest
gtest_main
${PROCESS_CPP_LIBRARIES}
)
qt5_use_modules(
test_sensor_api_mock
Core
Sensors
)
# we need to call the tests with pointing to the locally built plugins
add_test(
test_sensor_api_mock
# add QT_DEBUG_PLUGINS=1 if plugin isn't loading
env QT_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_BINARY_DIR}/test_sensor_api_mock
)
if(DEFINED ENV{UBUNTU_PLATFORM_API_BACKEND})
add_test(
test_sensor_api
# add QT_DEBUG_PLUGINS=1 if plugin isn't loading
env QT_PLUGIN_PATH=${CMAKE_BINARY_DIR}/plugins ${CMAKE_CURRENT_BINARY_DIR}/test_sensor_api
)
endif()
qtubuntu-sensors-0.6+16.04.20151127/tests/test_sensor_api_mock.cpp 0000644 0000153 0000161 00000021330 12626127204 025355 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright (C) 2014 Canonical Ltd
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Authored by: Martin Pitt
*
* This test suite uses the simulated sensor test backend from
* libubuntu-application-api-test1. Please see
* /usr/share/doc/libubuntu-application-api-test1/README.md for how to use it
* and the format of the sensor data files.
*/
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
// structures for logging received events from signals
struct AccelEvent {
qreal x, y, z;
chrono::time_point time;
};
struct OrientationEvent {
QOrientationReading::Orientation orientation;
chrono::time_point time;
};
/*******************************************
*
* Tests with simulated sensor backend
*
*******************************************/
class SimBackendTest : public testing::Test
{
public:
SimBackendTest()
{
QCoreApplication::setLibraryPaths(QStringList("../plugins/"));
accel_sensor = new QAccelerometer();
orientation_sensor = new QOrientationSensor();
}
protected:
virtual void SetUp()
{
bool openResult = data_file.open();
EXPECT_EQ(openResult, true);
setenv("UBUNTU_PLATFORM_API_SENSOR_TEST", qPrintable(data_file.fileName()), 1);
setenv("UBUNTU_PLATFORM_API_BACKEND", "test", 1);
// ensure the queues are clear
while (accel_events.size() > 0)
accel_events.pop();
while (orientation_events.size() > 0)
orientation_events.pop();
}
virtual void TearDown()
{
data_file.remove();
}
void set_data(const char* data)
{
data_file.write(data);
data_file.flush();
}
// run main loop for given number of ms
void run_events(unsigned ms)
{
int argc = 0;
char* argv[] = { NULL };
const unsigned step = 10; // ms per iteration
unsigned count = ms / step;
QCoreApplication app(argc, argv);
while (count-- > 0) {
QThread::msleep(step);
app.processEvents();
}
}
// check the next event in accel_events for expected values and delay
void check_accel_event(qreal x, qreal y, qreal z, unsigned ms)
{
auto e = accel_events.front();
accel_events.pop();
EXPECT_FLOAT_EQ(e.x, x);
EXPECT_FLOAT_EQ(e.y, y);
EXPECT_FLOAT_EQ(e.z, z);
// allow -5 to +10 ms slack in event time
auto delay = chrono::duration_cast(e.time - start_time).count();
EXPECT_GE(delay, ms - 10);
EXPECT_LE(delay, ms + 20);
}
// check the next event in orientation_events for expected value and delay
void check_orientation_event(QOrientationReading::Orientation value, unsigned ms)
{
auto e = orientation_events.front();
orientation_events.pop();
EXPECT_EQ(e.orientation, value);
// allow -5 to +10 ms slack in event time
auto delay = chrono::duration_cast(e.time - start_time).count();
EXPECT_GE(delay, ms - 10);
EXPECT_LE(delay, ms + 40);
}
QTemporaryFile data_file;
QAccelerometer *accel_sensor;
QOrientationSensor *orientation_sensor;
chrono::time_point start_time;
queue accel_events;
queue orientation_events;
};
TESTP_F(SimBackendTest, CreateAccelerometer, {
set_data("create accel 0.5 1000 0.1");
QAccelerometer sensor;
// connect to the qtubuntu-sensors backend; default is dummy, and there
// does not seem to be a way to use data/Sensors.conf
sensor.setIdentifier("core.accelerometer");
EXPECT_EQ(sensor.start(), true);
EXPECT_EQ(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), true);
EXPECT_EQ(sensor.identifier(), "core.accelerometer");
EXPECT_EQ(sensor.accelerationMode(), QAccelerometer::Combined);
//EXPECT_EQ(sensor.outputRange(), 0); // FIXME: bug in code
qoutputrange r = sensor.outputRanges()[0];
EXPECT_FLOAT_EQ(r.minimum, 0.5f);
EXPECT_FLOAT_EQ(r.maximum, 1000.0f);
// defined initial values
auto reading = sensor.reading();
EXPECT_FLOAT_EQ(reading->x(), 0.0);
EXPECT_FLOAT_EQ(reading->y(), 0.0);
EXPECT_FLOAT_EQ(reading->z(), 0.0);
})
TESTP_F(SimBackendTest, CreateOrientation, {
// orientation sensor is based on acceleration
set_data("create accel -500 500 1");
QOrientationSensor sensor;
// connect to the qtubuntu-sensors backend; default is dummy, and there
// does not seem to be a way to use data/Sensors.conf
sensor.setIdentifier("core.orientation");
EXPECT_EQ(sensor.start(), true);
EXPECT_EQ(sensor.error(), 0);
EXPECT_EQ(sensor.isConnectedToBackend(), true);
EXPECT_EQ(sensor.identifier(), "core.orientation");
// defined initial value
EXPECT_EQ(sensor.reading()->orientation(), QOrientationReading::Undefined);
})
TESTP_F(SimBackendTest, AccelerometerEvents, {
set_data("create accel -500 500 0.1\n"
"10 accel 0 -9.9 0\n"
"200 accel 1.5 400 0.5\n"
"300 accel -1 -9.8 -0.5\n");
// connect to the qtubuntu-sensors backend; default is dummy, and there
// does not seem to be a way to use data/Sensors.conf
accel_sensor->setIdentifier("core.accelerometer");
QObject::connect(accel_sensor, &QAccelerometer::readingChanged, [=]() {
auto r = accel_sensor->reading();
accel_events.push({r->x(), r->y(), r->z(), chrono::system_clock::now()});
});
EXPECT_EQ(accel_sensor->start(), true);
start_time = chrono::system_clock::now();
run_events(550);
EXPECT_EQ(accel_events.size(), 3);
check_accel_event(0.0, -9.9, 0.0, 10);
check_accel_event(1.5, 400, 0.5, 210);
check_accel_event(-1.0, -9.8, -0.5, 510);
})
TESTP_F(SimBackendTest, AccelerometerReadings, {
set_data("create accel -500 500 0.1\n"
"10 accel 0 -9.9 0\n"
"200 accel 1.5 400 0.5\n"
"300 accel -1 -9.8 -0.5\n");
// connect to the qtubuntu-sensors backend; default is dummy, and there
// does not seem to be a way to use data/Sensors.conf
accel_sensor->setIdentifier("core.accelerometer");
EXPECT_EQ(accel_sensor->start(), true);
// initial value
auto reading = accel_sensor->reading();
EXPECT_FLOAT_EQ(reading->x(), 0.0);
EXPECT_FLOAT_EQ(reading->y(), 0.0);
EXPECT_FLOAT_EQ(reading->z(), 0.0);
run_events(50);
reading = accel_sensor->reading();
EXPECT_FLOAT_EQ(reading->x(), 0.0);
EXPECT_FLOAT_EQ(reading->y(), -9.9);
EXPECT_FLOAT_EQ(reading->z(), 0.0);
run_events(200);
reading = accel_sensor->reading();
EXPECT_FLOAT_EQ(reading->x(), 1.5);
EXPECT_FLOAT_EQ(reading->y(), 400);
EXPECT_FLOAT_EQ(reading->z(), 0.5);
run_events(350);
reading = accel_sensor->reading();
EXPECT_FLOAT_EQ(reading->x(), -1);
EXPECT_FLOAT_EQ(reading->y(), -9.8);
EXPECT_FLOAT_EQ(reading->z(), -0.5);
})
TESTP_F(SimBackendTest, OrientationReading, {
set_data("create accel -500 500 0.001\n"
"70 accel 0.347 9.768 0.162\n"
"70 accel -0.600 9.947 0.174\n"
"70 accel -0.885 11.061 -0.177\n"
"70 accel -2.121 10.397 -0.468\n"
"70 accel -4.242 8.664 -0.023\n"
"70 accel -5.882 7.633 0.169\n"
"70 accel -7.031 5.822 -0.268\n"
"70 accel -8.138 3.775 0.564\n"
"70 accel -9.616 1.854 1.981\n"
"70 accel -9.562 -0.195 1.138\n"
"70 accel -10.373 -0.597 1.802\n"
);
orientation_sensor->setIdentifier("core.orientation");
EXPECT_EQ(orientation_sensor->start(), true);
// initial value
EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::Undefined);
// Right up after stream of svents
run_events(1400);
EXPECT_EQ(orientation_sensor->reading()->orientation(), QOrientationReading::LeftUp);
})
qtubuntu-sensors-0.6+16.04.20151127/plugins/ 0000755 0000153 0000161 00000000000 12626127552 020765 5 ustar pbuser pbgroup 0000000 0000000 qtubuntu-sensors-0.6+16.04.20151127/plugins/feedback/ 0000755 0000153 0000161 00000000000 12626127552 022511 5 ustar pbuser pbgroup 0000000 0000000 qtubuntu-sensors-0.6+16.04.20151127/plugins/feedback/core_feedback.cpp 0000644 0000153 0000161 00000007163 12626127214 025753 0 ustar pbuser pbgroup 0000000 0000000 /*
* Copyright 2013 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see .
*
* Author: Christian Dywan
*/
#include "core_feedback.h"
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
core::Feedback::Feedback() : QObject(),
m_vibrator(NULL)
{
actuatorList << createFeedbackActuator(this, 42);
if (qgetenv("UBUNTU_PLATFORM_API_BACKEND").isNull())
return;
m_vibrator = ua_sensors_haptic_new();
ua_sensors_haptic_enable(m_vibrator);
}
core::Feedback::~Feedback()
{
if (m_vibrator) {
ua_sensors_haptic_destroy(m_vibrator);
}
}
QFeedbackInterface::PluginPriority core::Feedback::pluginPriority()
{
return PluginHighPriority;
}
QList core::Feedback::actuators()
{
return actuatorList;
}
void core::Feedback::setActuatorProperty(const QFeedbackActuator&, ActuatorProperty prop, const QVariant &)
{
switch (prop)
{
case Enabled:
break;
default:
break;
}
}
QVariant core::Feedback::actuatorProperty(const QFeedbackActuator &actuator, ActuatorProperty prop)
{
QVariant result;
switch (prop)
{
case Name: result = QString::fromLocal8Bit("Ubuntu Vibrator"); break;
case State: result = actuator.isValid() ? QFeedbackActuator::Ready : QFeedbackActuator::Unknown; break;
case Enabled: result = true; break;
}
return result;
}
bool core::Feedback::isActuatorCapabilitySupported(const QFeedbackActuator &, QFeedbackActuator::Capability cap)
{
bool result = false;
switch(cap)
{
case QFeedbackActuator::Envelope:
case QFeedbackActuator::Period: result = true; break;
}
return result;
}
void core::Feedback::updateEffectProperty(const QFeedbackHapticsEffect *effect, EffectProperty)
{
if (effect->period() != -1) {
/* Not currently supported */
reportError(effect, QFeedbackEffect::UnknownError);
}
}
void core::Feedback::vibrateOnce(const QFeedbackEffect* effect)
{
int effectiveDuration = effect->duration();
switch (effectiveDuration)
{
case QFeedbackEffect::Infinite:
case 0:
effectiveDuration = 150;
}
if (m_vibrator)
ua_sensors_haptic_vibrate_once(m_vibrator, effectiveDuration);
}
void core::Feedback::setEffectState(const QFeedbackHapticsEffect *effect, QFeedbackEffect::State state)
{
switch (state)
{
case QFeedbackEffect::Stopped:
break;
case QFeedbackEffect::Paused:
break;
case QFeedbackEffect::Running:
vibrateOnce(effect);
break;
case QFeedbackEffect::Loading:
break;
}
}
QFeedbackEffect::State core::Feedback::effectState(const QFeedbackHapticsEffect *)
{
// We don't currently support on-going vibrations
// This can be added when moving to a vibration service
return QFeedbackEffect::Stopped;
}
qtubuntu-sensors-0.6+16.04.20151127/plugins/feedback/feedback.qrc 0000644 0000153 0000161 00000000141 12626127204 024732 0 ustar pbuser pbgroup 0000000 0000000
feedback.json