summaryrefslogtreecommitdiff
path: root/fw/fe310/eos/eve/eve_vtrack.c
blob: a7619fb9f4ca3bfce5f442563a5fc6cef316b016 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdlib.h>
#include <math.h>

#include "eve.h"

static EVEVTrack vtrack;
static EVEPhyAcc vtrack_acc;

void eve_vtrack_init(void) {
    eve_phy_acc_init(&vtrack_acc, -EVE_VTRACK_ACC_A);
    eve_vtrack_reset();
}

EVEVTrack *eve_vtrack_get(void) {
    return &vtrack;
}

void eve_vtrack_set(eve_vtrack_start_t start, eve_vtrack_tick_t tick, eve_vtrack_stop_t stop, void *param) {
    vtrack.start = start;
    vtrack.tick = tick;
    vtrack.stop = stop;
    vtrack.param = param;
}

void eve_vtrack_reset(void) {
    eve_vtrack_set(eve_vtrack_acc_start, eve_vtrack_acc_tick, NULL, &vtrack_acc);
}

int eve_vtrack_start(EVETouch *touch, uint8_t tag0, uint32_t to) {
    if (vtrack.start) {
        int start;

        start = vtrack.start(touch, vtrack.param);
        if (start) eve_timer_set(touch, EVE_TOUCH_ETYPE_TRACK, tag0, to);

        return start;
    }
    return 0;
}

void eve_vtrack_stop(EVETouch *touch) {
    eve_timer_clear(touch);
    eve_vtrack_reset();
}

int eve_vtrack_acc_start(EVETouch *touch, void *p) {
    EVEPhyAcc *param = (EVEPhyAcc *)p;

    return eve_phy_acc_start(param, touch->x, touch->y, touch->t, touch->vx, touch->vy);
}

int eve_vtrack_acc_tick(EVETouch *touch, void *p) {
    EVEPhyAcc *param = (EVEPhyAcc *)p;

    return eve_phy_acc_tick(param, eve_get_tick() - touch->t, &touch->x, &touch->y);
}