2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 * @file HapticPattern.cpp
20 * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
25 #include "HapticPattern.h"
26 #include <Commons/Exception.h>
28 namespace WrtDeviceApis {
31 void HapticPattern::addInterval(unsigned long duration,
39 if (0 == m_sequence.size()) {
40 m_startsActive = vibrate;
41 m_sequence.push_back(duration);
45 // check if last interval is action or pause
46 bool lastVibrates = m_startsActive ^ ((m_sequence.size() & 0x1) == 0);
48 if (lastVibrates == vibrate) {
49 *m_sequence.rbegin() += duration; // extend last interval
51 m_sequence.push_back(duration); // add new interval
55 bool HapticPattern::isActive(size_t interval) const
57 if (interval >= m_sequence.size()) {
58 ThrowMsg(Commons::OutOfRangeException,
59 "Interval index is out of haptic sequence range");
62 return m_startsActive ^ ((interval & 0x1) != 0);
65 unsigned long HapticPattern::duration(size_t interval) const
67 if (interval >= m_sequence.size()) {
71 return m_sequence[interval];