root / lab4 / lab4.c @ 73
History | View | Annotate | Download (3.93 KB)
1 |
#include <lcom/lcf.h> |
---|---|
2 |
|
3 |
#include <stdint.h> |
4 |
#include <stdio.h> |
5 |
|
6 |
#include "mouse.h" |
7 |
#include "kbc.h" |
8 |
#include "errors.h" |
9 |
#include "mouse_macros.h" |
10 |
|
11 |
int main(int argc, char *argv[]) { |
12 |
// sets the language of LCF messages (can be either EN-US or PT-PT)
|
13 |
lcf_set_language("EN-US");
|
14 |
|
15 |
// enables to log function invocations that are being "wrapped" by LCF
|
16 |
// [comment this out if you don't want/need/ it]
|
17 |
lcf_trace_calls("/home/lcom/labs/lab4/trace.txt");
|
18 |
|
19 |
// enables to save the output of printf function calls on a file
|
20 |
// [comment this out if you don't want/need it]
|
21 |
lcf_log_output("/home/lcom/labs/lab4/output.txt");
|
22 |
|
23 |
// handles control over to LCF
|
24 |
// [LCF handles command line arguments and invokes the right function]
|
25 |
if (lcf_start(argc, argv))
|
26 |
return 1; |
27 |
|
28 |
// LCF clean up tasks
|
29 |
// [must be the last statement before return]
|
30 |
lcf_cleanup(); |
31 |
|
32 |
return 0; |
33 |
} |
34 |
|
35 |
extern uint8_t packet[3]; |
36 |
extern int counter; |
37 |
|
38 |
int (mouse_test_packet)(uint32_t cnt) {
|
39 |
/// loop stuff
|
40 |
int ipc_status, r;
|
41 |
message msg; |
42 |
/// Keyboard interrupt handling
|
43 |
uint8_t mouse_irq_bit = 12;
|
44 |
int mouse_id = 0; |
45 |
int mouse_irq = BIT(mouse_irq_bit);
|
46 |
if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1; |
47 |
if (mouse_set_data_report(true)) return 1; |
48 |
/// cycle
|
49 |
int good = 1; |
50 |
uint32_t cnt_now = 0;
|
51 |
while (good) {
|
52 |
/* Get a request message. */
|
53 |
if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) { |
54 |
printf("driver_receive failed with %d", r);
|
55 |
continue;
|
56 |
} |
57 |
if (is_ipc_notify(ipc_status)) { /* received notification */ |
58 |
switch (_ENDPOINT_P(msg.m_source)) {
|
59 |
case HARDWARE: /* hardware interrupt notification */ |
60 |
if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */ |
61 |
mouse_ih(); |
62 |
if(counter >= 3){ |
63 |
struct packet pp = mouse_parse_packet(packet);
|
64 |
mouse_print_packet(&pp); |
65 |
cnt_now++; |
66 |
if(cnt == cnt_now) good = 0; |
67 |
} |
68 |
} |
69 |
break;
|
70 |
default:
|
71 |
break; /* no other notifications expected: do nothing */ |
72 |
} |
73 |
} else { /* received standart message, not a notification */ |
74 |
/* no standart message expected: do nothing */
|
75 |
} |
76 |
} |
77 |
|
78 |
if (unsubscribe_interrupt(&mouse_id)) return 1; |
79 |
if (mouse_set_data_report(false)) return 1; |
80 |
|
81 |
return 0; |
82 |
} |
83 |
|
84 |
int (mouse_test_remote)(uint16_t period, uint8_t cnt) {
|
85 |
|
86 |
// Mouse packets data
|
87 |
uint8_t packet[3];
|
88 |
int sz = 0; |
89 |
uint8_t data = 0;
|
90 |
// Cycle
|
91 |
int packetCounter = 0; |
92 |
int good = 1; |
93 |
// return value
|
94 |
int ret;
|
95 |
|
96 |
while (good) {
|
97 |
|
98 |
if ((ret = mouse_read_data(&data))) return ret; |
99 |
|
100 |
if ((data & FIRST_BYTE_ID) || sz) {
|
101 |
packet[sz] = data; |
102 |
sz++; |
103 |
} |
104 |
|
105 |
if (sz == 3) { |
106 |
struct packet pp = mouse_parse_packet(packet);
|
107 |
mouse_print_packet(&pp); |
108 |
packetCounter++; |
109 |
sz = 0;
|
110 |
if (packetCounter == cnt) good = 0; |
111 |
} |
112 |
|
113 |
tickdelay(micros_to_ticks(period*1e3));
|
114 |
} |
115 |
|
116 |
// Set Stream mode
|
117 |
if ((ret = mouse_issue_cmd(SET_STREAM_MD))) return ret; |
118 |
// Disable data reporting
|
119 |
if ((ret = mouse_set_data_report(false))) return ret; |
120 |
|
121 |
uint8_t cmd_byte = minix_get_dflt_kbc_cmd_byte(); |
122 |
if ((ret = kbc_change_cmd(cmd_byte))) return ret; |
123 |
|
124 |
return SUCCESS;
|
125 |
} |
126 |
|
127 |
int (mouse_test_async)(uint8_t idle_time) {
|
128 |
/* To be completed */
|
129 |
printf("%s(%u): under construction\n", __func__, idle_time);
|
130 |
return 1; |
131 |
} |
132 |
|
133 |
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {
|
134 |
/* To be completed */
|
135 |
printf("%s: under construction\n", __func__);
|
136 |
return 1; |
137 |
} |