diff --git a/zh-cn/native_sdk/vibrator/ndk_vibrator.h b/zh-cn/native_sdk/vibrator/ndk_vibrator.h new file mode 100644 index 0000000000000000000000000000000000000000..e4b337e7b9fa544fd7c34eef3a40606a94c7228b --- /dev/null +++ b/zh-cn/native_sdk/vibrator/ndk_vibrator.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @addtogroup 马达 + * @{ + * + * @brief 提为马达服务提供统一的API以访问马达驱动程序。 + * @since 11 + */ + +/** + * @file ndk_vibrator.h + * + * @brief 声明用于启动或停止马达的函数。 + * @since 11 + */ + +#ifndef NDK_VIBRATOR_H +#include +#include "ndk_vibrator_type.h" +#include "vibrator_agent.h" +#define NDK_VIBRATOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +namespace OHOS { +namespace Sensors { +/** + * @brief 控制马达执行给定持续时间的单次振动。 + * + * @param duration 表示单次振动持续的持续时间,以毫秒为单位。 + * @param attribute 表示马达的属性。关于细节,请参阅{@link VibrateAttribute}。 + * @return 如果操作成功,则返回0;否则返回负值。 + * + * @since 11 + */ +int32_t OH_Vibrator_PlayVibration(int32_t duration, struct VibrateAttribute attribute); +/** + * @brief 根据传入的振动效果启动马达。 + * + * @param effect 表示振动效果。关于细节,请参阅{@link VibrateEffect}。 + * @param attribute 表示马达的属性。关于细节,请参阅{@link VibrateAttribute}。 + * @return 如果操作成功,则返回0;否则返回负值。 + * + * @since 11 + */ +int32_t OH_Vibrator_PlayVibrationCustom(struct VibrateFileDescription fileDescription, struct VibrateAttribute attribute); +/** + * @brief 播放自定义振动序列。 + * + * @param fd 表示自定义振动序列的文件描述。关于细节,请参阅{@link HapticFileDiscriptor}。 + * @param attribute 表示马达的属性。关于细节,请参阅{@link VibrateAttribute}。 + * @return 如果操作成功,则返回0;否则返回负值。 + * + * @since 11 + */ +int32_t OH_Vibrator_PlayVibrationEvent(struct VibrateEffect vibrateEffect, struct VibrateAttribute attribute); + +#ifdef __cplusplus +}; +} +} +#endif +/** @} */ +#endif // endif NDK_VIBRATOR_H \ No newline at end of file diff --git a/zh-cn/native_sdk/vibrator/ndk_vibrator_type.h b/zh-cn/native_sdk/vibrator/ndk_vibrator_type.h new file mode 100644 index 0000000000000000000000000000000000000000..6c4a50d5f72460ecb0d772bed2c6bb7c5442897a --- /dev/null +++ b/zh-cn/native_sdk/vibrator/ndk_vibrator_type.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef NDK_VIBRATOR_TYPE_H +#define NDK_VIBRATOR_TYPE_H + +#include +#include "vibrator_agent_type.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 振动事件类型。 + * + * @since 11 + */ +enum VibrateEventType { + /**< 无效振动类型 */ + VIBRATE_TYPE_INVALID = 0, + /**< 瞬时振动类型 */ + VIBRATE_TYPE_TRANSIENT = 1, + /**< 连续振动类型 */ + VIBRATE_TYPE_CONTINUOUS = 2 +}; + +/** + * @brief 自定义振动效果。 + * + * @since 11 + */ +struct VibrateEvent { + /**< 振动事件类型 */ + enum VibrateEventType type; + /**< 振动开始时间 */ + int32_t startTime; + /**< 振动持续时长 */ + int32_t duration; + /**< 振动强度 */ + int32_t intensity; + /**< 振动频率 */ + int32_t frequency; +}; + +/** + * @brief 马达属性。 + * + * @since 11 + */ +struct VibrateAttribute { + /**< 马达ID */ + int32_t id; + /**< 振动场景 */ + enum VibratorUsage usage; +}; + +/** + * @brief 振动效果。 + * + * @since 11 + */ +struct VibrateEffect { + /**< 事件个数 */ + int32_t count; + /**< 振动事件 */ + struct VibrateEvent* vibrateEvents; +}; + +/** + * @brief 振动文件描述。 + * + * @since 11 + */ +struct VibrateFileDescription { + /**< 自定义振动序列的文件句柄。 */ + int32_t fd; + /**< 自定义振动序列的偏移地址。 */ + int64_t offset; + /**< 自定义振动序列的总长度。 */ + int64_t length; +}; +/** @} */ +#ifdef __cplusplus +}; +#endif + +#endif // endif NDK_VIBRATOR_TYPE_H \ No newline at end of file