1 /* 2 * Copyright (c) 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 APIs for vibrator services to access the vibrator driver. 21 * @since 11 22 */ 23 24 /** 25 * @file vibrator.h 26 * @kit SensorServiceKit 27 * @brief Declares the APIs for starting or stopping vibration. 28 * @library libohvibrator.z.so 29 * @syscap SystemCapability.Sensors.MiscDevice 30 * @since 11 31 */ 32 33 #ifndef VIBRATOR_H 34 #define VIBRATOR_H 35 36 #include "vibrator_type.h" 37 38 #ifdef __cplusplus 39 extern "C" { 40 #endif 41 42 /** 43 * @brief Controls the vibrator to vibrate continuously for a given duration. 44 * 45 * @param duration - Vibration duration, in milliseconds. 46 * @param attribute - Vibration attribute. For details, see {@link Vibrator_Attribute}. 47 * @return Returns <b>0</b> if the operation is successful; returns the following error code otherwise. 48 * {@link PERMISSION_DENIED} Permission verification failed.\n 49 * {@link PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid, 50 * or the parameter type passed in is incorrect.\n 51 * {@link UNSUPPORTED} The API is not supported on the device. The device supports the corresponding SysCap, 52 * but does not support certain APIs in this SysCap.\n 53 * {@link DEVICE_OPERATION_FAILED} The operation on the device failed.\n 54 * @permission ohos.permission.VIBRATE 55 * 56 * @since 11 57 */ 58 int32_t OH_Vibrator_PlayVibration(int32_t duration, Vibrator_Attribute attribute); 59 60 /** 61 * @brief Controls the vibrator to vibrate with the custom sequence. 62 * 63 * @param fileDescription - File descriptor of the custom vibration effect. 64 * For details, see {@link Vibrator_FileDescription}. 65 * @param vibrateAttribute - Vibration attribute. For details, see {@link Vibrator_Attribute}. 66 * @return Returns <b>0</b> if the operation is successful; returns the following error code otherwise. 67 * {@link PERMISSION_DENIED} Permission verification failed.\n 68 * {@link PARAMETER_ERROR} Parameter check failed. For example, the parameter is invalid, 69 * or the parameter type passed in is incorrect.\n 70 * {@link UNSUPPORTED} The API is not supported on the device. The device supports the corresponding SysCap, 71 * but does not support certain APIs in this SysCap.\n 72 * {@link DEVICE_OPERATION_FAILED} The operation on the device failed.\n 73 * @permission ohos.permission.VIBRATE 74 * 75 * @since 11 76 */ 77 int32_t OH_Vibrator_PlayVibrationCustom(Vibrator_FileDescription fileDescription, 78 Vibrator_Attribute vibrateAttribute); 79 80 /** 81 * @brief Stop the motor vibration according to the input mode. 82 * 83 * @permission ohos.permission.VIBRATE 84 * @return Returns <b>0</b> if the operation is successful; returns the following error code otherwise. 85 * {@link PERMISSION_DENIED} Permission verification failed.\n 86 * {@link UNSUPPORTED} The API is not supported on the device. The device supports the corresponding SysCap, 87 * but does not support certain APIs in this SysCap.\n 88 * {@link DEVICE_OPERATION_FAILED} The operation on the device failed.\n 89 * @permission ohos.permission.VIBRATE 90 * 91 * @since 11 92 */ 93 int32_t OH_Vibrator_Cancel(); 94 #ifdef __cplusplus 95 } 96 #endif 97 /** @} */ 98 #endif // endif VIBRATOR_H