Project

General

Profile

Revision 79

fully implemented state_machine & gesture

View differences:

lab4/kbc.c
30 30
    int ret = 0;
31 31
    uint8_t cmd = 0;
32 32
    if((ret = kbc_read_cmd(&cmd))) return ret;
33
    cmd = (cmd | INT_KBD) & (~DIS_KBD) ;
33
    cmd = (cmd | INT_KBD) & (~DIS_KBD);
34 34
    if((ret = kbc_change_cmd(cmd))) return ret;
35 35
    return SUCCESS;
36 36
}
lab4/lab4.c
101 101

  
102 102
    if ((ret = mouse_set_data_report(true))) return ret;
103 103

  
104
    uint8_t cmd = 0;
105
    if ((ret = kbc_read_cmd(&cmd))) return ret;
106

  
107 104
    while (good) {
108 105

  
109 106
        if ((ret = mouse_read_data(&data))) return ret;
......
195 192
}
196 193

  
197 194
int (mouse_test_gesture)(uint8_t x_len, uint8_t tolerance) {
195
    int ret;
198 196
    /// loop stuff
199 197
    int ipc_status, r;
200 198
    message msg;
......
202 200
    uint8_t mouse_irq_bit = 12;
203 201
    int mouse_id = 0;
204 202
    int mouse_irq = BIT(mouse_irq_bit);
205
    //if ((ret = mouse_set_data_report(true))) return ret;
206
    if (mouse_enable_data_reporting()) return 1;
203
    if ((ret = mouse_set_data_report(true))) return ret;
207 204

  
208 205
    if (subscribe_mouse_interrupt(mouse_irq_bit, &mouse_id)) return 1;
209 206
    /// cycle
......
213 210
    struct mouse_ev *event;
214 211
    struct packet pp;
215 212
    int response;
216

  
217 213
    while (good) {
218 214
        /* Get a request message. */
219 215
        if ((r = driver_receive(ANY, &msg, &ipc_status)) != 0) {
......
227 223
                        mouse_ih();
228 224
                        if(counter >= 3) {
229 225
                            pp = mouse_parse_packet(packet);
230
                            //mouse_print_packet(&pp);
226
                            mouse_print_packet(&pp);
231 227
                            event = mouse_get_event(&pp);
232 228

  
233 229
                            response = state_machine(event, x_len, tolerance);
lab4/state_machine.c
4 4
#include "mouse_macros.h"
5 5
#include "mouse.h"
6 6
#include "errors.h"
7
#include "utils.h"
7 8

  
8 9
struct mouse_ev* mouse_get_event(struct packet *pp) {
9 10

  
......
18 19
    uint8_t lb_press = pp->bytes[0] & LEFT_BUTTON;
19 20
    uint8_t rb_press = pp->bytes[0] & RIGHT_BUTTON;
20 21
    uint8_t mb_press = pp->bytes[0] & MIDDLE_BUTTON;
21
    int16_t delta_x = sign_extend_byte(pp->bytes[0] & MSB_X_DELTA, pp->bytes[1]);
22
    int16_t delta_y = sign_extend_byte(pp->bytes[0] & MSB_Y_DELTA, pp->bytes[2]);
22
    int16_t delta_x = pp->delta_x;
23
    int16_t delta_y = pp->delta_y;
23 24

  
24 25
    if (aux) { // first event detected
25 26
        if (lb_press && (rb_press | mb_press) == 0 && delta_x == 0 && delta_y == 0)
......
70 71

  
71 72
    if (event == NULL)
72 73
        return response;
73

  
74 74
    switch (state) {
75 75
        case INITIAL:
76 76
            if (event->type == LB_PRESSED)
......
138 138
                    state = INITIAL;
139 139
                    break;
140 140
                }
141

  
142 141
                int slope = y_length / x_length;
143 142

  
144 143
                if (slope >= -1 || x_length < x_len) {
......
149 148
                }
150 149

  
151 150
                state = FINAL;
151
                response = SUCCESS;
152 152
                x_length = 0;
153 153
                y_length = 0;
154 154
            } else {
lab4/utils.c
31 31
    #endif
32 32
    return SUCCESS;
33 33
}
34

  
35
int16_t abs16(int16_t x) {
36
    return (x >= 0) ? (int16_t)(x) : (int16_t)(-x);
37
}
lab4/utils.h
11 11

  
12 12
int (util_sys_inb)(int port, uint8_t *value);
13 13

  
14
int16_t abs16(int16_t x);
15

  
14 16
#endif //UTILS_H_INCLUDED

Also available in: Unified diff