@@ -23,9 +23,12 @@ static rt_uint32_t cur_range[2];
23
23
static rt_uint32_t cur_points [2 ];
24
24
static rt_uint32_t cur_last_points [2 ];
25
25
static rt_bool_t cur_event_sync ;
26
+ static rt_uint32_t color [2 ] = { 0xff0000 , 0x0000ff };
26
27
27
28
void tablet_event_handler (struct virtio_input_event event )
28
29
{
30
+ static rt_bool_t cur_btn_down = RT_FALSE ;
31
+
29
32
if (event .type == EV_ABS )
30
33
{
31
34
if (event .code == 0 )
@@ -37,6 +40,24 @@ void tablet_event_handler(struct virtio_input_event event)
37
40
cur_points [1 ] = (cur_max [1 ] * (event .value - cur_min [1 ]) + cur_range [1 ] / 2 ) / cur_range [1 ];
38
41
}
39
42
}
43
+ else if (event .type == EV_KEY )
44
+ {
45
+ if (event .code == BTN_LEFT )
46
+ {
47
+ if (cur_btn_down && event .value == 0 )
48
+ {
49
+ color [0 ] ^= color [1 ];
50
+ color [1 ] ^= color [0 ];
51
+ color [0 ] ^= color [1 ];
52
+ cur_btn_down = RT_FALSE ;
53
+ cur_event_sync = RT_TRUE ;
54
+ }
55
+ else
56
+ {
57
+ cur_btn_down = RT_TRUE ;
58
+ }
59
+ }
60
+ }
40
61
else if (event .type == EV_SYN )
41
62
{
42
63
cur_event_sync = RT_TRUE ;
@@ -52,8 +73,6 @@ void graphic_thread(void *param)
52
73
rt_device_t tablet_dev = RT_NULL ;
53
74
struct virtio_input_config tablet_config ;
54
75
55
- rt_uint32_t red = 0xff0000 ;
56
- rt_uint32_t blue = 0x0000ff ;
57
76
rt_uint32_t white = 0xffffff ;
58
77
rt_device_t gpu_dev = RT_NULL ;
59
78
struct rt_device_rect_info rect_info ;
@@ -87,15 +106,13 @@ void graphic_thread(void *param)
87
106
cur_last_points [0 ] = graphic_info .width / 2 ;
88
107
cur_last_points [1 ] = graphic_info .height / 2 ;
89
108
90
- virtio_gpu_graphic_ops -> draw_hline ((char * )& red , 0 , graphic_info .width , cur_last_points [1 ]);
91
- virtio_gpu_graphic_ops -> draw_vline ((char * )& blue , cur_last_points [0 ], 0 , graphic_info .height );
109
+ virtio_gpu_graphic_ops -> draw_hline ((char * )& color [ 0 ] , 0 , graphic_info .width , cur_last_points [1 ]);
110
+ virtio_gpu_graphic_ops -> draw_vline ((char * )& color [ 1 ] , cur_last_points [0 ], 0 , graphic_info .height );
92
111
93
112
rt_device_control (device , RTGRAPHIC_CTRL_RECT_UPDATE , & rect_info );
94
113
95
114
gpu_dev = device ;
96
115
}
97
-
98
- rt_device_close (device );
99
116
}
100
117
101
118
/* Keyboard, Mouse, Tablet */
@@ -153,8 +170,8 @@ void graphic_thread(void *param)
153
170
cur_last_points [0 ] = cur_points [0 ];
154
171
cur_last_points [1 ] = cur_points [1 ];
155
172
156
- virtio_gpu_graphic_ops -> draw_hline ((char * )& red , 0 , graphic_info .width , cur_last_points [1 ]);
157
- virtio_gpu_graphic_ops -> draw_vline ((char * )& blue , cur_last_points [0 ], 0 , graphic_info .height );
173
+ virtio_gpu_graphic_ops -> draw_hline ((char * )& color [ 0 ] , 0 , graphic_info .width , cur_last_points [1 ]);
174
+ virtio_gpu_graphic_ops -> draw_vline ((char * )& color [ 1 ] , cur_last_points [0 ], 0 , graphic_info .height );
158
175
159
176
rt_device_control (gpu_dev , RTGRAPHIC_CTRL_RECT_UPDATE , & rect_info );
160
177
0 commit comments