root / lab4 / lab4.c @ 57
History | View | Annotate | Download (3.55 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include <stdint.h> |
4 |
#include <stdio.h> |
5 |
|
6 |
#include "mouse_func.h" |
7 |
#include "kbc_func.h" |
8 |
|
9 |
int main(int argc, char *argv[]) { |
10 |
// sets the language of LCF messages (can be either EN-US or PT-PT)
|
11 |
lcf_set_language("EN-US");
|
12 |
|
13 |
// enables to log function invocations that are being "wrapped" by LCF
|
14 |
// [comment this out if you don't want/need/ it]
|
15 |
lcf_trace_calls("/home/lcom/labs/lab4/trace.txt");
|
16 |
|
17 |
// enables to save the output of printf function calls on a file
|
18 |
// [comment this out if you don't want/need it]
|
19 |
lcf_log_output("/home/lcom/labs/lab4/output.txt");
|
20 |
|
21 |
// handles control over to LCF
|
22 |
// [LCF handles command line arguments and invokes the right function]
|
23 |
if (lcf_start(argc, argv))
|
24 |
return 1; |
25 |
|
26 |
// LCF clean up tasks
|
27 |
// [must be the last statement before return]
|
28 |
lcf_cleanup(); |
29 |
|
30 |
return 0; |
31 |
} |
32 |
|
33 |
extern uint8_t packet[3]; |
34 |
extern int counter; |
35 |
|
36 |
int (mouse_test_packet)(uint32_t cnt) {
|
37 |
/// loop stuff
|
38 |
int ipc_status, r;
|
39 |
message msg; |
40 |
/// Keyboard interrupt handling
|
41 |
uint8_t mouse_irq_bit = 12;
|
42 |
int mouse_id = 0; |
43 |
int mouse_irq = BIT(mouse_irq_bit);
|
44 |
if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; |
45 |
if(mouse_enable_data_reporting()) return 1; |
46 |
/// cycle
|
47 |
int good = 1; |
48 |
uint32_t cnt_now = 0;
|
49 |
while (good) {
|
50 |
/* Get a request message. */
|
51 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
52 |
printf("driver_receive failed with %d", r);
|
53 |
continue;
|
54 |
} |
55 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
56 |
switch (_ENDPOINT_P(msg.m_source)) {
|
57 |
case HARDWARE: /* hardware interrupt notification */ |
58 |
if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */ |
59 |
mouse_ih(); |
60 |
if(counter >= 3){ |
61 |
struct packet pp = mouse_parse_packet(packet);
|
62 |
mouse_print_packet(&pp); |
63 |
cnt_now++; |
64 |
if(cnt == cnt_now) good = 0; |
65 |
} |
66 |
/*
|
67 |
if (!(two_byte_scancode || got_error)) { // finished processing a scancode
|
68 |
if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
|
69 |
else kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
|
70 |
} else { break; }
|
71 |
if (scancode[0] == ESC_BREAK_CODE) good = 0;
|
72 |
*/
|
73 |
} |
74 |
break;
|
75 |
default:
|
76 |
break; /* no other notifications expected: do nothing */ |
77 |
} |
78 |
} else { /* received standart message, not a notification */ |
79 |
/* no standart message expected: do nothing */
|
80 |
} |
81 |
} |
82 |
|
83 |
if (unsubscribe_interrupt(&mouse_id)) return 1; |
84 |
if(kbc_restore_kbd()) return 1; |
85 |
|
86 |
return 0; |
87 |
} |
88 |
|
89 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) {
|
90 |
/* To be completed */
|
91 |
printf("%s(%u, %u): under construction\n", __func__, period, cnt);
|
92 |
return 1; |
93 |
} |
94 |
|
95 |
int (mouse_test_async)(uint8_t idle_time) {
|
96 |
/* To be completed */
|
97 |
printf("%s(%u): under construction\n", __func__, idle_time);
|
98 |
return 1; |
99 |
} |
100 |
|
101 |
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {
|
102 |
/* To be completed */
|
103 |
printf("%s: under construction\n", __func__);
|
104 |
return 1; |
105 |
} |