root / lab4 / lab4.c @ 64
History | View | Annotate | Download (3.04 KB)
1 | 53 | up20180655 | #include <lcom/lcf.h> |
---|---|---|---|
2 | |||
3 | #include <stdint.h> |
||
4 | #include <stdio.h> |
||
5 | |||
6 | 58 | up20180642 | #include "mouse.h" |
7 | #include "kbc.h" |
||
8 | 53 | up20180655 | |
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 | 56 | up20180642 | extern uint8_t packet[3]; |
34 | extern int counter; |
||
35 | 53 | up20180655 | |
36 | int (mouse_test_packet)(uint32_t cnt) {
|
||
37 | 55 | up20180642 | /// 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 | 56 | up20180642 | uint32_t cnt_now = 0;
|
49 | 55 | up20180642 | 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 | 56 | up20180642 | 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 | 55 | up20180642 | } |
67 | break;
|
||
68 | default:
|
||
69 | break; /* no other notifications expected: do nothing */ |
||
70 | } |
||
71 | } else { /* received standart message, not a notification */ |
||
72 | /* no standart message expected: do nothing */
|
||
73 | } |
||
74 | } |
||
75 | |||
76 | if (unsubscribe_interrupt(&mouse_id)) return 1; |
||
77 | |||
78 | 58 | up20180642 | if(mouse_set_data_report(false)) return 1; |
79 | |||
80 | 55 | up20180642 | return 0; |
81 | 53 | up20180655 | } |
82 | |||
83 | int (mouse_test_remote)(uint16_t period, uint8_t cnt) {
|
||
84 | /* To be completed */
|
||
85 | printf("%s(%u, %u): under construction\n", __func__, period, cnt);
|
||
86 | return 1; |
||
87 | } |
||
88 | |||
89 | int (mouse_test_async)(uint8_t idle_time) {
|
||
90 | /* To be completed */
|
||
91 | printf("%s(%u): under construction\n", __func__, idle_time);
|
||
92 | return 1; |
||
93 | } |
||
94 | |||
95 | 54 | up20180642 | int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {
|
96 | 53 | up20180655 | /* To be completed */
|
97 | printf("%s: under construction\n", __func__);
|
||
98 | return 1; |
||
99 | } |