feedback daemon.
# if driver = external or undefined
-%package driver-external
+%package driver-external
Summary: Feedbackd binaries targeting external plugin
Provides: %{name}-compat = %{version}-%{release}
Conflicts: %{name}-driver-emulator
Conflicts: %{name}-driver-gpio
Conflicts: %{name}-driver-standard
-Conflicts: %{name}-driver-circle
%description driver-external
Feedbackd binaries with external plugin. Required by main feedbackd package
# if driver = emulator or undefined
-%package driver-emulator
+%package driver-emulator
Summary: Feedbackd binaries targeting emulator plugin
Provides: %{name}-compat = %{version}-%{release}
Conflicts: %{name}-driver-external
Conflicts: %{name}-driver-gpio
Conflicts: %{name}-driver-standard
-Conflicts: %{name}-driver-circle
%description driver-emulator
Feedbackd binaries with emulator plugin. Required by main feedbackd package
# if driver = gpio or undefined
-%package driver-gpio
+%package driver-gpio
Summary: Feedbackd binaries targeting gpio plugin
Provides: %{name}-compat = %{version}-%{release}
Conflicts: %{name}-driver-external
Conflicts: %{name}-driver-emulator
Conflicts: %{name}-driver-standard
-Conflicts: %{name}-driver-circle
%description driver-gpio
Feedbackd binaries with gpio plugin. Required by main feedbackd package
# if driver = standard or undefined
Conflicts: %{name}-driver-external
Conflicts: %{name}-driver-emulator
Conflicts: %{name}-driver-gpio
-Conflicts: %{name}-driver-circle
%description driver-standard
Feedbackd binaries with standard plugin. Required by main feedbackd package
-# if driver = circle or undefined
-%package driver-circle
-Summary: Feedbackd binaries targeting circle plugin
-Provides: %{name}-compat = %{version}-%{release}
-Conflicts: %{name}-driver-external
-Conflicts: %{name}-driver-emulator
-Conflicts: %{name}-driver-gpio
-Conflicts: %{name}-driver-standard
-%description driver-circle
-Feedbackd binaries with circle plugin. Required by main feedbackd package
%package conf-level3
Summary: Feedbackd level configuration file
%prep
%setup -q
-# Build per driver
+# Build per driver
# if driver = external or undefined
mkdir -p build_external
pushd build_external
#eol
popd
-# if driver = circle or undefined
-mkdir -p build_circle
-pushd build_circle
-%cmake .. \
- -DCMAKE_INSTALL_PREFIX=%{_prefix} \
- -DDRIVER=circle \
- #eol
-popd
-
%build
cp %{SOURCE1} .
-# Build per driver
+# Build per driver
# if driver = external or undefined
pushd build_external
make %{?jobs:-j%jobs}
make %{?jobs:-j%jobs}
popd
-# if driver = circle or undefined
-pushd build_circle
-make %{?jobs:-j%jobs}
-popd
-
%install
rm -rf %{buildroot}
# Build per driver
mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.standard
popd
-pushd build_circle
-%make_install
-mv %{buildroot}%{_bindir}/feedbackd %{buildroot}%{_bindir}/feedbackd.circle
-popd
%install_service delayed.target.wants feedbackd.service
systemctl stop feedbackd.service
fi
-%post driver-circle
-mv %{_bindir}/feedbackd.circle %{_bindir}/feedbackd
-
-%preun driver-circle
-mv %{_bindir}/feedbackd %{_bindir}/feedbackd.circle
-
-if [ "$1" == "0" ]; then
- systemctl stop feedbackd.service
-fi
-
%post conf-level3
mv %{_sysconfdir}/feedbackd/haptic-level3.conf %{_sysconfdir}/feedbackd/haptic.conf
%manifest %{name}.manifest
%{_bindir}/feedbackd.standard
-%files driver-circle
-%license LICENSE.Apache-2.0
-%manifest %{name}.manifest
-%{_bindir}/feedbackd.circle
-
%files conf-level3
%license LICENSE.Apache-2.0
%manifest %{name}.manifest
+++ /dev/null
-/*
- * feedbackd
- *
- * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the License);
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <limits.h>
-#include <fcntl.h>
-#include <sys/types.h>
-
-#include "core/log.h"
-#include "core/list.h"
-#include "haptic.h"
-
-#define CIRCLE_ON_PATH "/sys/class/sec/motor/motor_on"
-#define CIRCLE_OFF_PATH "/sys/class/sec/motor/motor_off"
-
-#define BUF_SIZE 8
-
-static int fd_play = -1, fd_stop = -1;
-static dd_list *handle_list;
-static guint stop_timer;
-static int unique_number;
-static bool state = false;
-
-static int stop_device(int device_handle);
-static bool find_from_list(int handle)
-{
- dd_list *elem;
-
- elem = DD_LIST_FIND(handle_list, (gpointer)(long)handle);
- if (elem)
- return true;
-
- return false;
-}
-
-static gboolean timer_cb(void *data)
-{
- int device_handle = (int)(long)data;
- int ret;
- char buf[BUF_SIZE];
- bool found;
-
- _I("Stop vibration by timer.");
-
- found = find_from_list(device_handle);
- if (!found)
- return G_SOURCE_REMOVE;
-
- /* stop previous vibration */
- if (fd_stop < 0) {
- fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY);
- if (fd_stop < 0)
- return G_SOURCE_REMOVE;
- }
- ret = read(fd_stop, buf, BUF_SIZE);
- if (ret < 0) {
- _E("Failed to stop.");
- return G_SOURCE_REMOVE;
- }
- stop_timer = 0;
-
- return G_SOURCE_REMOVE;
-}
-
-static int get_device_count(int *count)
-{
- /* suppose there is just one haptic device */
- if (count)
- *count = 1;
-
- return 0;
-}
-
-static int open_device(int device_index, int *device_handle)
-{
- int n;
- bool found = false;
- dd_list *elem;
-
- if (!device_handle)
- return -EINVAL;
-
- /* if it is the first element */
- n = DD_LIST_LENGTH(handle_list);
- if (n == 0) {
- _I("Open.");
- if (fd_play < 0) {
- fd_play = open(CIRCLE_ON_PATH, O_RDONLY);
- if (fd_play < 0) {
- _E("Failed to open '%s': %d", CIRCLE_ON_PATH, errno);
- return -errno;
- }
- }
- if (fd_stop < 0) {
- fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY);
- if (fd_stop < 0) {
- _E("Failed to open '%s': %d", CIRCLE_OFF_PATH, errno);
- return -errno;
- }
- }
- }
-
- if (unique_number == INT_MAX)
- unique_number = 0;
-
- while (found != true) {
- ++unique_number;
- elem = DD_LIST_FIND(handle_list, (gpointer)(long)unique_number);
- if (!elem)
- found = true;
- }
-
- /* add info to local list */
- DD_LIST_APPEND(handle_list, (gpointer)(long)unique_number);
-
- *device_handle = unique_number;
- return 0;
-}
-
-static int close_device(int device_handle)
-{
- int r, n;
- bool found;
-
- found = find_from_list(device_handle);
- if (!found) {
- _E("Handle(%d) fail to check info.", device_handle);
- return -EINVAL;
- }
-
- if (fd_stop < 0) {
- fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY);
- if (fd_stop < 0) {
- _E("Handle(%d) fail to check fd.", device_handle);
- return -ENODEV;
- }
- }
-
- /* stop vibration */
- r = stop_device(device_handle);
- if (r < 0)
- _I("Handle(%d) already stopped or failed to stop effect: %d", device_handle, r);
-
- DD_LIST_REMOVE(handle_list, (gpointer)(long)device_handle);
-
- /* if it is the last element */
- n = DD_LIST_LENGTH(handle_list);
- if (n == 0) {
- _I("Close.");
- if (fd_play > 0) {
- close(fd_play);
- fd_play = -1;
- }
- if (fd_stop > 0) {
- close(fd_stop);
- fd_stop = -1;
- }
- }
-
- return 0;
-}
-
-static int vibrate_monotone(int device_handle, int duration, int frequency, int overdrive, int level, int intensity, int priority)
-{
- int ret;
- char buf[BUF_SIZE];
- bool found;
-
- found = find_from_list(device_handle);
- if (!found) {
- _E("Handle(%d) fail to check list.", device_handle);
- return -EINVAL;
- }
-
- if (fd_play < 0) {
- fd_play = open(CIRCLE_ON_PATH, O_RDONLY);
- if (fd_play < 0) {
- _E("Handle(%d) fail to check handle.", device_handle);
- return -ENODEV;
- }
- }
-
- if (duration <= 0) {
- _E("Handle(%d) skip requested with 0.", device_handle);
- return -EINVAL;
- }
-
- /* Zero(0) is the infinitely vibration value */
- if (duration == HAPTIC_MODULE_DURATION_UNLIMITED)
- duration = 0;
-
- if (stop_timer)
- stop_device(device_handle);
-
- /* play vibration */
- ret = read(fd_play, buf, BUF_SIZE);
- if (ret < 0) {
- _E("Handle(%d) failed to play.", device_handle);
- return -errno;
- }
-
- /* register timer */
- if (duration) {
- stop_timer = g_timeout_add(duration, timer_cb, (void *)(long)device_handle);
-
- if (!stop_timer)
- _E("Handle(%d) Failed to add timer callback.", device_handle);
- }
-
- _D("Device handle(%d) %dms.", device_handle, duration);
-
- return 0;
-}
-
-static int stop_device(int device_handle)
-{
- int ret;
- char buf[BUF_SIZE];
- bool found;
-
- found = find_from_list(device_handle);
- if (!found) {
- _E("Handle(%d) fail to check info.", device_handle);
- return -EINVAL;
- }
-
- if (cur_h_data.handle > 0 && cur_h_data.handle != device_handle) {
- _E("Only same handle can stop current vibration.");
- return -EPERM;
- }
-
- if (fd_stop < 0) {
- fd_stop = open(CIRCLE_OFF_PATH, O_RDONLY);
- if (fd_stop < 0) {
- _E("Handle(%d) fail to check fd.", device_handle);
- return -ENODEV;
- }
- }
- ret = read(fd_stop, buf, BUF_SIZE);
- if (ret < 0) {
- _E("Failed to stop.");
- return -errno;
- }
- if (stop_timer) {
- g_source_remove(stop_timer);
- stop_timer = 0;
- }
-
- return 0;
-}
-/* END: Haptic Module APIs */
-
-static const struct haptic_plugin_ops default_plugin = {
- .get_device_count = get_device_count,
- .open_device = open_device,
- .close_device = close_device,
- .vibrate_monotone = vibrate_monotone,
- .stop_device = stop_device,
-};
-
-static bool is_valid(void)
-{
- if ((access(CIRCLE_ON_PATH, R_OK) != 0) ||
- (access(CIRCLE_OFF_PATH, R_OK) != 0)) {
- _E("Do not support wearable haptic device.");
- state = false;
- return false;
- }
-
- state = true;
- _I("Support wearable haptic device.");
- return true;
-}
-
-static const struct haptic_plugin_ops *load(void)
-{
- return &default_plugin;
-}
-
-static const struct haptic_ops std_ops = {
- .type = HAPTIC_STANDARD,
- .is_valid = is_valid,
- .load = load,
-};
-
-HAPTIC_OPS_REGISTER(&std_ops)