1 /*
2  * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 /**
17  * @addtogroup Vibrator
18  * @{
19  *
20  * @brief Provides unified APIs for vibrator services to access the vibrator driver.
21  *
22  * After obtaining a driver object or agent, a vibrator service starts or stops the vibrator
23  * using the functions provided by the driver object or agent.
24  *
25  * @version 1.0
26  */
27 
28 /**
29  * @file vibrator_type.h
30  *
31  * @brief Defines the vibrator data structure, including the vibration mode and effect type.
32  *
33  * @since 2.2
34  * @version 1.0
35  */
36 
37 #ifndef VIBRATOR_TYPE_H
38 #define VIBRATOR_TYPE_H
39 
40 #include <stdint.h>
41 
42 #ifdef __cplusplus
43 #if __cplusplus
44 extern "C" {
45 #endif
46 #endif /* __cplusplus */
47 
48 /**
49  * @brief Enumerates the return values of the vibrator module.
50  *
51  * @since 3.2
52  */
53 enum VibratorStatus {
54     /** The operation is successful. */
55     VIBRATOR_SUCCESS            = 0,
56     /** The period setting is not supported. */
57     VIBRATOR_NOT_PERIOD         = -1,
58     /** The intensity setting is not supported. */
59     VIBRATOR_NOT_INTENSITY      = -2,
60     /** The frequency setting is not supported. */
61     VIBRATOR_NOT_FREQUENCY      = -3,
62 };
63 
64 /**
65  * @brief Enumerates the vibration modes of this vibrator.
66  *
67  * @since 2.2
68  */
69 enum VibratorMode {
70     /**< Indicates the one-shot vibration with the given duration. */
71     VIBRATOR_MODE_ONCE   = 0,
72     /**< Indicates the periodic vibration with the preset effect. */
73     VIBRATOR_MODE_PRESET = 1,
74     /**< Indicates the vibration is high-definition. */
75     VIBRATOR_MODE_HDHAPTIC = 2,
76     /**< Indicates invalid the effect mode. */
77     VIBRATOR_MODE_BUTT
78 };
79 
80 /**
81  * @brief Enumerates the effect types of the composite effects.
82  *
83  * @since 3.2
84  */
85 enum EffectType {
86     /**< Indicates the time effect type of the given time series. */
87     EFFECT_TYPE_TIME,
88     /**< Indicates primitive vibration effect type for a given primitive vibration sequence. */
89     EFFECT_TYPE_PRIMITIVE,
90     /**< Indicates invalid the effect type. */
91     EFFECT_TYPE_BUTT,
92 };
93 
94 /**
95  * @brief Enumerates the event types.
96  *
97  * @since 4.1
98  */
99 enum EVENT_TYPE {
100     /**< Indicates that the vibration is continuous. */
101     CONTINUOUS = 0,
102     /**< Indicates that the vibration is instantaneous. */
103     TRANSIENT  = 1,
104 };
105 
106 /**
107  * @brief Defines the vibration parameters.
108  *
109  * The parameters include the setting intensity and frequency capability the on and intensity and frequency range.
110  *
111  * @since 3.2
112  */
113 struct VibratorInfo {
114     /**< setting intensity capability. 1 indicates support, 0 indicates not support. */
115     bool isSupportIntensity;
116     /**< setting frequency capability. 1 indicates support, 0 indicates not support. */
117     bool isSupportFrequency;
118     /**< Max intensity. */
119     uint16_t intensityMaxValue;
120     /**< Min intensity. */
121     uint16_t intensityMinValue;
122     /**< Max frequency(Hz). */
123     int16_t frequencyMaxValue;
124     /**< Min frequency(Hz). */
125     int16_t frequencyMinValue;
126 };
127 
128 /**
129  * @brief Defines the time effect parameters.
130  *
131  * The parameters include delay, time, intensity and frequency of vibration.
132  *
133  * @since 3.2
134  */
135 struct TimeEffect {
136     int32_t delay;        /** Waiting time. */
137     int32_t time;         /** Vibration time. */
138     uint16_t intensity;   /** Vibration intensity. */
139     int16_t frequency;    /** Vibration frequency(Hz). */
140 };
141 
142 /**
143  * @brief Defines the primitive effect parameters.
144  *
145  * The parameters include delay, effect id and vibration intensity.
146  *
147  * @since 3.2
148  */
149 struct PrimitiveEffect {
150     int32_t delay;         /** Waiting time. */
151     int32_t effectId;      /** Effect id. */
152     uint16_t intensity;    /** Vibration intensity. */
153 };
154 
155 /**
156  * @brief Defines two effects for custom composite effects.
157  *
158  * The parameters include time effect and primitive effect.
159  *
160  * @since 3.2
161  */
162 union Effect {
163     struct TimeEffect timeEffect;              /** Time effect, see {@link TimeEffect}. */
164     struct PrimitiveEffect primitiveEffect;    /** Primitive effect, see {@link PrimitiveEffect}. */
165 };
166 
167 /**
168  * @brief Defines the composite vibration effect parameters.
169  *
170  * The parameters include type and sequences of composite effects.
171  *
172  * @since 3.2
173  */
174 struct CompositeEffect {
175     /** Type of the composite effect, see {@link union HdfEffectType}. */
176     int32_t type;
177     /** The sequences of composite effects, see {@link union Effect}. */
178     union Effect effects[];
179 };
180 
181 /**
182  * @brief Defines the vibration effect information.
183  *
184  * The information include the capability to set the effect and the vibration duration of the effect.
185  *
186  * @since 3.2
187  */
188 struct EffectInfo {
189     /** Vibration duration of the effect, in milliseconds. */
190     int32_t duration;
191     /**< setting effect capability. 1 indicates support, 0 indicates not support. */
192     bool isSupportEffect;
193 };
194 
195 
196 /**
197  * @brief Defines the vibration point parameters.
198  *
199  * The information include the time, intensity, and frequency.
200  *
201  * @since 4.1
202  */
203 struct CurvePoint {
204     /** Time of the vibration point. */
205     int32_t time;
206     /** Intensity of the vibration point. */
207     int32_t intensity;
208     /** Frequency of the vibration point. */
209     int32_t frequency;
210 };
211 
212 /**
213  * @brief Defines the HD vibration event.
214  *
215  * The information include the HD vibration event.
216  *
217  * @since 4.1
218  */
219 struct HapticEvent {
220     /** Indicates the vibration type. */
221     enum EVENT_TYPE type;
222     /** Indicates the vibration time. */
223     int32_t time;
224     /** Indicates the vibration duration. */
225     int32_t duration;
226     /** Indicates the vibration intensity. */
227     int32_t intensity;
228     /** Indicates the vibration frequency. */
229     int32_t frequency;
230     /** ID of the vibration motor. Indicates the time from command is issued to the time the motor starts. */
231     int32_t index;
232     /** Indicates the number of vibration points. */
233     int32_t pointNum;
234     /** Indicates the vibration point array. */
235     struct CurvePoint points[];
236 };
237 
238 /**
239  * @brief Defines the vibration data delivery packet.
240  *
241  * The information include the different trypes of vibrationsr;
242  *
243  * @since 4.1
244  */
245 struct HapticPaket {
246     /** Indicates the vibration data delivery time. */
247     int32_t time;
248     /** Indicates the vibration number of data to be delivered. */
249     int32_t eventNum;
250     /** Indicates the vibration data delivery event array. */
251     struct HapticEvent events[];
252 };
253 
254 /**
255  * @brief Defines the vibration capability data package.
256  *
257  * The information include the different types of vibrations.
258  *
259  * @since 4.1
260  */
261 struct HapticCapacity {
262     /** Indicates the vibration support HD vibration. */
263     bool isSupportHdHaptic;
264     /** Indicates the vibration support preset mapping. */
265     bool isSupportPresetMapping;
266     /** Indicates the vibration support dalay vibration. */
267     bool isSupportTimeDelay;
268     /** Indicates the vibration Standby parameter. */
269     bool reserved0;
270     /** Indicates the vibration Standby parameter. */
271     int32_t reserved1;
272 };
273 
274 #ifdef __cplusplus
275 #if __cplusplus
276 }
277 #endif
278 #endif /* __cplusplus */
279 
280 #endif /* VIBRATOR_TYPE_H */
281 /** @} */
282