Project

General

Profile

Statistics
| Revision:

root / lab4 / lab4.c @ 55

History | View | Annotate | Download (3.12 KB)

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