input: support powerkey shortpress for iot-headless 71/265571/3 submit/tizen/20211103.072537 submit/tizen/20211104.031932
authorYoungjae Cho <y0.cho@samsung.com>
Fri, 22 Oct 2021 07:32:21 +0000 (16:32 +0900)
committerYoungjae Cho <y0.cho@samsung.com>
Mon, 1 Nov 2021 08:11:51 +0000 (17:11 +0900)
Change-Id: I0451471b0b17746e30e159c7ac5e0e7395fd39e1
Signed-off-by: Youngjae Cho <y0.cho@samsung.com>
plugins/iot-headless/input/input-handler.c
src/shared/device-notifier.h

index ae25482..69b619e 100644 (file)
 
 #include "shared/common.h"
 #include "shared/devices.h"
+#include "shared/device-notifier.h"
 #include "shared/log.h"
 
 #define KEYVALUE_PRESS       1
 #define KEYVALUE_RELEASE     0
 
 #define LONGPRESS_INTERVAL   10000   /* milisecond */
+#define SHORTPRESS_INTERVAL  3000    /* milisecond */
 
 static int longpress_interval = LONGPRESS_INTERVAL;
+static int shortpress_interval = SHORTPRESS_INTERVAL;
+static guint shortpress_timer_id;
 static guint longpress_timer_id;
 
+static gboolean shortpressed_cb(void *data)
+{
+       shortpress_timer_id = 0;
+
+       return G_SOURCE_REMOVE;
+}
+
 static gboolean longpressed_cb(void *data)
 {
        const struct device_ops *power_device;
@@ -43,13 +54,23 @@ static gboolean longpressed_cb(void *data)
                return G_SOURCE_REMOVE;
 
        if (power_device->execute) {
-               _D("powerkey long pressed, start poweroff sequence");
+               _D("powerkey long pressed");
                power_device->execute("poweroff");
        }
 
        return G_SOURCE_REMOVE;
 }
 
+static void start_shortpress_timer(void)
+{
+       if (shortpress_timer_id) {
+               g_source_remove(shortpress_timer_id);
+               shortpress_timer_id = 0;
+       }
+
+       shortpress_timer_id = g_timeout_add(shortpress_interval, shortpressed_cb, NULL);
+}
+
 static void start_longpress_timer(void)
 {
        if (longpress_timer_id) {
@@ -60,6 +81,17 @@ static void start_longpress_timer(void)
        longpress_timer_id = g_timeout_add(longpress_interval, longpressed_cb, NULL);
 }
 
+static void stop_shortpress_timer(void)
+{
+       if (shortpress_timer_id) {
+               g_source_remove(shortpress_timer_id);
+               shortpress_timer_id = 0;
+       } else {
+               _D("powerkey short pressed");
+               device_notify(DEVICE_NOTIFIER_KEY_SHORTPRESS, (void *)(intptr_t) KEY_POWER);
+       }
+}
+
 static void stop_longpress_timer(void)
 {
        if (longpress_timer_id) {
@@ -89,10 +121,13 @@ static int input_handler_execute(void *data)
        _D("key input: code=%d, value=%d", keycode, keyvalue);
 
        if (keycode == KEY_POWER) {
-               if (keyvalue == KEYVALUE_PRESS)
+               if (keyvalue == KEYVALUE_PRESS) {
+                       start_shortpress_timer();
                        start_longpress_timer();
-               else if (keyvalue == KEYVALUE_RELEASE)
+               } else if (keyvalue == KEYVALUE_RELEASE) {
+                       stop_shortpress_timer();
                        stop_longpress_timer();
+               }
        }
 
        return 0;
index ba597b1..72d2ed8 100644 (file)
@@ -61,6 +61,7 @@ enum device_notifier_type {
        DEVICE_NOTIFIER_ULTRAPOWERSAVING,
        DEVICE_NOTIFIER_EXTCON_COUNT,
        DEVICE_NOTIFIER_REQUEST_WAKE_LOCK,
+       DEVICE_NOTIFIER_KEY_SHORTPRESS, /* hold down a key for a short duration */
        DEVICE_NOTIFIER_REQUEST_WAKE_UNLOCK,
        DEVICE_NOTIFIER_MAX,
 };