qtubuntu-sensors-0.6+14.04.20140304/ 0000755 0000152 0177776 00000000000 12305345556 017342 5 ustar pbuser nogroup 0000000 0000000 qtubuntu-sensors-0.6+14.04.20140304/tests/ 0000755 0000152 0177776 00000000000 12305345556 020504 5 ustar pbuser nogroup 0000000 0000000 qtubuntu-sensors-0.6+14.04.20140304/tests/CMakeLists.txt 0000644 0000152 0177776 00000001277 12305345334 023245 0 ustar pbuser nogroup 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
)
# we need to call the tests with pointing to the locally built plugins
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
)
qtubuntu-sensors-0.6+14.04.20140304/tests/test_sensor_api.cpp 0000644 0000152 0177776 00000033051 12305345334 024405 0 ustar pbuser nogroup 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
{
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", "libubuntu_application_api_test.so.1", 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, OrientationEvents, {
/* test some "parallel to coordinate axes" conditions, as well as some
* ~ 45 degrees angles; we want a hysteresis there, i. e. it should not
* flip back and forth when wiggling around the diagonals but only when
* it's mostly pointing towards an axis
* coordinate system:
* http://qt-project.org/doc/qt-5.1/qtsensors/qaccelerometerreading.html
*/
set_data("create accel -500 500 0.1\n"
"10 accel 0 9.8 0\n" // TopUp
"100 accel 6.9 6.9 0\n" // turning left
"150 accel 8.1 2.3 0\n" // almost turned left, should trigger RightUp
"50 accel -7.1 6.9 0\n" // turn right, wiggle around diagonal several times
"30 accel -6.5 7.1 0\n"
"30 accel -7.0 6.0 0\n"
"30 accel -7.0 6.0 0\n"
"30 accel -8.0 3.0 0\n" // finally turn right enough to trigger LeftUp
"30 accel 0 -9.8 0\n" // TopDown
"30 accel 0 0 9.8\n" // FaceUp
"30 accel 0 0 -9.8\n" // FaceDown
);
orientation_sensor.setIdentifier("core.orientation");
QObject::connect(&orientation_sensor, &QOrientationSensor::readingChanged, [=]() {
auto r = orientation_sensor.reading();
orientation_events.push({r->orientation(), chrono::system_clock::now()});
});
EXPECT_EQ(orientation_sensor.start(), true);
start_time = chrono::system_clock::now();
run_events(550); // must be long enough to catch all events
EXPECT_EQ(orientation_events.size(), 6);
check_orientation_event(QOrientationReading::TopUp, 10);
check_orientation_event(QOrientationReading::RightUp, 260);
check_orientation_event(QOrientationReading::LeftUp, 430);
check_orientation_event(QOrientationReading::TopDown, 460);
check_orientation_event(QOrientationReading::FaceUp, 490);
check_orientation_event(QOrientationReading::FaceDown, 520);
})
TESTP_F(SimBackendTest, OrientationReading, {
set_data("create accel -500 500 0.1\n"
"10 accel 0 9.8 0\n" // TopUp
"20 accel 6.9 6.9 0\n" // turning left
"20 accel 8.1 2.3 0\n" // almost turned left, should trigger RightUp
);
orientation_sensor.setIdentifier("core.orientation");
EXPECT_EQ(orientation_sensor.start(), true);
// initial value
EXPECT_EQ(orientation_sensor.reading()->orientation(), QOrientationReading::Undefined);
// TopUp after first event
run_events(20);
EXPECT_EQ(orientation_sensor.reading()->orientation(), QOrientationReading::TopUp);
// not changed for "turning left" yet
run_events(20);
EXPECT_EQ(orientation_sensor.reading()->orientation(), QOrientationReading::TopUp);
// but changed after "almost turned left"
run_events(20);
EXPECT_EQ(orientation_sensor.reading()->orientation(), QOrientationReading::RightUp);
})
/*******************************************
*
* Tests with real sensor backend
*
*******************************************/
class RealBackendTest : public testing::Test
{
virtual void SetUp()
{
unsetenv("UBUNTU_PLATFORM_API_BACKEND");
}
};
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()
{
unsetenv("UBUNTU_PLATFORM_API_BACKEND");
}
};
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+14.04.20140304/CMakeLists.txt 0000644 0000152 0177776 00000002026 12305345334 022074 0 ustar pbuser nogroup 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+14.04.20140304/data/ 0000755 0000152 0177776 00000000000 12305345556 020253 5 ustar pbuser nogroup 0000000 0000000 qtubuntu-sensors-0.6+14.04.20140304/data/Sensors.conf 0000644 0000152 0177776 00000000132 12305345334 022544 0 ustar pbuser nogroup 0000000 0000000 [Default]
QAccelerometer = core.accelerometer
QOrientationSensor = core.orientationsensor
qtubuntu-sensors-0.6+14.04.20140304/COPYING 0000644 0000152 0177776 00000016743 12305345334 020402 0 ustar pbuser nogroup 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+14.04.20140304/plugins/ 0000755 0000152 0177776 00000000000 12305345556 021023 5 ustar pbuser nogroup 0000000 0000000 qtubuntu-sensors-0.6+14.04.20140304/plugins/sensors/ 0000755 0000152 0177776 00000000000 12305345556 022517 5 ustar pbuser nogroup 0000000 0000000 qtubuntu-sensors-0.6+14.04.20140304/plugins/sensors/core_shared_accelerometer.h 0000644 0000152 0177776 00000003324 12305345334 030034 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 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 .
*/
#ifndef CORE_SHARED_ACCELEROMETER_H
#define CORE_SHARED_ACCELEROMETER_H
#include
#include
#include
#include
namespace core
{
class SharedAccelerometer : public QObject
{
Q_OBJECT
public:
static SharedAccelerometer& instance();
void start();
void stop();
qreal getMinDelay() const;
qreal getMinValue() const;
qreal getMaxValue() const;
qreal getResolution() const;
Q_SIGNALS:
void accelerometerReadingChanged(QSharedPointer reading);
private:
SharedAccelerometer(QObject *parent = NULL);
UASensorsAccelerometer *m_accelerometer;
qreal m_minDelay;
qreal m_minValue;
qreal m_maxValue;
qreal m_resolution;
bool m_available;
// Gets called by the underlying platform when there is a new accelerometer reading
static void onAccelerometerReadingCb(UASAccelerometerEvent *event, void *context);
void onAccelerometerReading(UASAccelerometerEvent *event);
};
}
#endif // CORE_SHARED_ACCELEROMETER_H
qtubuntu-sensors-0.6+14.04.20140304/plugins/sensors/CMakeLists.txt 0000644 0000152 0177776 00000002151 12305345334 025250 0 ustar pbuser nogroup 0000000 0000000 find_package(PkgConfig)
find_package(Qt5Core REQUIRED)
find_package(Qt5Sensors REQUIRED)
pkg_check_modules(UBUNTU_PLATFORM_API ubuntu-platform-api REQUIRED)
qt5_add_resources(SENSORS_RESOURCES sensors.qrc)
add_library(
qtubuntu_sensors_plugins SHARED
core_accelerometer.h
core_orientation_sensor.h
core_sensor_plugins.h
core_shared_accelerometer.h
core_accelerometer.cpp
core_orientation_sensor.cpp
core_sensor_plugins.cpp
core_shared_accelerometer.cpp
${SENSORS_RESOURCES}
)
# Ideally, we would read the plugin installation location from cmake
# but this does not work currently.
set(PLUGIN_INSTALL_LOCATION "${CMAKE_INSTALL_LIBDIR}/qt5/plugins/sensors")
# get_target_property(PLUGIN_LOCATION Qt5::Sensors PLUGIN_LOCATION)
message(STATUS "Installing Qt5 sensors plugin to: ${PLUGIN_INSTALL_LOCATION}")
qt5_use_modules(qtubuntu_sensors_plugins Core Sensors)
target_link_libraries(
qtubuntu_sensors_plugins
${CMAKE_THREAD_LIBS_INIT}
Qt5::Core
Qt5::Sensors
${UBUNTU_PLATFORM_API_LIBRARIES})
install(
TARGETS qtubuntu_sensors_plugins
LIBRARY DESTINATION ${PLUGIN_INSTALL_LOCATION})
qtubuntu-sensors-0.6+14.04.20140304/plugins/sensors/core_shared_accelerometer.cpp 0000644 0000152 0177776 00000007011 12305345334 030364 0 ustar pbuser nogroup 0000000 0000000 /*
* Copyright (C) 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 .
*/
#include "core_shared_accelerometer.h"
#include
#include
Q_DECLARE_METATYPE(QSharedPointer)
core::SharedAccelerometer& core::SharedAccelerometer::instance()
{
static core::SharedAccelerometer instance;
return instance;
}
core::SharedAccelerometer::SharedAccelerometer(QObject *parent)
: QObject(parent),
m_minDelay(-1),
m_minValue(0.0),
m_maxValue(0.0),
m_resolution(0.0),
m_available(false)
{
qRegisterMetaType >("QSharedPointer");
m_accelerometer = ua_sensors_accelerometer_new();
if (m_accelerometer == NULL)
return;
ua_sensors_accelerometer_set_reading_cb(
m_accelerometer,
core::SharedAccelerometer::onAccelerometerReadingCb,
static_cast(this));
// Get the minimum sensor reading delay
m_minDelay = static_cast(ua_sensors_accelerometer_get_min_delay(m_accelerometer));
m_minValue = static_cast(ua_sensors_accelerometer_get_min_value(m_accelerometer));
m_maxValue = static_cast(ua_sensors_accelerometer_get_max_value(m_accelerometer));
m_resolution = static_cast(ua_sensors_accelerometer_get_resolution(m_accelerometer));
m_available = true;
}
void core::SharedAccelerometer::start()
{
if (m_available)
ua_sensors_accelerometer_enable(m_accelerometer);
}
void core::SharedAccelerometer::stop()
{
if (m_available)
ua_sensors_accelerometer_disable(m_accelerometer);
}
qreal core::SharedAccelerometer::getMinDelay() const
{
return m_minDelay;
}
qreal core::SharedAccelerometer::getMinValue() const
{
return m_minValue;
}
qreal core::SharedAccelerometer::getMaxValue() const
{
return m_maxValue;
}
qreal core::SharedAccelerometer::getResolution() const
{
return m_resolution;
}
void core::SharedAccelerometer::onAccelerometerReadingCb(UASAccelerometerEvent *event, void *context)
{
SharedAccelerometer* ac = static_cast(context);
if (ac != NULL)
ac->onAccelerometerReading(event);
}
void core::SharedAccelerometer::onAccelerometerReading(UASAccelerometerEvent *event)
{
Q_ASSERT(event != NULL);
// TODO(tvoss): We should rely on an object pool to recycle accelerometer reading
// instances here. We could use a custom deleter for the shared pointer to put
// instances that have been successfully delivered to slots back into the pool.
QSharedPointer reading(new QAccelerometerReading());
reading->setX(uas_accelerometer_event_get_acceleration_x(event));
reading->setY(uas_accelerometer_event_get_acceleration_y(event));
reading->setZ(uas_accelerometer_event_get_acceleration_z(event));
reading->setTimestamp(uas_accelerometer_event_get_timestamp(event));
Q_EMIT accelerometerReadingChanged(reading);
}
qtubuntu-sensors-0.6+14.04.20140304/plugins/sensors/sensors.qrc 0000644 0000152 0177776 00000000140 12305345334 024707 0 ustar pbuser nogroup 0000000 0000000
sensors.json