#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;
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) {
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) {
_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;