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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
|
/*
* emulator controller client
*
* Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact:
* Kitae Kim <kt920.kim@samsung.com>
* JiHye Kim <jihye1128.kim@samsung.com>
* YeongKyoon Lee <yeongkyoon.lee@samsung.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
* Contributors:
* - S-Core Co., Ltd
*
*/
#include "emulator_common.h"
#include "emul_state.h"
#include "common.h"
#include "touch.h"
#include "encode_fb.h"
#include "genmsg/eventcast.pb-c.h"
#include "ecs/ecs_eventcast.h"
#include "util/new_debug_ch.h"
DECLARE_DEBUG_CHANNEL(eventcast);
static int touch_device_status;
static bool send_display_image_data(void);
#define HARD_KEY_MENU 169
#define HARD_KEY_BACK 158
static bool build_touch_msg(Eventcast__TouchMsg *touch)
{
bool ret = false;
Eventcast__EventCastMsg msg = EVENTCAST__EVENT_CAST_MSG__INIT;
LOG_TRACE("enter: %s\n", __func__);
msg.type = EVENTCAST__EVENT_CAST_MSG__TYPE__TOUCH_MSG;
msg.touchmsg = touch;
LOG_TRACE("touch message size: %d\n", eventcast__event_cast_msg__get_packed_size(&msg));
ret = send_msg_to_controller(&msg);
LOG_TRACE("leave: %s, ret: %d\n", __func__, ret);
return ret;
}
static bool send_touch_start_ans_msg(Eventcast__MessageResult result)
{
bool ret = false;
Eventcast__TouchMsg mt = EVENTCAST__TOUCH_MSG__INIT;
Eventcast__StartAns start_ans = EVENTCAST__START_ANS__INIT;
LOG_TRACE("enter: %s\n", __func__);
start_ans.result = result;
mt.type = EVENTCAST__TOUCH_MSG__TYPE__START_ANS;
mt.startans = &start_ans;
ret = build_touch_msg(&mt);
LOG_TRACE("leave: %s, ret: %d\n", __func__, ret);
return ret;
}
static bool send_set_touch_max_count(void)
{
bool ret = false;
Eventcast__TouchMsg mt = EVENTCAST__TOUCH_MSG__INIT;
Eventcast__TouchMaxCount touch_cnt =
EVENTCAST__TOUCH_MAX_COUNT__INIT;
LOG_TRACE("enter: %s\n", __func__);
touch_cnt.max = get_max_touch_point();
mt.type = EVENTCAST__TOUCH_MSG__TYPE__MAX_COUNT;
mt.maxcount = &touch_cnt;
LOG_TRACE("send touch max count: %d\n", touch_cnt.max);
ret = build_touch_msg(&mt);
LOG_TRACE("leave: %s, ret: %d\n", __func__, ret);
return ret;
}
static void set_touch_data(Eventcast__TouchData *data)
{
float x = 0.0, y = 0.0;
int32_t index = 0, state = 0;
switch(data->state) {
case EVENTCAST__TOUCH_STATE__PRESSED:
LOG_TRACE("touch pressed\n");
index = data->index;
x = data->xpoint;
y = data->ypoint;
state = PRESSED;
break;
case EVENTCAST__TOUCH_STATE__RELEASED:
LOG_TRACE("touch released\n");
index = data->index;
x = data->xpoint;
y = data->ypoint;
state = RELEASED;
break;
default:
LOG_TRACE("invalid touch data\n");
break;
}
LOG_TRACE("set touch_data. index: %d, x: %lf, y: %lf\n", index, x, y);
send_eventcast_touch_data(x, y, index, state);
}
static bool send_set_touch_resolution(void)
{
bool ret = false;
Eventcast__TouchMsg mt = EVENTCAST__TOUCH_MSG__INIT;
Eventcast__Resolution resolution = EVENTCAST__RESOLUTION__INIT;
LOG_TRACE("enter: %s\n", __func__);
resolution.width = get_display_resolution_width();
resolution.height = get_display_resolution_height();
mt.type = EVENTCAST__TOUCH_MSG__TYPE__RESOLUTION;
mt.resolution = &resolution;
LOG_TRACE("send touch resolution: %dx%d\n",
resolution.width, resolution.height);
ret = build_touch_msg(&mt);
LOG_TRACE("leave: %s, ret: %d\n", __func__, ret);
return ret;
}
static void set_hwkey_data(Eventcast__HWKeyMsg *msg)
{
int32_t keycode = 0;
switch (msg->type) {
case EVENTCAST__HWKEY_TYPE__MENU:
keycode = HARD_KEY_MENU;
break;
case EVENTCAST__HWKEY_TYPE__HOME:
keycode = HARD_KEY_HOME;
break;
case EVENTCAST__HWKEY_TYPE__BACK:
keycode = HARD_KEY_BACK;
break;
case EVENTCAST__HWKEY_TYPE__POWER:
keycode = HARD_KEY_POWER;
break;
case EVENTCAST__HWKEY_TYPE__VOLUME_UP:
keycode = HARD_KEY_VOL_UP;
break;
case EVENTCAST__HWKEY_TYPE__VOLUME_DOWN:
keycode = HARD_KEY_VOL_DOWN;
break;
default:
LOG_WARNING("undefined type: %d\n", msg->type);
}
LOG_TRACE("convert hwkey msg to keycode: %d\n", keycode);
send_eventcast_hwkey_data(keycode);
}
bool msgproc_eventcast_touch_msg(void *message)
{
bool ret = true;
Eventcast__TouchMsg *msg = (Eventcast__TouchMsg *)message;
switch(msg->type) {
case EVENTCAST__TOUCH_MSG__TYPE__START_REQ:
LOG_TRACE("TOUCH_MSG_TYPE_START\n");
send_set_touch_max_count();
send_set_touch_resolution();
ret = send_touch_start_ans_msg(EVENTCAST__MESSAGE_RESULT__SUCCESS);
break;
case EVENTCAST__TOUCH_MSG__TYPE__TERMINATE:
LOG_TRACE("TOUCH_MSG_TYPE_TERMINATE\n");
break;
case EVENTCAST__TOUCH_MSG__TYPE__TOUCH_DATA:
LOG_TRACE("TOUCH_MSG_TYPE_TOUCH_DATA\n");
set_touch_data(msg->touchdata);
break;
case EVENTCAST__TOUCH_MSG__TYPE__DISPLAY_MSG:
LOG_TRACE("TOUCH_MSG_TYPE_DISPLAY_MSG\n");
if (is_display_dirty()) {
LOG_TRACE("display dirty status!! send the image\n");
send_display_image_data();
set_display_dirty(false);
}
break;
case EVENTCAST__TOUCH_MSG__TYPE__HWKEY_MSG:
LOG_TRACE("TOUCH_MSG_TYPE_HWKEY_MSG\n");
set_hwkey_data(msg->hwkey);
break;
default:
LOG_TRACE("invalid touch_msg\n");
ret = false;
break;
}
return ret;
}
int get_eventcast_touch_status(void)
{
return touch_device_status;
}
void set_eventcast_touch_status(int status)
{
touch_device_status = status;
send_eventcast_touch_status_ecp();
}
static void dump_display_image_data(struct encode_mem *image)
{
#ifdef IMAGE_DUMP
FILE *fp = NULL;
fp = fopen("display_image_dump.png", "wb");
if (fp != NULL) {
fwrite(image->buffer, 1, image->length, fp);
fclose(fp);
}
#endif
}
static bool send_display_image_data(void)
{
bool ret = false;
struct encode_mem *image = NULL;
Eventcast__TouchMsg touch = EVENTCAST__TOUCH_MSG__INIT;
Eventcast__DisplayMsg display = EVENTCAST__DISPLAY_MSG__INIT;
LOG_TRACE("enter: %s\n", __func__);
image = (struct encode_mem *)encode_framebuffer(ENCODE_PNG);
if (!image) {
LOG_SEVERE("failed to encode framebuffer\n");
return false;
}
dump_display_image_data(image);
LOG_TRACE("image data size %d\n", image->length);
display.has_imagedata = true;
display.imagedata.len = image->length;
display.imagedata.data = image->buffer;
touch.type = EVENTCAST__TOUCH_MSG__TYPE__DISPLAY_MSG;
touch.display = &display;
ret = build_touch_msg(&touch);
LOG_TRACE("send display message: %d\n", ret);
g_free(image->buffer);
g_free(image);
LOG_TRACE("leave: %s, ret: %d\n", __func__, ret);
return ret;
}
|