Revision 56
implementing mouse_parse_packet
lab4/lab4.c | ||
---|---|---|
29 | 29 |
return 0; |
30 | 30 |
} |
31 | 31 |
|
32 |
extern uint8_t packet[3]; |
|
33 |
extern int counter; |
|
32 | 34 |
|
33 | 35 |
int (mouse_test_packet)(uint32_t cnt) { |
34 | 36 |
/// loop stuff |
... | ... | |
42 | 44 |
if(mouse_enable_data_reporting()) return 1; |
43 | 45 |
/// cycle |
44 | 46 |
int good = 1; |
47 |
uint32_t cnt_now = 0; |
|
45 | 48 |
while (good) { |
46 | 49 |
/* Get a request message. */ |
47 | 50 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
... | ... | |
53 | 56 |
case HARDWARE: /* hardware interrupt notification */ |
54 | 57 |
if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */ |
55 | 58 |
mouse_ih(); |
59 |
if(counter >= 3){ |
|
60 |
struct packet pp = mouse_parse_packet(packet); |
|
61 |
mouse_print_packet(&pp); |
|
62 |
cnt_now++; |
|
63 |
if(cnt == cnt_now) good = 0; |
|
64 |
} |
|
56 | 65 |
/* |
57 | 66 |
if (!(two_byte_scancode || got_error)) { // finished processing a scancode |
58 | 67 |
if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode); |
lab4/mouse_func.c | ||
---|---|---|
17 | 17 |
if (sys_irqrmpolicy(interrupt_id)) return UNSBCR_ERROR; |
18 | 18 |
return SUCCESS; |
19 | 19 |
} |
20 |
|
|
21 |
int got_error = 0; |
|
22 |
uint8_t packet[3]; |
|
23 |
int counter = 0; |
|
24 |
|
|
25 |
void (mouse_ih)(void) { |
|
26 |
uint8_t status = 0; |
|
27 |
got_error = 0; |
|
28 |
|
|
29 |
if (util_sys_inb(STATUS_REG, &status)) { |
|
30 |
got_error = 1; |
|
31 |
return; |
|
32 |
} |
|
33 |
|
|
34 |
if (status & (TIME_OUT_REC | PARITY_ERROR)) { |
|
35 |
got_error = 1; |
|
36 |
return; |
|
37 |
} |
|
38 |
|
|
39 |
uint8_t byte = 0; |
|
40 |
|
|
41 |
if (util_sys_inb(OUTPUT_BUF, &byte)) { |
|
42 |
got_error = 1; |
|
43 |
return; |
|
44 |
} |
|
45 |
|
|
46 |
if(counter >= 3) counter = 0; |
|
47 |
packet[counter] = byte; |
|
48 |
counter++; |
|
49 |
|
|
50 |
} |
|
51 |
|
|
52 |
struct packet (mouse_parse_packet)(const uint8_t *packet_bytes){ |
|
53 |
struct packet pp; |
|
54 |
pp.bytes[0] = packet_bytes[0]; |
|
55 |
pp.bytes[1] = packet_bytes[1]; |
|
56 |
pp.bytes[2] = packet_bytes[2]; |
|
57 |
pp.rb = pp.bytes[0] & RIGHT_BUTTON; |
|
58 |
pp.mb = pp.bytes[0] & MIDDLE_BUTTON; |
|
59 |
pp.lb = pp.bytes[0] & LEFT_BUTTON; |
|
60 |
//pp.delta_x = |
|
61 |
return pp; |
|
62 |
} |
lab4/mouse_func.h | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
int (unsubscribe_interrupt)(int *interrupt_id); |
23 | 23 |
|
24 |
struct packet (mouse_parse_packet)(const uint8_t *packet_bytes); |
|
25 |
|
|
24 | 26 |
#endif /* end of include guard: _MOUSE_FUNC_H_ */ |
Also available in: Unified diff