root / lab4 / lab4.c @ 15
History | View | Annotate | Download (3.33 KB)
1 |
// IMPORTANT: you must include the following line in all your C files
|
---|---|
2 |
#include <lcom/lcf.h> |
3 |
|
4 |
#include <stdint.h> |
5 |
#include <stdio.h> |
6 |
#include "mouse.h" |
7 |
|
8 |
// Any header files included below this line should have been created by you
|
9 |
|
10 |
int main(int argc, char *argv[]) { |
11 |
// sets the language of LCF messages (can be either EN-US or PT-PT)
|
12 |
lcf_set_language("EN-US");
|
13 |
|
14 |
// enables to log function invocations that are being "wrapped" by LCF
|
15 |
// [comment this out if you don't want/need/ it]
|
16 |
lcf_trace_calls("/home/lcom/labs/lab4/trace.txt");
|
17 |
|
18 |
// enables to save the output of printf function calls on a file
|
19 |
// [comment this out if you don't want/need it]
|
20 |
lcf_log_output("/home/lcom/labs/lab4/output.txt");
|
21 |
|
22 |
// handles control over to LCF
|
23 |
// [LCF handles command line arguments and invokes the right function]
|
24 |
if (lcf_start(argc, argv))
|
25 |
return 1; |
26 |
|
27 |
// LCF clean up tasks
|
28 |
// [must be the last statement before return]
|
29 |
lcf_cleanup(); |
30 |
|
31 |
return 0; |
32 |
} |
33 |
|
34 |
extern uint8_t byte;
|
35 |
|
36 |
int (mouse_test_packet)(uint32_t cnt) {
|
37 |
int r, ipc_status;
|
38 |
uint8_t mouse_irq, size=0; //size of mouse packet is 3 byte long |
39 |
message msg; |
40 |
uint32_t counter_copy=cnt; |
41 |
|
42 |
struct packet pp;
|
43 |
|
44 |
if(mouse_enable_data_reporting()!=0){ //check if disabling stream mode worked |
45 |
printf("Error disabling stream mode\n");
|
46 |
return 1; |
47 |
} |
48 |
|
49 |
if(mouse_subscribe_int(&kmouse_irq)!=0){ //check if subscription worked |
50 |
printf("Error subscribing int\n");
|
51 |
return 1; |
52 |
} |
53 |
|
54 |
while(counter_copy>0){ //looping until counter>0 |
55 |
|
56 |
if ((r = driver_receive(ANY, &msg, &ipc_status))==1){ |
57 |
printf("driver_receive failed with: %d",r);
|
58 |
continue;
|
59 |
} |
60 |
if (is_ipc_notify(ipc_status)){ //received notification |
61 |
switch (_ENDPOINT_P(msg.m_source)){
|
62 |
case HARDWARE: //hardware interrupt notification |
63 |
if (msg.m_notify.interrupts &mouse_irq){ // subscribed interrupt |
64 |
|
65 |
mouse_ih(); |
66 |
if((size==0 && ((byte&0x08)==0x08)) || size==1 ||size==2){ //0x08 is the mask to check if the 3rd bit of the first byte is set |
67 |
pp.bytes[size]=byte; |
68 |
size++; |
69 |
} |
70 |
if(size==3){ |
71 |
size=0;
|
72 |
parse_packet(&pp); |
73 |
mouse_print_packet(&pp); |
74 |
counter_copy--; |
75 |
} |
76 |
} |
77 |
break;
|
78 |
default:
|
79 |
break; //no other notifications expected: do nothing |
80 |
} |
81 |
} |
82 |
else { //received a standard message, not a notification |
83 |
//no standard messages expected: do nothing
|
84 |
} |
85 |
} |
86 |
|
87 |
if (mouse_unsubscribe_int() != 0) { //check if unsubscription worked |
88 |
printf("Error unsubscribing int \n");
|
89 |
return 1; |
90 |
} |
91 |
scan_code=0;
|
92 |
|
93 |
return 0; |
94 |
} |
95 |
|
96 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) {
|
97 |
/* To be completed */
|
98 |
printf("%s(%u, %u): under construction\n", __func__, period, cnt);
|
99 |
return 1; |
100 |
} |
101 |
|
102 |
int (mouse_test_async)(uint8_t idle_time) {
|
103 |
/* To be completed */
|
104 |
printf("%s(%u): under construction\n", __func__, idle_time);
|
105 |
return 1; |
106 |
} |
107 |
|
108 |
int (mouse_test_gesture)() {
|
109 |
/* To be completed */
|
110 |
printf("%s: under construction\n", __func__);
|
111 |
return 1; |
112 |
} |