input: add input-handler for iot-headless 88/264688/3 accepted/tizen/6.5/unified/20211028.114341 accepted/tizen/unified/20211001.001408 submit/tizen/20210929.005949 submit/tizen_6.5/20211028.162501 tizen_6.5.m2_release
authorYoungjae Cho <y0.cho@samsung.com>
Tue, 28 Sep 2021 08:15:48 +0000 (17:15 +0900)
committerHyotaek Shim <hyotaek.shim@samsung.com>
Wed, 29 Sep 2021 00:40:07 +0000 (00:40 +0000)
Change-Id: Ie90573af3c1351d8f1f6ed8622ed8ec021eb8ba8
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
CMakeLists.txt
packaging/deviced.spec
plugins/iot-headless/input/CMakeLists.txt [new file with mode: 0644]
plugins/iot-headless/input/input-handler.c [new file with mode: 0644]
src/display/display-input.c

index 4713f60..e16edd2 100644 (file)
@@ -339,10 +339,12 @@ ADD_SUBDIRECTORY(plugins/mobile/display)
 ADD_SUBDIRECTORY(plugins/wearable/display)
 ADD_SUBDIRECTORY(plugins/tv/display)
 ADD_SUBDIRECTORY(plugins/iot-headed/display)
+ADD_SUBDIRECTORY(plugins/iot-headless/input)
 IF(BATTERY_MODULE STREQUAL on)
        ADD_SUBDIRECTORY(plugins/mobile/battery)
        ADD_SUBDIRECTORY(plugins/wearable/battery)
 ENDIF()
+
 INSTALL_CONF(conf mobile-display)
 INSTALL_CONF(conf wearable-display)
 INSTALL_CONF(conf tv-display)
index 9c4fb41..34679aa 100644 (file)
@@ -257,6 +257,7 @@ mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so
 mv %{_sysconfdir}/deviced/iot-headless-display.conf %{_sysconfdir}/deviced/display.conf
 mkdir -p %{_libdir}/deviced
 mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so
+mv %{_libdir}/iot-headless-input-handler.so %{_libdir}/deviced/input-handler.so
 
 %files
 %manifest %{name}.manifest
@@ -375,5 +376,6 @@ mv %{_libdir}/iot-headed-display.so %{_libdir}/deviced/display.so
 %defattr(-,root,root,-)
 %config %{_sysconfdir}/deviced/iot-headed-display.conf
 %{_libdir}/iot-headed-display.so
+%{_libdir}/iot-headless-input-handler.so
 %{_unitdir}/rndis.service
 %{_bindir}/rndis.sh
diff --git a/plugins/iot-headless/input/CMakeLists.txt b/plugins/iot-headless/input/CMakeLists.txt
new file mode 100644 (file)
index 0000000..f9a7881
--- /dev/null
@@ -0,0 +1,17 @@
+CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
+
+PROJECT(iot-headless-input-handler C)
+
+INCLUDE(FindPkgConfig)
+PKG_CHECK_MODULES(REQUIRED_PKGS REQUIRED
+       glib-2.0
+       dlog
+       libinput)
+
+INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src)
+
+FILE(GLOB SRCS "*.c")
+ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS})
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES PREFIX "")
+SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES OUTPUT_NAME iot-headless-input-handler)
+INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries)
diff --git a/plugins/iot-headless/input/input-handler.c b/plugins/iot-headless/input/input-handler.c
new file mode 100644 (file)
index 0000000..cacd970
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * deviced
+ *
+ * Copyright (c) 2021 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 <libinput.h>
+#include <glib.h>
+
+#include "core/devices.h"
+#include "shared/log.h"
+
+#define KEYCODE_LEFTKEY      114
+#define KEYCODE_RIGHTKEY     116
+
+#define KEYVALUE_PRESS       1
+#define KEYVALUE_RELEASE     0
+
+#define LONGPRESS_INTERVAL   3000   /* milisecond */
+
+static guint longpress_timer_id;
+
+static gboolean longpressed_cb(void *data)
+{
+       const struct device_ops *power_device;
+
+       longpress_timer_id = 0;
+
+       power_device = find_device("power");
+       if (check_default(power_device))
+               return G_SOURCE_REMOVE;
+
+       if (power_device->execute) {
+               _D("longkey pressed, do poweroff");
+               power_device->execute("poweroff");
+       }
+
+       return G_SOURCE_REMOVE;
+}
+
+static void start_longpress_timer(void)
+{
+       if (longpress_timer_id) {
+               g_source_remove(longpress_timer_id);
+               longpress_timer_id = 0;
+       }
+
+       longpress_timer_id = g_timeout_add(LONGPRESS_INTERVAL, longpressed_cb, NULL);
+}
+
+static void stop_longpress_timer(void)
+{
+       if (longpress_timer_id) {
+               g_source_remove(longpress_timer_id);
+               longpress_timer_id = 0;
+       }
+}
+
+/* poweroff if left button is pressed longer than LONGPRESS_INTERVAL */
+static void input_event_handler(struct libinput_event *e)
+{
+       struct libinput_event_keyboard *ek;
+       int keycode, keyvalue;
+
+       if (libinput_event_get_type(e) != LIBINPUT_EVENT_KEYBOARD_KEY)
+               return;
+
+       ek = libinput_event_get_keyboard_event(e);
+       keycode = libinput_event_keyboard_get_key(ek);
+       keyvalue = libinput_event_keyboard_get_key_state(ek);
+
+       _D("key input: code=%d, value=%d", keycode, keyvalue);
+
+       if (keycode == KEYCODE_LEFTKEY) {
+               if (keyvalue == KEYVALUE_PRESS)
+                       start_longpress_timer();
+               else if (keyvalue == KEYVALUE_RELEASE)
+                       stop_longpress_timer();
+       }
+}
+
+static void input_event_handler_init(void *data)
+{
+       const struct device_ops *input_device;
+
+       input_device = find_device("input");
+       if (check_default(input_device)) {
+               _E("There is no input device");
+               return;
+       }
+
+       if (input_device->init) {
+               _D("[%s] Initialization.", input_device->name);
+               input_device->init(input_event_handler);
+       }
+}
+
+static void input_event_handler_exit(void *data)
+{
+       const struct device_ops *input_device;
+
+       input_device = find_device("input");
+       if (check_default(input_device)) {
+               _E("There is no input device");
+               return;
+       }
+
+       if (input_device->exit)
+               input_device->exit(NULL);
+}
+
+static const struct device_ops input_event_handler_device_ops = {
+       DECLARE_NAME_LEN("input-event-handler"),
+       .init        = input_event_handler_init,
+       .exit        = input_event_handler_exit,
+};
+
+DEVICE_OPS_REGISTER(&input_event_handler_device_ops);
index 9b86aff..0e1d4c6 100644 (file)
@@ -46,7 +46,7 @@ static void process_event(struct libinput_event *ev)
 
        if (!display_device_ops) {
                display_device_ops = find_device("display");
-               if (!display_device_ops)
+               if (check_default(display_device_ops))
                        return;
        }
 
@@ -110,7 +110,7 @@ gboolean display_input_init(gpointer data)
        static const struct device_ops *input_device;
 
        input_device = find_device("input");
-       if (!input_device)
+       if (check_default(input_device))
                return G_SOURCE_REMOVE;
 
        _D("[%s] Initialization.", input_device->name);
@@ -125,7 +125,7 @@ int display_input_exit(void)
        static const struct device_ops *input_device;
 
        input_device = find_device("input");
-       if (!input_device)
+       if (check_default(input_device))
                return 0;
 
        input_device->exit(NULL);