From f8192fbb1c1f1b6c2a5de206e4720512af0d6a10 Mon Sep 17 00:00:00 2001 From: hellohyh001 Date: Mon, 21 Aug 2023 07:36:21 +0000 Subject: [PATCH] add vib ndk Signed-off-by: hellohyh001 --- en/native_sdk/vibrator/vibrator.h | 71 ++++++++++++++++++++ en/native_sdk/vibrator/vibrator_type.h | 82 +++++++++++++++++++++++ zh-cn/native_sdk/vibrator/vibrator.h | 70 +++++++++++++++++++ zh-cn/native_sdk/vibrator/vibrator_type.h | 82 +++++++++++++++++++++++ 4 files changed, 305 insertions(+) create mode 100644 en/native_sdk/vibrator/vibrator.h create mode 100644 en/native_sdk/vibrator/vibrator_type.h create mode 100644 zh-cn/native_sdk/vibrator/vibrator.h create mode 100644 zh-cn/native_sdk/vibrator/vibrator_type.h diff --git a/en/native_sdk/vibrator/vibrator.h b/en/native_sdk/vibrator/vibrator.h new file mode 100644 index 00000000..dbede0a8 --- /dev/null +++ b/en/native_sdk/vibrator/vibrator.h @@ -0,0 +1,71 @@ +/* + * 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 Vibrator + * @{ + * + * @brief Provides APIs for vibrator services to access the vibrator driver. + * @since 11 + */ + +/** + * @file vibrator.h + * + * @brief Declares the APIs for starting or stopping vibration. + * @since 11 + */ + +#ifndef VIBRATOR_H +#include +#include "vibrator_type.h" +#define VIBRATOR_H + +#ifdef __cplusplus +extern "C" { +#endif + +namespace OHOS { +namespace Sensors { +/** + * @brief Controls the vibrator to vibrate continuously for a given duration. + * + * @param duration Vibration duration, in milliseconds. + * @param attribute Vibration attribute. For details, see {@link VibrateAttribute}. + * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. + * + * @since 11 + */ +int32_t OH_Vibrator_PlayVibration(int32_t duration, struct VibrateAttribute attribute); + +/** + * @brief Controls the vibrator to vibrate with the custom sequence. + * + * @param fileDescription File descriptor of the custom vibration effect. + * For details, see {@link VibrateFileDescription}. + * @param attribute Vibration attribute. For details, see {@link VibrateAttribute}. + * @return Returns 0 if the operation is successful; returns a non-zero value otherwise. + * + * @since 11 + */ +int32_t OH_Vibrator_PlayVibrationCustom(struct VibrateFileDescription fileDescription, + struct VibrateAttribute attribute); +} // namespace Sensors +} // namespace OHOS +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // endif VIBRATOR_H diff --git a/en/native_sdk/vibrator/vibrator_type.h b/en/native_sdk/vibrator/vibrator_type.h new file mode 100644 index 00000000..4754f2c1 --- /dev/null +++ b/en/native_sdk/vibrator/vibrator_type.h @@ -0,0 +1,82 @@ +/* + * 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 VIBRATOR_TYPE_H +#define VIBRATOR_TYPE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Enumerates vibration usages. + * + * @since 11 + */ +enum VibratorUsage { + /**< Vibration is used for unknown, lowest priority */ + USAGE_UNKNOWN = 0, + /**< Vibration is used for alarm */ + USAGE_ALARM = 1, + /**< Vibration is used for ring */ + USAGE_RING = 2, + /**< Vibration is used for notification */ + USAGE_NOTIFICATION = 3, + /**< Vibration is used for communication */ + USAGE_COMMUNICATION = 4, + /**< Vibration is used for touch */ + USAGE_TOUCH = 5, + /**< Vibration is used for media */ + USAGE_MEDIA = 6, + /**< Vibration is used for physical feedback */ + USAGE_PHYSICAL_FEEDBACK = 7, + /**< Vibration is used for simulate reality */ + USAGE_SIMULATE_REALITY = 8, + USAGE_MAX = 9 +}; + +/** + * @brief Defines the vibrator attribute. + * + * @since 11 + */ +struct VibrateAttribute { + /**< Vibrator ID. */ + int32_t id; + /**< Vibration scenario. */ + VibratorUsage usage; +}; + +/** + * @brief Defines the vibration file description. + * + * @since 11 + */ +struct VibrateFileDescription { + /**< File handle of the custom vibration sequence. */ + int32_t fd; + /**< Offset address of the custom vibration sequence. */ + int64_t offset; + /**< Total length of the custom vibration sequence. */ + int64_t length; +}; +/** @} */ +#ifdef __cplusplus +}; +#endif + +#endif // endif VIBRATOR_TYPE_H diff --git a/zh-cn/native_sdk/vibrator/vibrator.h b/zh-cn/native_sdk/vibrator/vibrator.h new file mode 100644 index 00000000..6f32faf8 --- /dev/null +++ b/zh-cn/native_sdk/vibrator/vibrator.h @@ -0,0 +1,70 @@ +/* + * 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 vibrator.h + * + * @brief 为您提供标准的开放api,用于控制马达振动的启停。 + * @since 11 + */ + +#ifndef VIBRATOR_H +#include +#include "vibrator_type.h" +#define 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 fileDescription 自定义振动效果文件描述符,请参阅{@Link VibrateFileDescription}。 + * @param attribute 振动属性,请参考{@Link VibrateAttribute}。 + * @return 如果操作成功,则返回0;否则返回非零值。 + * + * @since 11 + */ +int32_t OH_Vibrator_PlayVibrationCustom(struct VibrateFileDescription fileDescription, + struct VibrateAttribute attribute); +} // namespace Sensors +} // namespace OHOS +#ifdef __cplusplus +}; +#endif +/** @} */ +#endif // endif VIBRATOR_H \ No newline at end of file diff --git a/zh-cn/native_sdk/vibrator/vibrator_type.h b/zh-cn/native_sdk/vibrator/vibrator_type.h new file mode 100644 index 00000000..65e6e8b1 --- /dev/null +++ b/zh-cn/native_sdk/vibrator/vibrator_type.h @@ -0,0 +1,82 @@ +/* + * 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 VIBRATOR_TYPE_H +#define VIBRATOR_TYPE_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief 振动优先级。 + * + * @since 11 + */ +enum VibratorUsage { + /**< 未知场景 */ + USAGE_UNKNOWN = 0, + /**< 报警 */ + USAGE_ALARM = 1, + /**< 铃声 */ + USAGE_RING = 2, + /**< 通知 */ + USAGE_NOTIFICATION = 3, + /**< 通信 */ + USAGE_COMMUNICATION = 4, + /**< 触摸 */ + USAGE_TOUCH = 5, + /**< 媒体 */ + USAGE_MEDIA = 6, + /**< 物理反馈 */ + USAGE_PHYSICAL_FEEDBACK = 7, + /**< 模拟现实 */ + USAGE_SIMULATE_REALITY = 8, + USAGE_MAX = 9 +}; + +/** + * @brief 马达属性。 + * + * @since 11 + */ +struct VibrateAttribute { + /**< 马达ID */ + int32_t id; + /**< 振动场景 */ + VibratorUsage usage; +}; + +/** + * @brief 振动文件描述。 + * + * @since 11 + */ +struct VibrateFileDescription { + /**< 自定义振动序列的文件句柄。 */ + int32_t fd; + /**< 自定义振动序列的偏移地址。 */ + int64_t offset; + /**< 自定义振动序列的总长度。 */ + int64_t length; +}; +/** @} */ +#ifdef __cplusplus +}; +#endif + +#endif // endif VIBRATOR_TYPE_H \ No newline at end of file -- Gitee