1094332d3Sopenharmony_ci/*
2094332d3Sopenharmony_ci * Copyright (c) 2021-2023 Huawei Device Co., Ltd.
3094332d3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4094332d3Sopenharmony_ci * you may not use this file except in compliance with the License.
5094332d3Sopenharmony_ci * You may obtain a copy of the License at
6094332d3Sopenharmony_ci *
7094332d3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8094332d3Sopenharmony_ci *
9094332d3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10094332d3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11094332d3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12094332d3Sopenharmony_ci * See the License for the specific language governing permissions and
13094332d3Sopenharmony_ci * limitations under the License.
14094332d3Sopenharmony_ci */
15094332d3Sopenharmony_ci
16094332d3Sopenharmony_ci/**
17094332d3Sopenharmony_ci * @addtogroup Vibrator
18094332d3Sopenharmony_ci * @{
19094332d3Sopenharmony_ci *
20094332d3Sopenharmony_ci * @brief Provides a driver for upper-layer vibrator services.
21094332d3Sopenharmony_ci *
22094332d3Sopenharmony_ci * After obtaining a driver object or agent, a vibrator service starts or stops the vibrator
23094332d3Sopenharmony_ci * using the functions provided by the driver object or agent.
24094332d3Sopenharmony_ci *
25094332d3Sopenharmony_ci * @since 2.2
26094332d3Sopenharmony_ci */
27094332d3Sopenharmony_ci
28094332d3Sopenharmony_ci/**
29094332d3Sopenharmony_ci * @file vibrator_if.h
30094332d3Sopenharmony_ci *
31094332d3Sopenharmony_ci * @brief Declares common APIs in the vibrator module. The APIs can be used to control
32094332d3Sopenharmony_ci * the vibrator to perform a one-shot or periodic vibration.
33094332d3Sopenharmony_ci *
34094332d3Sopenharmony_ci * @since 2.2
35094332d3Sopenharmony_ci * @version 1.0
36094332d3Sopenharmony_ci */
37094332d3Sopenharmony_ci
38094332d3Sopenharmony_ci#ifndef VIBRATOR_IF_H
39094332d3Sopenharmony_ci#define VIBRATOR_IF_H
40094332d3Sopenharmony_ci
41094332d3Sopenharmony_ci#include <stdint.h>
42094332d3Sopenharmony_ci#include "vibrator_type.h"
43094332d3Sopenharmony_ci
44094332d3Sopenharmony_ci#ifdef __cplusplus
45094332d3Sopenharmony_ci#if __cplusplus
46094332d3Sopenharmony_ciextern "C" {
47094332d3Sopenharmony_ci#endif
48094332d3Sopenharmony_ci#endif /* __cplusplus */
49094332d3Sopenharmony_ci
50094332d3Sopenharmony_cistruct VibratorInterface {
51094332d3Sopenharmony_ci    /**
52094332d3Sopenharmony_ci     * @brief Controls the vibrator to perform a one-shot vibration that lasts for a given duration.
53094332d3Sopenharmony_ci     *
54094332d3Sopenharmony_ci     * One-shot vibration is mutually exclusive with periodic vibration. Before using one-shot vibration,
55094332d3Sopenharmony_ci     * exit periodic vibration.
56094332d3Sopenharmony_ci     *
57094332d3Sopenharmony_ci     * @param duration Indicates the duration that the one-shot vibration lasts, in milliseconds.
58094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
59094332d3Sopenharmony_ci     *
60094332d3Sopenharmony_ci     * @since 2.2
61094332d3Sopenharmony_ci     * @version 1.0
62094332d3Sopenharmony_ci     */
63094332d3Sopenharmony_ci    int32_t (*StartOnce)(uint32_t duration);
64094332d3Sopenharmony_ci    /**
65094332d3Sopenharmony_ci     * @brief Controls the vibrator to perform a periodic vibration with the preset effect.
66094332d3Sopenharmony_ci     *
67094332d3Sopenharmony_ci     * One-shot vibration is mutually exclusive with periodic vibration. Before using periodic vibration,
68094332d3Sopenharmony_ci     * exit one-shot vibration.
69094332d3Sopenharmony_ci     *
70094332d3Sopenharmony_ci     * @param effectType Indicates the pointer to the preset effect type. It is recommended that the
71094332d3Sopenharmony_ci     * maximum length be 64 bytes.
72094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
73094332d3Sopenharmony_ci     *
74094332d3Sopenharmony_ci     * @since 2.2
75094332d3Sopenharmony_ci     * @version 1.0
76094332d3Sopenharmony_ci     */
77094332d3Sopenharmony_ci    int32_t (*Start)(const char *effectType);
78094332d3Sopenharmony_ci    /**
79094332d3Sopenharmony_ci     * @brief Stops the vibration.
80094332d3Sopenharmony_ci     *
81094332d3Sopenharmony_ci     * Before the vibrator starts, it must stop vibrating in any mode. This function can be used during
82094332d3Sopenharmony_ci     * and after the vibrating process.
83094332d3Sopenharmony_ci     *
84094332d3Sopenharmony_ci     * @param mode Indicates the vibration mode, which can be one-shot or periodic. For details,
85094332d3Sopenharmony_ci     * see {@link VibratorMode}.
86094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
87094332d3Sopenharmony_ci     *
88094332d3Sopenharmony_ci     * @since 2.2
89094332d3Sopenharmony_ci     * @version 1.0
90094332d3Sopenharmony_ci     */
91094332d3Sopenharmony_ci    int32_t (*Stop)(enum VibratorMode mode);
92094332d3Sopenharmony_ci    /**
93094332d3Sopenharmony_ci     * @brief Obtains information about all the vibrator that support setting intensity and frequency in the system.
94094332d3Sopenharmony_ci     *
95094332d3Sopenharmony_ci     * @param vibratorInfo Indicates the pointer to the vibration effect, For details, see {@link VibratorInfo}.
96094332d3Sopenharmony_ci     *
97094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
98094332d3Sopenharmony_ci     *
99094332d3Sopenharmony_ci     * @since 3.2
100094332d3Sopenharmony_ci     * @version 1.1
101094332d3Sopenharmony_ci     */
102094332d3Sopenharmony_ci    int32_t (*GetVibratorInfo)(struct VibratorInfo **vibratorInfo);
103094332d3Sopenharmony_ci    /**
104094332d3Sopenharmony_ci     * @brief Start the vibrator according to the incoming vibration effect.
105094332d3Sopenharmony_ci     *
106094332d3Sopenharmony_ci     * @param duration Indicates the duration that the vibration lasts, in milliseconds.
107094332d3Sopenharmony_ci     *
108094332d3Sopenharmony_ci     * @param intensity indicates vibrator intensity in a vibration period.
109094332d3Sopenharmony_ci     *
110094332d3Sopenharmony_ci     * @param frequency indicates vibrator frequency in a vibration period.
111094332d3Sopenharmony_ci     *
112094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
113094332d3Sopenharmony_ci     * @return Returns <b>-1</b> if the vibrationPeriod setting is not supported.
114094332d3Sopenharmony_ci     * @return Returns <b>-2</b> if the intensity setting is not supported.
115094332d3Sopenharmony_ci     * @return Returns <b>-3</b> if the frequency setting is not supported.
116094332d3Sopenharmony_ci     *
117094332d3Sopenharmony_ci     * @since 3.2
118094332d3Sopenharmony_ci     * @version 1.1
119094332d3Sopenharmony_ci     */
120094332d3Sopenharmony_ci    int32_t (*EnableVibratorModulation)(uint32_t duration, uint16_t intensity, int16_t frequency);
121094332d3Sopenharmony_ci    /**
122094332d3Sopenharmony_ci     * @brief Controls the vibrator to perform a periodic vibration with the custom composite effect.
123094332d3Sopenharmony_ci     *
124094332d3Sopenharmony_ci     * @param effect Indicates the pointer to the custom composite effect type. For details,
125094332d3Sopenharmony_ci     * see {@link CompositeEffect}.
126094332d3Sopenharmony_ci     *
127094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
128094332d3Sopenharmony_ci     *
129094332d3Sopenharmony_ci     * @since 3.2
130094332d3Sopenharmony_ci     * @version 1.1
131094332d3Sopenharmony_ci     */
132094332d3Sopenharmony_ci    int32_t (*EnableCompositeEffect)(struct CompositeEffect *effect);
133094332d3Sopenharmony_ci    /**
134094332d3Sopenharmony_ci     * @brief Obtains the vibration effect information with the specified effect type.
135094332d3Sopenharmony_ci     *
136094332d3Sopenharmony_ci     * @param effectType Indicates the pointer to the preset effect type. It is recommended that the
137094332d3Sopenharmony_ci     * maximum length be 64 bytes.
138094332d3Sopenharmony_ci     *
139094332d3Sopenharmony_ci     * @param effectInfo Indicates the pointer to the vibration effect information. For details,
140094332d3Sopenharmony_ci     * see {@link EffectInfo}.
141094332d3Sopenharmony_ci     *
142094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
143094332d3Sopenharmony_ci     * @return Returns negative value if the get failed.
144094332d3Sopenharmony_ci     *
145094332d3Sopenharmony_ci     * @since 3.2
146094332d3Sopenharmony_ci     * @version 1.1
147094332d3Sopenharmony_ci     */
148094332d3Sopenharmony_ci    int32_t (*GetEffectInfo)(const char *effectType, struct EffectInfo *effectInfo);
149094332d3Sopenharmony_ci    /**
150094332d3Sopenharmony_ci     * @brief Obtains whether the vibrator is currently vibrating.
151094332d3Sopenharmony_ci     *
152094332d3Sopenharmony_ci     * @param state Indicates current vibration state of the vibrator.
153094332d3Sopenharmony_ci     *
154094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
155094332d3Sopenharmony_ci     * @return Returns negative value if the get failed.
156094332d3Sopenharmony_ci     *
157094332d3Sopenharmony_ci     * @since 3.2
158094332d3Sopenharmony_ci     * @version 1.1
159094332d3Sopenharmony_ci     */
160094332d3Sopenharmony_ci    int32_t (*IsVibratorRunning)(bool state);
161094332d3Sopenharmony_ci    /**
162094332d3Sopenharmony_ci     * @brief HD vibration data packet delivery.
163094332d3Sopenharmony_ci     *
164094332d3Sopenharmony_ci     * @param Indecates the Hd vibration data packet.
165094332d3Sopenharmony_ci     *
166094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
167094332d3Sopenharmony_ci     * @return Returns negative value if the get failed.
168094332d3Sopenharmony_ci     *
169094332d3Sopenharmony_ci     * @since 4.1
170094332d3Sopenharmony_ci     * @version 1.2
171094332d3Sopenharmony_ci     */
172094332d3Sopenharmony_ci    int32_t (*PlayHapticPattern)(struct HapticPaket *pkg);
173094332d3Sopenharmony_ci    /**
174094332d3Sopenharmony_ci     * @brief Obtains the vibration capability of the motor.
175094332d3Sopenharmony_ci     *
176094332d3Sopenharmony_ci     * @param Indecates the vibration capability of the motor.
177094332d3Sopenharmony_ci     *
178094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
179094332d3Sopenharmony_ci     * @return Returns negative value if the get failed.
180094332d3Sopenharmony_ci     *
181094332d3Sopenharmony_ci     * @since 4.1
182094332d3Sopenharmony_ci     * @version 1.2
183094332d3Sopenharmony_ci     */
184094332d3Sopenharmony_ci    int32_t (*GetHapticCapacity)(struct HapticCapacity *hapticCapacity);
185094332d3Sopenharmony_ci    /**
186094332d3Sopenharmony_ci     * @brief Obtains the start_up time of the motor.
187094332d3Sopenharmony_ci     *
188094332d3Sopenharmony_ci     * @param Indicates the time from command is issued to the time the motor starts.
189094332d3Sopenharmony_ci     *
190094332d3Sopenharmony_ci     * @return Returns <b>0</b> if the operation is successful.
191094332d3Sopenharmony_ci     * @return Returns negative value if the get failed.
192094332d3Sopenharmony_ci     *
193094332d3Sopenharmony_ci     * @since 4.1
194094332d3Sopenharmony_ci     * @version 1.2
195094332d3Sopenharmony_ci     */
196094332d3Sopenharmony_ci    int32_t (*GetHapticStartUpTime)(int32_t mode, int32_t *startUpTime);
197094332d3Sopenharmony_ci};
198094332d3Sopenharmony_ci
199094332d3Sopenharmony_ci/**
200094332d3Sopenharmony_ci * @brief Creates a <b>VibratorInterface</b> instance.
201094332d3Sopenharmony_ci *
202094332d3Sopenharmony_ci * The obtained <b>VibratorInterface</b> instance can be used to control the vibrator to vibrate as configured.
203094332d3Sopenharmony_ci *
204094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful.
205094332d3Sopenharmony_ci * @return Returns negative value if the get failed.
206094332d3Sopenharmony_ci *
207094332d3Sopenharmony_ci * @since 2.2
208094332d3Sopenharmony_ci * @version 1.0
209094332d3Sopenharmony_ci */
210094332d3Sopenharmony_ciconst struct VibratorInterface *NewVibratorInterfaceInstance(void);
211094332d3Sopenharmony_ci
212094332d3Sopenharmony_ci/**
213094332d3Sopenharmony_ci * @brief Releases this <b>VibratorInterface</b> instance to free up related resources.
214094332d3Sopenharmony_ci *
215094332d3Sopenharmony_ci * @return Returns <b>0</b> if the operation is successful; returns a negative value otherwise.
216094332d3Sopenharmony_ci *
217094332d3Sopenharmony_ci * @since 2.2
218094332d3Sopenharmony_ci * @version 1.0
219094332d3Sopenharmony_ci */
220094332d3Sopenharmony_ciint32_t FreeVibratorInterfaceInstance(void);
221094332d3Sopenharmony_ci
222094332d3Sopenharmony_ci#ifdef __cplusplus
223094332d3Sopenharmony_ci#if __cplusplus
224094332d3Sopenharmony_ci}
225094332d3Sopenharmony_ci#endif
226094332d3Sopenharmony_ci#endif /* __cplusplus */
227094332d3Sopenharmony_ci
228094332d3Sopenharmony_ci#endif /* VIBRATOR_IF_H */
229094332d3Sopenharmony_ci/** @} */
230