Static int compute_delta(struct tpms_softc *sc, int *dx, int *dy, int *dz, uint32_t * buttons) { int x_det, y_det, x_raw, y_raw, x_fingers, y_fingers, fingers, x, y; x_det = detect_pos(sc->sc_acc, sc->sc_x_sensors, sc->sc_threshold, sc->sc_x_factor, &x_raw, &x_fingers); y_det = detect_pos(sc->sc_acc + TPMS_X_SENSORS, sc->sc_y_sensors, sc->sc_threshold, sc->sc_y_factor, &y_raw, &y_fingers); fingers = max(x_fingers, y_fingers); /* Check the number of fingers and if we have detected a position. */ if (fingers > 1) { /* More than one finger detected, resetting. */ memset(sc->sc_acc, 0, sizeof(sc->sc_acc)); sc->sc_x_raw = sc->sc_y_raw = sc->sc_x = sc->sc_y = -1; return 0; } else if (x_det == 0 && y_det == 0) { /* No position detected, resetting. */ memset(sc->sc_acc, 0, sizeof(sc->sc_acc)); sc->sc_x_raw = sc->sc_y_raw = sc->sc_x = sc->sc_y = -1; } else if (x_det > 0 && y_det > 0) { /* Smooth position. */ if (sc->sc_x_raw >= 0) { sc->sc_x_raw = (3 * sc->sc_x_raw + x_raw) / 4; sc->sc_y_raw = (3 * sc->sc_y_raw + y_raw) / 4; /* * Compute virtual position and change if we already * have a decent position. */ if (sc->sc_x >= 0) { x = smooth_pos(sc->sc_x, sc->sc_x_raw, sc->sc_noise); y = smooth_pos(sc->sc_y, sc->sc_y_raw, sc->sc_noise); *dx = x - sc->sc_x; *dy = y - sc->sc_y; sc->sc_x = x; sc->sc_y = y; } else { /* Initialise virtual position. */ sc->sc_x = sc->sc_x_raw; sc->sc_y = sc->sc_y_raw; } } else { /* Initialise raw position. */ sc->sc_x_raw = x_raw; sc->sc_y_raw = y_raw; } } return (1); }
/* * Compute the change in x, y and z direction, update the button state * (to simulate more than one button, scrolling etc.), and update the * history. Note that dx, dy, dz and buttons are modified only if * corresponding pressure is detected and should thus be initialised * before the call. Return 0 on error. * * XXX Could we report something useful in dz? */ int compute_delta(struct utpms_softc *sc, int *dx, int *dy, int *dz, uint32_t * buttons) { int x_det, y_det, x_raw, y_raw, x_fingers, y_fingers, fingers, x, y; x_det = detect_pos(sc->sc_acc, sc->sc_x_sensors, sc->sc_threshold, sc->sc_x_factor, &x_raw, &x_fingers); y_det = detect_pos(sc->sc_acc + UTPMS_X_SENSORS, sc->sc_y_sensors, sc->sc_threshold, sc->sc_y_factor, &y_raw, &y_fingers); fingers = max(x_fingers, y_fingers); /* Check the number of fingers and if we have detected a position. */ if (x_det == 0 && y_det == 0) { /* No position detected, resetting. */ bzero(sc->sc_acc, sizeof(sc->sc_acc)); sc->sc_x_raw = sc->sc_y_raw = sc->sc_x = sc->sc_y = -1; } else if (x_det > 0 && y_det > 0) { switch (fingers) { case 1: /* Smooth position. */ if (sc->sc_x_raw >= 0) { sc->sc_x_raw = (3 * sc->sc_x_raw + x_raw) / 4; sc->sc_y_raw = (3 * sc->sc_y_raw + y_raw) / 4; /* * Compute virtual position and change if we * already have a decent position. */ if (sc->sc_x >= 0) { x = smooth_pos(sc->sc_x, sc->sc_x_raw, sc->sc_noise); y = smooth_pos(sc->sc_y, sc->sc_y_raw, sc->sc_noise); *dx = x - sc->sc_x; *dy = y - sc->sc_y; sc->sc_x = x; sc->sc_y = y; } else { /* Initialise virtual position. */ sc->sc_x = sc->sc_x_raw; sc->sc_y = sc->sc_y_raw; } } else { /* Initialise raw position. */ sc->sc_x_raw = x_raw; sc->sc_y_raw = y_raw; } break; case 2: if (*buttons == 1) *buttons = 4; break; case 3: if (*buttons == 1) *buttons = 2; break; } } return (1); }