Revision 78
fixed ack reading issue. added statemachine, still not working
lab4.c | ||
---|---|---|
7 | 7 |
#include "kbc.h" |
8 | 8 |
#include "errors.h" |
9 | 9 |
#include "mouse_macros.h" |
10 |
#include "kbc_macros.h" |
|
10 | 11 |
#include "timer.h" |
12 |
#include "state_machine.h" |
|
11 | 13 |
|
12 | 14 |
int main(int argc, char *argv[]) { |
13 | 15 |
// sets the language of LCF messages (can be either EN-US or PT-PT) |
... | ... | |
95 | 97 |
// return value |
96 | 98 |
int ret; |
97 | 99 |
|
100 |
if ((ret = mouse_issue_cmd(SET_REMOTE_MD))) return ret; |
|
101 |
|
|
102 |
if ((ret = mouse_set_data_report(true))) return ret; |
|
103 |
|
|
104 |
uint8_t cmd = 0; |
|
105 |
if ((ret = kbc_read_cmd(&cmd))) return ret; |
|
106 |
|
|
98 | 107 |
while (good) { |
99 | 108 |
|
100 | 109 |
if ((ret = mouse_read_data(&data))) return ret; |
... | ... | |
103 | 112 |
packet[sz] = data; |
104 | 113 |
sz++; |
105 | 114 |
} |
106 |
|
|
107 | 115 |
if (sz == 3) { |
108 | 116 |
struct packet pp = mouse_parse_packet(packet); |
109 | 117 |
mouse_print_packet(&pp); |
... | ... | |
111 | 119 |
sz = 0; |
112 | 120 |
if (packetCounter == cnt) good = 0; |
113 | 121 |
} |
114 |
|
|
115 | 122 |
tickdelay(micros_to_ticks(period*1e3)); |
116 | 123 |
} |
117 | 124 |
|
... | ... | |
119 | 126 |
if ((ret = mouse_issue_cmd(SET_STREAM_MD))) return ret; |
120 | 127 |
// Disable data reporting |
121 | 128 |
if ((ret = mouse_set_data_report(false))) return ret; |
122 |
|
|
123 | 129 |
uint8_t cmd_byte = minix_get_dflt_kbc_cmd_byte(); |
124 | 130 |
if ((ret = kbc_change_cmd(cmd_byte))) return ret; |
125 | 131 |
|
... | ... | |
188 | 194 |
return 0; |
189 | 195 |
} |
190 | 196 |
|
191 |
enum state{ |
|
192 |
STATE_NEUTRAL, |
|
193 |
STATE_FIRST, |
|
194 |
STATE_MID, |
|
195 |
STATE_SECOND |
|
196 |
}; |
|
197 |
|
|
198 | 197 |
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) { |
199 |
int ret = 0; |
|
200 | 198 |
/// loop stuff |
201 | 199 |
int ipc_status, r; |
202 | 200 |
message msg; |
... | ... | |
205 | 203 |
int mouse_id = 0; |
206 | 204 |
int mouse_irq = BIT(mouse_irq_bit); |
207 | 205 |
//if ((ret = mouse_set_data_report(true))) return ret; |
208 |
if ((ret = mouse_enable_data_reporting())) return ret;
|
|
206 |
if (mouse_enable_data_reporting()) return 1;
|
|
209 | 207 |
|
210 | 208 |
if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; |
211 | 209 |
/// cycle |
212 | 210 |
int good = 1; |
213 |
//int st = STATE_NEUTRAL; |
|
214 |
//int16_t dx, dy; |
|
211 |
|
|
212 |
// mouse event gesture |
|
213 |
struct mouse_ev *event; |
|
214 |
struct packet pp; |
|
215 |
int response; |
|
216 |
|
|
215 | 217 |
while (good) { |
216 | 218 |
/* Get a request message. */ |
217 | 219 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
... | ... | |
223 | 225 |
case HARDWARE: /* hardware interrupt notification */ |
224 | 226 |
if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */ |
225 | 227 |
mouse_ih(); |
226 |
if(counter >= 3){ |
|
227 |
struct packet pp = mouse_parse_packet(packet); |
|
228 |
mouse_print_packet(&pp);/* |
|
229 |
switch(st){ |
|
230 |
case STATE_NEUTRAL: |
|
231 |
if(pp.lb == 1 && pp.mb == 0 && pp.rb == 0){ |
|
232 |
st = STATE_FIRST; |
|
233 |
dx = 0; |
|
234 |
dy = 0; |
|
235 |
} |
|
236 |
break; |
|
237 |
case STATE_FIRST: |
|
238 |
if(pp.lb == 1){ |
|
239 |
if(pp.delta_x >= -tolerance && pp.delta_y >= -tolerance){ |
|
240 |
dx += pp.delta_x; |
|
241 |
dy += pp.delta_y; |
|
242 |
}else{ |
|
243 |
st = STATE_NEUTRAL; |
|
244 |
} |
|
245 |
}else{ |
|
246 |
if(abs(dx) < abs(dy) && dx > 0 && dy > 0){ |
|
247 |
st = STATE_MID; |
|
248 |
}else{ |
|
249 |
st = STATE_NEUTRAL; |
|
250 |
} |
|
251 |
} |
|
252 |
break; |
|
253 |
case STATE_MID: |
|
254 |
if(pp.lb == 0 && pp.mb == 0 && pp.rb == 1){ |
|
255 |
st = STATE_SECOND; |
|
256 |
dx = 0; |
|
257 |
dy = 0; |
|
258 |
}else{ |
|
259 |
st = STATE_NEUTRAL; |
|
260 |
} |
|
261 |
break; |
|
262 |
case STATE_SECOND: |
|
263 |
if(pp.rb == 1){ |
|
264 |
if(pp.delta_x >= -tolerance && pp.delta_y <= tolerance){ |
|
265 |
dx += pp.delta_x; |
|
266 |
dy += pp.delta_y; |
|
267 |
}else{ |
|
268 |
st = STATE_NEUTRAL; |
|
269 |
} |
|
270 |
}else{ |
|
271 |
if(abs(dx) < abs(dy) && dx > 0 && dy < 0){ |
|
272 |
st = STATE_NEUTRAL; |
|
273 |
good = false; |
|
274 |
}else{ |
|
275 |
st = STATE_NEUTRAL; |
|
276 |
} |
|
277 |
} |
|
278 |
break; |
|
279 |
default: |
|
280 |
return OTHER_ERROR; |
|
281 |
break; |
|
282 |
}*/ |
|
228 |
if(counter >= 3) { |
|
229 |
pp = mouse_parse_packet(packet); |
|
230 |
//mouse_print_packet(&pp); |
|
231 |
event = mouse_get_event(&pp); |
|
232 |
|
|
233 |
response = state_machine(event, x_len, tolerance); |
|
234 |
|
|
235 |
if (response == SUCCESS) |
|
236 |
good = 0; |
|
237 |
else if (response == INVALID_STATE) |
|
238 |
return response; |
|
283 | 239 |
} |
284 | 240 |
} |
285 | 241 |
break; |
Also available in: Unified diff