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.
16 #ifndef WRTDEVICEAPIS_HAPTICS_MOTOR_H_
17 #define WRTDEVICEAPIS_HAPTICS_MOTOR_H_
20 #include <devman_haptic.h>
21 #include <dpl/mutex.h>
22 #include <dpl/shared_ptr.h>
23 #include <Commons/IEvent.h>
24 #include <Haptics/IMotor.h>
26 namespace WrtDeviceApis {
28 // Dummy event for asynchronous haptic motor schedule
29 class EventHapticAction : public Commons::IEvent<EventHapticAction>
32 typedef DPL::SharedPtr<EventHapticAction> EventHapticActionPtr;
33 typedef Commons::EventRequestReceiver<EventHapticAction> EventHapticActionReqReceiver;
34 typedef Commons::EventRequestReceiver<Api::EventStartMotor> EventStartMotorReqReceiver;
35 typedef Commons::EventRequestReceiver<Api::EventPlayBeep> EventPlayBeepReqReceiver;
39 public EventHapticActionReqReceiver,
40 public EventStartMotorReqReceiver,
41 public EventPlayBeepReqReceiver
44 explicit Motor(haptic_dev_idx index);
48 * Run vibrate for duration.
49 * @param duration is unsigned long and value in milliseconds..
52 void run(unsigned long duration);
55 * Run vibrate for given pattern .
56 * @param The pattern argument is a DOMString composed by '.' and '_' chars.
59 void run(const Api::HapticPatternPtr& pattern);
62 * Run vibrate for given event .
63 * @param The event argument is event included duration & pattern.
66 void run(const Api::EventStartMotorPtr& event);
69 * stop motor for vibrating device
76 * stop vibration. (pattern and motor)
83 * Run notify for given duration and volume.if volume!=0 beep device,volume=0&vibrate open vibrate device
84 * @param duration value is unsigned long in millsecond.
85 * @param volume value is 0~7
88 int playBeep(unsigned long duration,
92 * Run notify for given duration and volume.if volume!=0 beep device,volume=0&vibrate open vibrate device
93 * @param duration value is unsigned long in millsecond.
94 * @param volume value is 0~7
97 void playBeep(const Api::EventPlayBeepPtr& event);
100 * stop beep/vibrate/light-on device
107 void OnRequestReceived(const EventHapticActionPtr& event);
108 void OnRequestReceived(const Api::EventStartMotorPtr& event);
109 void OnRequestReceived(const Api::EventPlayBeepPtr& event);
112 void runNextPattern();
113 void arragePattern(Api::HapticPatternPtr& patternPtr,
114 const unsigned long duration);
117 int m_device; ///< Platform haptic device handle.
118 int m_beepHandle; ///< Platform beep handle.
119 Api::HapticPatternPtr m_pattern; // haptic action pattern
120 EventHapticActionPtr m_event; // haptic action scheduling event
121 size_t m_current; // current haptic action pattern interval
122 DPL::Mutex m_patternMutex;
127 #endif /* WRTDEVICEAPIS_HAPTICS_MOTOR_H_ */