Project

General

Profile

Statistics
| Revision:

root / lab4 / lab4.c @ 56

History | View | Annotate | Download (3.49 KB)

1
#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
extern uint8_t packet[3];
33
extern int counter;
34

    
35
int (mouse_test_packet)(uint32_t cnt) {
36
    /// loop stuff
37
    int ipc_status, r;
38
    message msg;
39
    /// Keyboard interrupt handling
40
    uint8_t mouse_irq_bit = 12;
41
    int mouse_id = 0;
42
    int mouse_irq = BIT(mouse_irq_bit);
43
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
44
    if(mouse_enable_data_reporting()) return 1;
45
    /// cycle
46
    int good = 1;
47
    uint32_t cnt_now = 0;
48
    while (good) {
49
        /* Get a request message. */
50
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
51
            printf("driver_receive failed with %d", r);
52
            continue;
53
        }
54
        if (is_ipc_notify(ipc_status)) { /* received notification */
55
            switch (_ENDPOINT_P(msg.m_source)) {
56
                case HARDWARE: /* hardware interrupt notification */
57
                    if (msg.m_notify.interrupts & mouse_irq) { /* subscribed interrupt */
58
                        mouse_ih();
59
                        if(counter >= 3){
60
                            struct packet pp = mouse_parse_packet(packet);
61
                            mouse_print_packet(&pp);
62
                            cnt_now++;
63
                            if(cnt == cnt_now) good = 0;
64
                        }
65
                        /*
66
                        if (!(two_byte_scancode || got_error)) { // finished processing a scancode
67
                            if (scancode[0] == TWO_BYTE_CODE) kbd_print_scancode(!(scancode[1] & BREAK_CODE_BIT), 2, scancode);
68
                            else                              kbd_print_scancode(!(scancode[0] & BREAK_CODE_BIT), 1, scancode);
69
                        } else { break; }
70
                        if (scancode[0] == ESC_BREAK_CODE) good = 0;
71
                        */
72
                    }
73
                    break;
74
                default:
75
                    break; /* no other notifications expected: do nothing */
76
            }
77
        } else { /* received standart message, not a notification */
78
            /* no standart message expected: do nothing */
79
        }
80
    }
81

    
82
    if (unsubscribe_interrupt(&mouse_id)) return 1;
83

    
84
    return 0;
85
}
86

    
87
int (mouse_test_remote)(uint16_t period, uint8_t cnt) {
88
    /* To be completed */
89
    printf("%s(%u, %u): under construction\n", __func__, period, cnt);
90
    return 1;
91
}
92

    
93
int (mouse_test_async)(uint8_t idle_time) {
94
    /* To be completed */
95
    printf("%s(%u): under construction\n", __func__, idle_time);
96
    return 1;
97
}
98

    
99
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {
100
    /* To be completed */
101
    printf("%s: under construction\n", __func__);
102
    return 1;
103
}