Project

General

Profile

Revision 79

fully implemented state_machine & gesture

View differences:

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 {

Also available in: Unified diff