-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtap.c
98 lines (82 loc) · 1.74 KB
/
tap.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* SPDX-License-Identifier: ISC
*
* Copyright (c) 2022 Codethink
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include "cmd/cmd.h"
#include "cmd/private.h"
#include "msg/msg.h"
#include "util/cli.h"
#include "util/log.h"
#include "util/util.h"
static struct tap_ctx {
int64_t x;
int64_t y;
} tap_ctx;
static const struct cli_table_entry cli_entries[] = {
CMD_CLI_COMMON("tap"),
{
.p = true,
.l = "X",
.t = CLI_INT,
.v.i = &tap_ctx.x,
.d = "X coordinate to tap (px from top edge)."
},
{
.p = true,
.l = "Y",
.t = CLI_INT,
.v.i = &tap_ctx.y,
.d = "Y coordinate to tap (px from left edge)."
},
};
static const struct cli_table cli = {
.entries = cli_entries,
.count = (sizeof(cli_entries))/(sizeof(*cli_entries)),
.min_positional = 4,
};
static bool cmd_tap_init(int argc, const char **argv,
struct cmd_options *options, void **pw_out)
{
int id;
if (!cmd_cli_parse(argc, argv, &cli, options)) {
return false;
}
msg_queue_for_send(&(const struct msg)
{
.type = MSG_TYPE_TOUCH_EVENT_START,
.data = {
.touch_event = {
.x = (int)tap_ctx.x,
.y = (int)tap_ctx.y,
},
},
}, &id);
msg_queue_for_send(&(const struct msg)
{
.type = MSG_TYPE_TOUCH_EVENT_END,
}, &id);
*pw_out = NULL;
return true;
}
static void cmd_tap_msg(void *pw, int id, const char *msg, size_t len)
{
(void)(pw);
cdt_log(CDT_LOG_NOTICE, "Received message with id %i: %*s",
id, (int)len, msg);
}
static void cmd_tap_help(int argc, const char **argv);
const struct cmd_table cmd_tap = {
.cmd = "tap",
.init = cmd_tap_init,
.help = cmd_tap_help,
.msg = cmd_tap_msg,
};
static void cmd_tap_help(int argc, const char **argv)
{
cli_help(&cli, (argc > 0) ? argv[0] : "cdt");
}