summaryrefslogtreecommitdiff
path: root/event_action.c
blob: 0acf1195b912eaabb9e0810cbcbc570f643b7984 (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
/*
 * gamepad.c: A plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */
#include "event_action.h"
#include <vdr/tools.h>

cEventAction::cEventAction(eKeys _key, bool _autorepeat, int repeatTimeMs, int repeatStartHoldMs) :  state(cGamepadHandler::RELEASE), key(_key), autorepeat(_autorepeat), lastEventTime(0), repeatTime(repeatTimeMs), repeatHold(repeatStartHoldMs)
{

}

void cEventAction::event(cGamepadHandler::generic_event *event)
{
    state = event->type;
    if (state == cGamepadHandler::PRESS)
    {
        fire();
    }
}

void cEventAction::fire()
{
    cRemote::Put(key);
    lastEventTime = cTimeMs::Now();
}

void cEventAction::repeat()
{
    if (autorepeat)
    {
        switch (state)
        {
            case cGamepadHandler::REPEAT:
                if ((cTimeMs::Now() - lastEventTime) > repeatTime)
                {
                    fire();
                }
                break;

            case cGamepadHandler::PRESS:
                if ((cTimeMs::Now() - lastEventTime) > repeatHold)
                {
                    fire();
                    state = cGamepadHandler::REPEAT;
                }
                break;
            default:
                break;
        }
    }
}