[-]
[+]
|
Changed |
_service:tar_git:qt5-feedback-haptics-droid-vibrator.changes
|
|
[-]
[+]
|
Changed |
_service:tar_git:qt5-feedback-haptics-droid-vibrator.spec
^
|
|
[-]
[+]
|
Changed |
_service:tar_git:qt5-feedback-haptics-droid-vibrator-0.2.1.tar.bz2/droid-vibrator.pro
^
|
@@ -6,14 +6,20 @@
TARGET = $$qtLibraryTarget(qtfeedback_droid-vibrator)
PLUGIN_TYPE = feedback
-HEADERS += qfeedback.h
+HEADERS += qfeedback.h vibratorimplementation.h
SOURCES += qfeedback.cpp
OTHER_FILES += droid-vibrator.json
-CONFIG += link_pkgconfig
-PKGCONFIG += android-headers libhardware libvibrator
DEFINES += 'DROID_VIBRATOR_SETTINGS=\'\"$$[QT_INSTALL_PLUGINS]/feedback/droid-vibrator-device.ini\"\''
+native_vibrator {
+ SOURCES += vibratorimplementation_native.cpp
+} else {
+ CONFIG += link_pkgconfig
+ PKGCONFIG += android-headers libhardware libvibrator
+ SOURCES += vibratorimplementation_hal.cpp
+}
+
target.path = $$[QT_INSTALL_PLUGINS]/feedback
INSTALLS += target
@@ -24,4 +30,4 @@
# also enable profile detection. libprofile-qt5 is a bit broken, work around it here.
QT += dbus
QMAKE_CXXFLAGS += -I/usr/include/profile-qt5
-QMAKE_LFLAGS += -lprofile-qt5
+LIBS += -lprofile-qt5
|
[-]
[+]
|
Changed |
_service:tar_git:qt5-feedback-haptics-droid-vibrator-0.2.1.tar.bz2/qfeedback.cpp
^
|
@@ -62,22 +62,13 @@
, m_actuator(createFeedbackActuator(this, 2))
, m_activeEffect(Q_NULLPTR)
, m_actuatorEnabled(true)
-#if ANDROID_VERSION_MAJOR >= 7
- , m_dev(NULL)
-#endif
+ , m_vibrator()
{
qCDebug(qtFeedbackDroidVibrator) << "Initializing plugin";
-#if (ANDROID_VERSION_MAJOR >= 7)
- struct hw_module_t *hwmod;
-
- hw_get_module(VIBRATOR_HARDWARE_MODULE_ID, (const hw_module_t **)(&hwmod));
- Q_ASSERT(hwmod != NULL);
-
- if (vibrator_open(hwmod, &m_dev) < 0) {
+ if (!m_vibrator.init()) {
qCCritical(qtFeedbackDroidVibrator) << "Unable to open vibrator device";
}
-#endif
// Defaults
m_durations[QFeedbackEffect::Press] = 20;
@@ -182,12 +173,7 @@
case QFeedbackEffect::Disappear:
case QFeedbackEffect::Move:
qCDebug(qtFeedbackDroidVibrator) << "Playing effect #" << effect << "(" << m_durations[effect] << "ms)";
-#if ANDROID_VERSION_MAJOR >= 7
- if (m_dev)
- m_dev->vibrator_on(m_dev, m_durations[effect]);
-#else
- vibrator_on(m_durations[effect]);
-#endif
+ m_vibrator.on(m_durations[effect]);
return true;
default:
qCDebug(qtFeedbackDroidVibrator) << "Unknown or undefined effect #" << effect;
@@ -287,13 +273,7 @@
m_activeEffect = const_cast<QFeedbackHapticsEffect*>(effect);
m_stateChangeTimerId = QObject::startTimer(m_activeEffect->duration());
qCDebug(qtFeedbackDroidVibrator) << "Playing custom effect due to state change (" << m_activeEffect->duration() << "ms)";
-#if ANDROID_VERSION_MAJOR >= 7
- if (m_dev)
- m_dev->vibrator_on(m_dev, m_activeEffect->duration());
-#else
- vibrator_on(m_activeEffect->duration());
-#endif
-
+ m_vibrator.on(m_activeEffect->duration());
}
}
@@ -301,12 +281,7 @@
{
if (m_activeEffect == effect) {
qCDebug(qtFeedbackDroidVibrator) << "Stopping custom effect due to state change";
-#if ANDROID_VERSION_MAJOR >= 7
- if (m_dev)
- m_dev->vibrator_off(m_dev);
-#else
- vibrator_off();
-#endif
+ m_vibrator.off();
killTimer(m_stateChangeTimerId);
m_activeEffect = 0;
m_stateChangeTimerId = 0;
|
[-]
[+]
|
Changed |
_service:tar_git:qt5-feedback-haptics-droid-vibrator-0.2.1.tar.bz2/qfeedback.h
^
|
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2014 Jolla Ltd.
+** Copyright (C) 2014,2018 Jolla Ltd.
** Contact: Thomas Perl <thomas.perl@jolla.com>
**
** This file is part of the QtFeedback Droid Vibrator Plugin.
@@ -49,12 +49,7 @@
#include <profile.h>
-#include <android-version.h>
-#if ANDROID_VERSION_MAJOR >= 7
-#include <hardware/vibrator.h>
-#else
-#include <hardware_legacy/vibrator.h>
-#endif
+#include "vibratorimplementation.h"
Q_DECLARE_LOGGING_CATEGORY(qtFeedbackDroidVibrator)
@@ -102,9 +97,7 @@
QFeedbackHapticsEffect *m_activeEffect;
bool m_actuatorEnabled;
int m_stateChangeTimerId;
-#if ANDROID_VERSION_MAJOR >= 7
- vibrator_device_t *m_dev;
-#endif
+ VibratorImplementation m_vibrator;
};
QT_END_HEADER
|
[-]
[+]
|
Added |
_service:tar_git:qt5-feedback-haptics-droid-vibrator-0.2.1.tar.bz2/vibratorimplementation.h
^
|
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Jolla Ltd.
+** Contact: Juho Hämäläinen <juho.hamalainen@jolla.com>
+**
+** This file is part of the QtFeedback Droid Vibrator Plugin.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#ifndef VIBRATOR_IMPLEMENTATION_H
+#define VIBRATOR_IMPLEMENTATION_H
+
+#include <cstdint>
+
+struct VibratorImplementationPrivate;
+
+class VibratorImplementation {
+public:
+ VibratorImplementation();
+ ~VibratorImplementation();
+
+ bool init();
+ void on(uint32_t duration_ms);
+ void off();
+
+private:
+ VibratorImplementationPrivate* const d_ptr;
+};
+
+#endif
|
[-]
[+]
|
Added |
_service:tar_git:qt5-feedback-haptics-droid-vibrator-0.2.1.tar.bz2/vibratorimplementation_hal.cpp
^
|
@@ -0,0 +1,115 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Jolla Ltd.
+** Contact: Juho Hämäläinen <juho.hamalainen@jolla.com>
+**
+** This file is part of the QtFeedback Droid Vibrator Plugin.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "vibratorimplementation.h"
+
+#include <android-version.h>
+#if ANDROID_VERSION_MAJOR >= 7
+#include <hardware/vibrator.h>
+#else
+#include <hardware_legacy/vibrator.h>
+#endif
+
+struct VibratorImplementationPrivate {
+#if ANDROID_VERSION_MAJOR >= 7
+ vibrator_device_t *dev;
+#endif
+};
+
+VibratorImplementation::VibratorImplementation()
+#if ANDROID_VERSION_MAJOR >= 7
+ : d_ptr(new VibratorImplementationPrivate())
+{
+ d_ptr->dev = 0;
+}
+#else
+ : d_ptr(0)
+{
+}
+#endif
+
+VibratorImplementation::~VibratorImplementation()
+{
+#if ANDROID_VERSION_MAJOR >= 7
+ if (d_ptr->dev) {
+ d_ptr->dev->common.close(reinterpret_cast<hw_device_t *>(d_ptr->dev));
+ }
+
+ delete d_ptr;
+#endif
+}
+
+bool VibratorImplementation::init()
+{
+#if ANDROID_VERSION_MAJOR >= 7
+ struct hw_module_t *hwmod = 0;
+
+ hw_get_module(VIBRATOR_HARDWARE_MODULE_ID, (const hw_module_t **)(&hwmod));
+
+ if (!hwmod || vibrator_open(hwmod, &d_ptr->dev) < 0) {
+ return false;
+ }
+#endif
+
+ return true;
+}
+
+void VibratorImplementation::on(uint32_t duration_ms)
+{
+#if ANDROID_VERSION_MAJOR >= 7
+ if (d_ptr->dev) {
+ d_ptr->dev->vibrator_on(d_ptr->dev, duration_ms);
+ }
+#else
+ vibrator_on(duration_ms);
+#endif
+}
+
+void VibratorImplementation::off()
+{
+#if ANDROID_VERSION_MAJOR >= 7
+ if (d_ptr->dev) {
+ d_ptr->dev->vibrator_off(d_ptr->dev);
+ }
+#else
+ vibrator_off();
+#endif
+}
|
[-]
[+]
|
Added |
_service:tar_git:qt5-feedback-haptics-droid-vibrator-0.2.1.tar.bz2/vibratorimplementation_native.cpp
^
|
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2018 Jolla Ltd.
+** Contact: Juho Hämäläinen <juho.hamalainen@jolla.com>
+**
+** This file is part of the QtFeedback Droid Vibrator Plugin.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "vibratorimplementation.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <cstdio>
+
+#define ACTIVATE_ON (1)
+#define ACTIVATE_OFF (0)
+
+struct file_location {
+ const char *duration;
+ const char *activate;
+};
+
+static const struct file_location file_locations[] = {
+ { "/sys/class/timed_output/vibrator/enable", NULL },
+ { "/sys/class/leds/vibrator/duration", "/sys/class/leds/vibrator/activate" },
+};
+
+struct VibratorImplementationPrivate {
+ void vibrator_write(int fd, uint32_t value);
+ int duration_fd;
+ int activate_fd;
+};
+
+VibratorImplementation::VibratorImplementation()
+ : d_ptr(new VibratorImplementationPrivate())
+{
+ d_ptr->duration_fd = -1;
+ d_ptr->activate_fd = -1;
+}
+
+VibratorImplementation::~VibratorImplementation()
+{
+ if (d_ptr->duration_fd >= 0)
+ close(d_ptr->duration_fd);
+
+ if (d_ptr->activate_fd >= 0)
+ close(d_ptr->activate_fd);
+
+ delete d_ptr;
+}
+
+bool VibratorImplementation::init()
+{
+ if (d_ptr->duration_fd >= 0)
+ return true;
+
+ for (unsigned i = 0; i < sizeof(file_locations) / sizeof(file_locations[0]); i++) {
+ const char *duration_path = file_locations[i].duration;
+ const char *activate_path = file_locations[i].activate;
+
+ if ((d_ptr->duration_fd = open(duration_path, O_WRONLY)) < 0)
+ continue;
+
+ if (activate_path) {
+ if ((d_ptr->activate_fd = open(activate_path, O_WRONLY)) < 0) {
+ close(d_ptr->duration_fd);
+ d_ptr->duration_fd = -1;
+ continue;
+ }
+ }
+
+ break;
+ }
+
+ if (d_ptr->duration_fd < 0)
+ return false;
+
+ return true;
+}
+
+void VibratorImplementation::on(uint32_t duration_ms)
+{
+ d_ptr->vibrator_write(d_ptr->duration_fd, duration_ms);
+ if (d_ptr->duration_fd >= 0)
+ d_ptr->vibrator_write(d_ptr->activate_fd, ACTIVATE_ON);
+}
+
+void VibratorImplementation::off()
+{
+ d_ptr->vibrator_write(d_ptr->duration_fd, ACTIVATE_OFF);
+ if (d_ptr->activate_fd >= 0)
+ d_ptr->vibrator_write(d_ptr->activate_fd, ACTIVATE_OFF);
+}
+
+void VibratorImplementationPrivate::vibrator_write(int fd, uint32_t value)
+{
+ char value_str[12]; /* fits UINT32_MAX value with newline */
+ int length;
+
+ if (fd < 0) {
+ return;
+ }
+
+ length = snprintf(value_str, sizeof(value_str), "%u\n", value);
+ write(fd, value_str, length);
+}
|