summaryrefslogtreecommitdiff
path: root/examples/widgets/symbianvibration/xqvibra_p.cpp
blob: 9f2b5f97b4634701735ed85f4b10ca7ba453768a (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include "xqvibra_p.h"

const int KDefaultIntensity = 0xFF;

XQVibraPrivate::XQVibraPrivate(XQVibra *vibra)
    : q(vibra), iStatus(XQVibra::StatusOff), iDuration(XQVibra::InfiniteDuration), iIntensity(KDefaultIntensity)

{
    TRAP(iError, iVibra = CHWRMVibra::NewL();)
    QObject::connect(&iTimer, SIGNAL(timeout()), q, SLOT(stop()));
}

XQVibraPrivate::~XQVibraPrivate()
{
    delete iVibra;
}

bool XQVibraPrivate::start(int aDuration)
{
    iDuration = aDuration;
    TRAP(iError,
        if (iIntensity == KDefaultIntensity) {
            iVibra->StartVibraL(XQVibra::InfiniteDuration);
        } else {
            iVibra->StopVibraL();
            iVibra->StartVibraL(XQVibra::InfiniteDuration, iIntensity);
        }

        if (aDuration != XQVibra::InfiniteDuration) {
            iTimer.start(aDuration);
        } else {
            iTimer.stop();
        }

        if (iStatus != XQVibra::StatusOn) {
            iStatus = XQVibra::StatusOn;
            emit q->statusChanged(iStatus);
        }
    )
    return (iError == KErrNone);
}

bool XQVibraPrivate::stop()
{
    TRAP(iError,
        if (iVibra->VibraStatus() == CHWRMVibra::EVibraStatusOn) {
            iVibra->StopVibraL();
            if (iTimer.isActive()) {
                iTimer.stop();
            }
        }

        iStatus = XQVibra::StatusOff;
        emit q->statusChanged(iStatus);
    )
    return (iError == KErrNone);
}

void XQVibraPrivate::VibraModeChanged(CHWRMVibra::TVibraModeState /*aStatus*/)
{
    // Implementation isn't needed here because this information isn't used in the public side of the extension
}

void XQVibraPrivate::VibraStatusChanged(CHWRMVibra::TVibraStatus aStatus)
{
    if (aStatus == CHWRMVibra::EVibraStatusUnknown ||
            aStatus == CHWRMVibra::EVibraStatusNotAllowed) {
        iStatus = XQVibra::StatusNotAllowed;
        emit q->statusChanged(iStatus);
    }

    if (iDuration ==  XQVibra::InfiniteDuration) {
        if (iStatus != XQVibra::StatusOff) {
            iStatus = XQVibra::StatusOff;
            emit q->statusChanged(iStatus);
        }
    }
}

bool XQVibraPrivate::setIntensity(int aIntensity)
{
    TRAP(iError,
        if (aIntensity >= KHWRMVibraMinIntensity && aIntensity <= KHWRMVibraMaxIntensity) {
            iIntensity = aIntensity;
            if (iIntensity == 0 && iStatus == XQVibra::StatusOn) {
                iVibra->StopVibraL();
            } else if (iStatus == XQVibra::StatusOn) {
                iVibra->StopVibraL();
                iVibra->StartVibraL(XQVibra::InfiniteDuration, iIntensity);
            }
        } else {
            User::Leave(KErrArgument);
        }
    )
    return (iError == KErrNone);
}

XQVibra::Status XQVibraPrivate::currentStatus() const
{
    if (iVibra->VibraStatus() == CHWRMVibra::EVibraStatusUnknown ||
            iVibra->VibraStatus() == CHWRMVibra::EVibraStatusNotAllowed) {
        return XQVibra::StatusNotAllowed;
    }
    return iStatus;
}

XQVibra::Error XQVibraPrivate::error() const
{
    switch (iError) {
    case KErrNone:
        return XQVibra::NoError;
    case KErrNoMemory:
        return XQVibra::OutOfMemoryError;
    case KErrArgument:
        return XQVibra::ArgumentError;
    case KErrInUse:
        return XQVibra::VibraInUseError;
    case KErrGeneral:
        return XQVibra::HardwareError;
    case KErrTimedOut:
        return XQVibra::TimeOutError;
    case KErrLocked:
        return XQVibra::VibraLockedError;
    case KErrAccessDenied:
        return XQVibra::AccessDeniedError;
    default:
        return XQVibra::UnknownError;
    }
}

// End of file