From 2a3a1b3f4ce2f9b92a2e7e2644c53eb040a95a74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=BE=8E=E4=BA=AE?= Date: Tue, 27 May 2025 21:32:56 +0800 Subject: [PATCH 1/4] modify vibrate taihe Signed-off-by:zzzzl-top MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周澎亮 --- bundle.json | 6 +- frameworks/ets/taihe/BUILD.gn | 115 +++ .../taihe/author/src/ohos.vibrator.impl.cpp | 446 +++++++++++ .../ets/taihe/author/src/vibrator_ani.cpp | 29 + frameworks/ets/taihe/idl/ohos.vibrator.taihe | 700 ++++++++++++++++++ frameworks/ets/taihe/user/main.ets | 81 ++ 6 files changed, 1376 insertions(+), 1 deletion(-) create mode 100644 frameworks/ets/taihe/BUILD.gn create mode 100644 frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp create mode 100644 frameworks/ets/taihe/author/src/vibrator_ani.cpp create mode 100644 frameworks/ets/taihe/idl/ohos.vibrator.taihe create mode 100644 frameworks/ets/taihe/user/main.ets diff --git a/bundle.json b/bundle.json index 414ba52..c9eb0fd 100644 --- a/bundle.json +++ b/bundle.json @@ -60,7 +60,8 @@ "//base/sensors/miscdevice/frameworks/native/vibrator:vibrator_target", "//base/sensors/miscdevice/frameworks/native/light:light_target", "//base/sensors/miscdevice/utils:miscdevice_utils_target", - "//base/sensors/miscdevice/frameworks/capi:ohvibrator" + "//base/sensors/miscdevice/frameworks/capi:ohvibrator", + "//base/sensors/miscdevice/frameworks/ets/taihe:vibrator_taihe" ], "service_group": [ "//base/sensors/miscdevice/services/miscdevice_service:miscdevice_service_target", @@ -68,6 +69,9 @@ ] }, "inner_kits": [ + { + "name": "//base/sensors/miscdevice/frameworks/ets/taihe:copy_taihe" + }, { "name": "//base/sensors/miscdevice/frameworks/native/vibrator:vibrator_interface_native", "header": { diff --git a/frameworks/ets/taihe/BUILD.gn b/frameworks/ets/taihe/BUILD.gn new file mode 100644 index 0000000..d0e40a5 --- /dev/null +++ b/frameworks/ets/taihe/BUILD.gn @@ -0,0 +1,115 @@ +# Copyright (c) 2025 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. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("./../../../miscdevice.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") + +subsystem_name = "sensors" +part_name = "miscdevice" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +copy_taihe_idl("copy_taihe") { + sources = [ + "idl/ohos.vibrator.taihe", + ] + + external_deps = [] +} + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_taihe" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.vibrator.abi.c", + "$taihe_generated_file_path/src/ohos.vibrator.ani.cpp", + ] +} + +taihe_shared_library("vibrator_taihe_native") { + branch_protector_ret = "pac_ret" + sanitize = { + boundary_sanitize = true + cfi = true + cfi_cross_dso = true + debug = false + integer_overflow = true + ubsan = true + } + taihe_generated_file_path = "$taihe_generated_file_path" + subsystem_name = "$subsystem_name" + part_name = "$part_name" + include_dirs = [ + "$SUBSYSTEM_DIR/interfaces/inner_api/vibrator", + "$SUBSYSTEM_DIR/frameworks/js/napi/vibrator/include", + "$SUBSYSTEM_DIR/utils/common/include", + ] + defines = [ + "APP_LOG_TAG = \"VibratorImpl\"", + "LOG_DOMAIN = 0xD002700", + ] + sources = get_target_outputs(":run_taihe") + sources += [ + "author/src/ani_constructor.cpp", + "author/src/ohos.vibrator.impl.cpp", + ] + deps = [ + ":run_taihe", + "$SUBSYSTEM_DIR/frameworks/native/vibrator:vibrator_interface_native", + "$SUBSYSTEM_DIR/utils/common:libmiscdevice_utils", + ] + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + ] +} + +generate_static_abc("vibrator_abc") { + base_url = "$taihe_generated_file_path" + files = [ + "$taihe_generated_file_path/@ohos.base.ets", + "$taihe_generated_file_path/@ohos.vibrator.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/vibrator_abc.abc" + dependencies = [ ":run_taihe" ] +} + +generate_static_abc("vibrator_test") { + base_url = "user" + files = [ + "user/main.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/vibrator_test.abc" + dependencies = [ ":run_taihe" ] +} + +ohos_prebuilt_etc("vibrator_etc") { + source = "$target_out_dir/vibrator_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ + ":vibrator_abc", + ":vibrator_test" + ] +} + +group("vibrator_taihe") { + deps = [ + ":vibrator_etc", + ":vibrator_taihe_native", + ] +} diff --git a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp new file mode 100644 index 0000000..6696463 --- /dev/null +++ b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp @@ -0,0 +1,446 @@ +/* + * Copyright (c) 2025 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. + */ + +#include +#include + +#include "ohos.vibrator.proj.hpp" +#include "ohos.vibrator.impl.hpp" +#include "stdexcept" +#include "taihe/runtime.hpp" + +#include "file_utils.h" +#include "miscdevice_log.h" +#include "sensors_errors.h" +#include "vibrator_agent.h" + +#undef LOG_TAG +#define LOG_TAG "VibratorImpl" + +namespace { +using namespace OHOS::Sensors; + +constexpr int32_t INTENSITY_ADJUST_MAX = 100; +constexpr int32_t EVENT_START_TIME_MAX = 1800000; +constexpr int32_t EVENT_NUM_MAX = 128; +constexpr int32_t INTENSITY_MIN = 0; +constexpr int32_t INTENSITY_MAX = 100; +constexpr int32_t FREQUENCY_MIN = 0; +constexpr int32_t FREQUENCY_MAX = 100; +constexpr int32_t CURVE_POINT_INTENSITY_MAX = 100; +constexpr int32_t CURVE_POINT_NUM_MIN = 4; +constexpr int32_t CURVE_POINT_NUM_MAX = 16; +constexpr int32_t CURVE_FREQUENCY_MIN = -100; +constexpr int32_t CURVE_FREQUENCY_MAX = 100; +constexpr int32_t CONTINUOUS_DURATION_MAX = 5000; +constexpr int32_t EVENT_INDEX_MAX = 2; + +static std::map g_usageType = { + {"unknown", USAGE_UNKNOWN}, + {"alarm", USAGE_ALARM}, + {"ring", USAGE_RING}, + {"notification", USAGE_NOTIFICATION}, + {"communication", USAGE_COMMUNICATION}, + {"touch", USAGE_TOUCH}, + {"media", USAGE_MEDIA}, + {"physicalFeedback", USAGE_PHYSICAL_FEEDBACK}, + {"simulateReality", USAGE_SIMULATE_REALITY}, +}; + +static std::set g_allowedTypes = {"time", "preset", "file", "pattern"}; + +struct VibrateInfo { + std::string type; + std::string usage; + bool systemUsage {false}; + int32_t duration = 0; + std::string effectId; + int32_t count = 0; + int32_t fd = -1; + int64_t offset = 0; + int64_t length = -1; + int32_t intensity = 0; + VibratorPattern vibratorPattern; +}; + +void stopVibrationByModeSync(::ohos::vibrator::VibratorStopMode stopMode) { + CALL_LOG_ENTER; + StopVibrator(stopMode.get_value()); +} + +static bool ParseVibratorCurvePoint(::taihe::array<::ohos::vibrator::VibratorCurvePoint> pointsArray, uint32_t index, + VibratorCurvePoint &point) +{ + CALL_LOG_ENTER; + point.time = pointsArray[index].time; + point.intensity = pointsArray[index].intensity.has_value() ? pointsArray[index].intensity.value() : 0; + point.frequency = pointsArray[index].frequency.has_value() ? pointsArray[index].frequency.value() : 0; + return true; +} + +static bool ParseVibratorCurvePointArray(::taihe::array<::ohos::vibrator::VibratorCurvePoint> pointsArray, + uint32_t pointsLength, VibratorEvent &event) +{ + CALL_LOG_ENTER; + if (pointsLength <= 0 || pointsLength > CURVE_POINT_NUM_MAX) { + MISC_HILOGE("pointsLength should not be less than or equal to 0 or greater than CURVE_POINT_NUM_MAX"); + return false; + } + VibratorCurvePoint *points = + static_cast(malloc(sizeof(VibratorCurvePoint) * pointsLength)); + if (points == nullptr) { + MISC_HILOGE("points is nullptr"); + return false; + } + for (uint32_t i = 0; i < pointsLength; ++i) { + if (!ParseVibratorCurvePoint(pointsArray, i, points[i])) { + MISC_HILOGE("ParseVibratorCurvePoint failed"); + free(points); + points = nullptr; + return false; + } + } + event.points = points; + return true; +} + +static bool ParseVibrateEvent(::taihe::array<::ohos::vibrator::VibratorEvent> eventArray, int32_t index, + VibratorEvent &event) +{ + CALL_LOG_ENTER; + ::ohos::vibrator::VibratorEvent vibratorEvent = eventArray[index]; + event.type = static_cast(static_cast(vibratorEvent.eventType)); + event.time = vibratorEvent.time; + event.duration = vibratorEvent.duration.has_value() ? vibratorEvent.duration.value() : 0; + event.intensity = vibratorEvent.intensity.has_value() ? vibratorEvent.intensity.value() : 0; + event.frequency = vibratorEvent.frequency.has_value() ? vibratorEvent.frequency.value() : 0; + event.index = vibratorEvent.index.has_value() ? vibratorEvent.index.value() : 0; + if (!vibratorEvent.points.has_value()) { + MISC_HILOGI("has no points"); + return true; + } + ::taihe::array<::ohos::vibrator::VibratorCurvePoint> points = vibratorEvent.points.value(); + std::size_t size = points.size(); + event.pointNum = static_cast(size); + if (size <= 0) { + MISC_HILOGI("has zero points"); + return true; + } + if (!ParseVibratorCurvePointArray(points, event.pointNum, event)) { + MISC_HILOGE("ParseVibratorCurvePointArray failed"); + return false; + } + return true; +} + +static bool ParseVibratorPattern(::ohos::vibrator::VibratorPattern pattern, VibrateInfo &vibrateInfo) +{ + CALL_LOG_ENTER; + vibrateInfo.vibratorPattern.time = pattern.time; + vibrateInfo.vibratorPattern.eventNum = pattern.events.size(); + if (vibrateInfo.vibratorPattern.eventNum <= 0 || vibrateInfo.vibratorPattern.eventNum > EVENT_NUM_MAX) { + MISC_HILOGE("length should not be less than or equal to 0 or greater than EVENT_NUM_MAX"); + return false; + } + VibratorEvent *events = static_cast(malloc(sizeof(VibratorEvent) * vibrateInfo.vibratorPattern.eventNum)); + if (events == nullptr) { + MISC_HILOGE("Events is nullptr"); + return false; + } + for (int32_t j = 0; j < vibrateInfo.vibratorPattern.eventNum; ++j) { + new (&events[j]) VibratorEvent(); + if (!ParseVibrateEvent(pattern.events, j, events[j])) { + MISC_HILOGE("ParseVibrateEvent failed"); + free(events); + events = nullptr; + return false; + } + } + vibrateInfo.vibratorPattern.events = events; + return true; +} + +static void PrintVibratorPattern(::ohos::vibrator::VibratorPattern &vibratorPattern) +{ + CALL_LOG_ENTER; + if (vibratorPattern.events.empty()) { + MISC_HILOGE("Events is empty"); + return; + } + MISC_HILOGD("PrintVibratorPattern, time:%{public}d, eventNum:%{public}lu", + vibratorPattern.time, vibratorPattern.events.size()); + for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { + MISC_HILOGD("PrintVibratorPattern, type:%{public}d, time:%{public}d, duration:%{public}d, \ + intensity:%{public}d, frequency:%{public}d, index:%{public}d, pointNum:%{public}lu", + static_cast(vibratorPattern.events[i].eventType), vibratorPattern.events[i].time, + vibratorPattern.events[i].duration.value(), vibratorPattern.events[i].intensity.value(), + vibratorPattern.events[i].frequency.value(), vibratorPattern.events[i].index.value(), + vibratorPattern.events[i].points.value().size()); + if ((!vibratorPattern.events[i].points.has_value()) || vibratorPattern.events[i].points.value().size() <= 0) { + MISC_HILOGE("points is empty"); + return; + } + ::taihe::array<::ohos::vibrator::VibratorCurvePoint> point = vibratorPattern.events[i].points.value(); + for (int32_t j = 0; j < vibratorPattern.events[i].points.value().size(); ++j) { + MISC_HILOGD("PrintVibratorPattern, time:%{public}d, intensity:%{public}d, frequency:%{public}d", + point[j].time, point[j].intensity.value(), point[j].frequency.value()); + } + } +} + +static bool CheckVibratorCurvePoint(const ::ohos::vibrator::VibratorEvent &event) +{ + CALL_LOG_ENTER; + if ((!event.points.has_value()) || (event.points.value().size() < CURVE_POINT_NUM_MIN) || (event.points.value().size() > CURVE_POINT_NUM_MAX)) { + MISC_HILOGE("The points size is out of range, pointNum:%{public}lu", event.points.value().size()); + return false; + } + for (int32_t j = 0; j < event.points.value().size(); ++j) { + if ((event.points.value()[j].time < 0) || (event.points.value()[j].time > event.duration.value())) { + MISC_HILOGE("time in points is out of range, time:%{public}d", event.points.value()[j].time); + return false; + } + if ((event.points.value()[j].intensity.value() < 0) || + (event.points.value()[j].intensity.value() > CURVE_POINT_INTENSITY_MAX)) { + MISC_HILOGE("intensity in points is out of range, intensity:%{public}d", + event.points.value()[j].intensity.value()); + return false; + } + if ((event.points.value()[j].frequency.value() < CURVE_FREQUENCY_MIN) || + (event.points.value()[j].frequency.value() > CURVE_FREQUENCY_MAX)) { + MISC_HILOGE("frequency in points is out of range, frequency:%{public}d", + event.points.value()[j].frequency.value()); + return false; + } + } + return true; +} + +static bool CheckVibratorEvent(const ::ohos::vibrator::VibratorEvent &event) +{ + CALL_LOG_ENTER; + if ((event.time < 0) || (event.time > EVENT_START_TIME_MAX)) { + MISC_HILOGE("The event time is out of range, time:%{public}d", event.time); + return false; + } + if ((!event.frequency.has_value()) || (event.frequency.value() < FREQUENCY_MIN) || + (event.frequency.value() > FREQUENCY_MAX)) { + MISC_HILOGE("The event frequency is out of range, frequency:%{public}d", event.frequency.value()); + return false; + } + if ((!event.intensity.has_value()) || (event.intensity.value() < INTENSITY_MIN) || + (event.intensity.value() > INTENSITY_MAX)) { + MISC_HILOGE("The event intensity is out of range, intensity:%{public}d", event.intensity.value()); + return false; + } + if ((!event.duration.has_value()) || (event.duration.value() <= 0) || + (event.duration.value() > CONTINUOUS_DURATION_MAX)) { + MISC_HILOGE("The event duration is out of range, duration:%{public}d", event.duration.value()); + return false; + } + if ((!event.index.has_value()) || (event.index.value() < 0) || (event.index.value() > EVENT_INDEX_MAX)) { + MISC_HILOGE("The event index is out of range, index:%{public}d", event.index.value()); + return false; + } + if ((event.eventType == VibratorEventType::EVENT_TYPE_CONTINUOUS) && (event.points.value().size() > 0)) { + if (!CheckVibratorCurvePoint(event)) { + MISC_HILOGE("CheckVibratorCurvePoint failed"); + return false; + } + } + return true; +} + +static bool CheckVibratorPatternParameter(::ohos::vibrator::VibratorPattern &vibratorPattern) +{ + CALL_LOG_ENTER; + if (vibratorPattern.events.empty()) { + MISC_HILOGE("Events is empty"); + return false; + } + if ((vibratorPattern.events.size() <= 0) || (vibratorPattern.events.size() > EVENT_NUM_MAX)) { + MISC_HILOGE("The event num is out of range, eventNum:%{public}lu", vibratorPattern.events.size()); + return false; + } + for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { + if (!CheckVibratorEvent(vibratorPattern.events[i])) { + MISC_HILOGE("CheckVibratorEvent failed"); + return false; + } + } + return true; +} + +bool ParseParameter(::ohos::vibrator::VibrateEffect const& effect, ::ohos::vibrator::VibrateAttribute const& attribute, + VibrateInfo &vibrateInfo) +{ + CALL_LOG_ENTER; + if (effect.holds_VibrateTime_type()) { + vibrateInfo.type = "time"; + ::ohos::vibrator::VibrateTime vibrateTime = effect.get_VibrateTime_type_ref(); + vibrateInfo.duration = vibrateTime.duration; + } else if (effect.holds_VibratePreset_type()) { + vibrateInfo.type = "preset"; + ::ohos::vibrator::VibratePreset vibratePreset = effect.get_VibratePreset_type_ref(); + vibrateInfo.effectId = vibratePreset.effectId; + vibrateInfo.count = vibratePreset.count.has_value() ? vibratePreset.count.value() : 1; + vibrateInfo.intensity = vibratePreset.intensity.has_value() ? vibratePreset.intensity.value() : INTENSITY_ADJUST_MAX; + } else if (effect.holds_VibrateFromFile_type()) { + vibrateInfo.type = "file"; + ::ohos::vibrator::VibrateFromFile vibrateFromFile = effect.get_VibrateFromFile_type_ref(); + vibrateInfo.fd = vibrateFromFile.hapticFd.fd; + vibrateInfo.offset = vibrateFromFile.hapticFd.offset.has_value() ? vibrateFromFile.hapticFd.offset.value() : 0; + int64_t fdSize = GetFileSize(vibrateInfo.fd); + CHKCR((vibrateInfo.offset >= 0) && (vibrateInfo.offset <= fdSize), false, "The parameter of offset is invalid"); + vibrateInfo.length = vibrateFromFile.hapticFd.length.has_value() ? vibrateFromFile.hapticFd.length.value() : fdSize - vibrateInfo.offset; + } else if (effect.holds_VibrateFromPattern_type()) { + vibrateInfo.type = "pattern"; + ::ohos::vibrator::VibrateFromPattern vibrateFromPattern = effect.get_VibrateFromPattern_type_ref(); + ParseVibratorPattern(vibrateFromPattern.pattern, vibrateInfo); + PrintVibratorPattern(vibrateFromPattern.pattern); + CHKCF(CheckVibratorPatternParameter(vibrateFromPattern.pattern), "CheckVibratorPatternParameter fail"); + } + vibrateInfo.usage = attribute.usage; + vibrateInfo.systemUsage = attribute.systemUsage.has_value() ? attribute.systemUsage.value() : false; + return true; +} + +bool SetUsageInner(const std::string &usage, bool systemUsage) +{ + CALL_LOG_ENTER; + if (auto iter = g_usageType.find(usage); iter == g_usageType.end()) { + taihe::set_business_error(PARAMETER_ERROR, "Wrong usage type " + usage); + return false; + } + return SetUsage(g_usageType[usage], systemUsage); +} + +int32_t CheckParameters(const VibrateInfo &info) +{ + CALL_LOG_ENTER; + if (!SetUsageInner(info.usage, info.systemUsage)) { + MISC_HILOGE("SetUsage fail"); + taihe::set_business_error(PARAMETER_ERROR, "Parameters invalid"); + return PARAMETER_ERROR; + } + if (g_allowedTypes.find(info.type) == g_allowedTypes.end()) { + MISC_HILOGE("Invalid vibrate type, type:%{public}s", info.type.c_str()); + taihe::set_business_error(PARAMETER_ERROR, "Parameters invalid"); + return PARAMETER_ERROR; + } + return OHOS::ERR_OK; +} + +int32_t StartVibrate(const VibrateInfo &info) +{ + CALL_LOG_ENTER; + if (CheckParameters(info) != OHOS::ERR_OK) { + taihe::set_business_error(PARAMETER_ERROR, "Parameters invalid"); + MISC_HILOGE("CheckParameters fail"); + return PARAMETER_ERROR; + } + if (info.type == "file") { + return PlayVibratorCustom(info.fd, info.offset, info.length); + } else if (info.type == "pattern") { + return PlayPattern(info.vibratorPattern); + } + return StartVibratorOnce(info.duration); +} + +bool ClearVibratorPattern(VibratorPattern &vibratorPattern) +{ + CALL_LOG_ENTER; + int32_t eventSize = vibratorPattern.eventNum; + if ((eventSize <= 0) || (vibratorPattern.events == nullptr)) { + MISC_HILOGW("events is not need to free, eventSize:%{public}d", eventSize); + return false; + } + auto events = vibratorPattern.events; + for (int32_t j = 0; j < eventSize; ++j) { + if (events[j].points != nullptr) { + free(events[j].points); + events[j].points = nullptr; + } + } + free(events); + events = nullptr; + return true; +} + +void startVibrationSync(::ohos::vibrator::VibrateEffect const& effect, ::ohos::vibrator::VibrateAttribute const& attribute) +{ + CALL_LOG_ENTER; + VibrateInfo vibrateInfo = {}; + if (!ParseParameter(effect, attribute, vibrateInfo)) { + MISC_HILOGE("ParseParameter fail"); + taihe::set_business_error(PARAMETER_ERROR, "ParseParameter fail"); + return; + } + if (vibrateInfo.type == "preset") { + if (!SetLoopCount(vibrateInfo.count) || CheckParameters(vibrateInfo) != OHOS::ERR_OK || + vibrateInfo.effectId.empty()) { + MISC_HILOGE("SetLoopCount fail or parameter invalid"); + taihe::set_business_error(PARAMETER_ERROR, "SetLoopCount fail or parameter invalid"); + return; + } + int32_t ret = PlayPrimitiveEffect(vibrateInfo.effectId.c_str(), vibrateInfo.intensity); + if (ret != SUCCESS) { + taihe::set_business_error(PARAMETER_ERROR, "start vibrator failed"); + return; + } + } else { + int32_t ret = StartVibrate(vibrateInfo); + if (vibrateInfo.vibratorPattern.events != nullptr) { + CHKCV(ClearVibratorPattern(vibrateInfo.vibratorPattern), "ClearVibratorPattern fail"); + } + if (ret == PARAMETER_ERROR) { + taihe::set_business_error(PARAMETER_ERROR, "Parameters invalid"); + return; + } + } +} + +bool isHdHapticSupported() { + CALL_LOG_ENTER; + return IsHdHapticSupported(); +} + +void stopVibrationSync() { + CALL_LOG_ENTER; + int32_t ret = Cancel(); + if (ret != SUCCESS) { + taihe::set_business_error(ret, "Cancel execution fail"); + } +} + +bool isSupportEffectSync(::taihe::string_view effectId) { + CALL_LOG_ENTER; + bool isSupportEffect = false; + int32_t ret = IsSupportEffect(effectId.c_str(), &isSupportEffect); + if (ret != SUCCESS) { + taihe::set_business_error(ret, "IsSupportEffect execution failed"); + } + return isSupportEffect; +} +} // namespace + +// Since these macros are auto-generate, lint will cause false positive. +// NOLINTBEGIN +TH_EXPORT_CPP_API_stopVibrationByModeSync(stopVibrationByModeSync); +TH_EXPORT_CPP_API_startVibrationSync(startVibrationSync); +TH_EXPORT_CPP_API_isHdHapticSupported(isHdHapticSupported); +TH_EXPORT_CPP_API_stopVibrationSync(stopVibrationSync); +TH_EXPORT_CPP_API_isSupportEffectSync(isSupportEffectSync); +// NOLINTEND diff --git a/frameworks/ets/taihe/author/src/vibrator_ani.cpp b/frameworks/ets/taihe/author/src/vibrator_ani.cpp new file mode 100644 index 0000000..b252a93 --- /dev/null +++ b/frameworks/ets/taihe/author/src/vibrator_ani.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2025 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. + */ + +#include "taihe/runtime.hpp" +#include "ohos.vibrator.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) { + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::vibrator::ANIRegister(env)) { + std::cerr << "Error from ohos::vibrator::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} \ No newline at end of file diff --git a/frameworks/ets/taihe/idl/ohos.vibrator.taihe b/frameworks/ets/taihe/idl/ohos.vibrator.taihe new file mode 100644 index 0000000..26e6fea --- /dev/null +++ b/frameworks/ets/taihe/idl/ohos.vibrator.taihe @@ -0,0 +1,700 @@ +/* + * Copyright (c) 2025 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. + */ + +@!namespace("@ohos.vibrator", "vibrator") + +/** + * Preset vibration type vibration effect. + * + * @interface VibratePreset + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +struct VibratePreset { + /** + * The value is "preset", which triggers motor vibration according to preset vibration effect. + * + * @type { 'preset' } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + type: 'preset'; + + /** + * Preset type vibration. + * + * @type { String } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + effectId: String; + + /** + * The number of vibration repetitions. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The number of vibration repetitions. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 12 + */ + count: Optional; + + /** + * The intensity of vibration effect. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 12 + */ + intensity: Optional; +} + +/** + * Vibrate continuously for a period of time at the default intensity of the system. + * + * @interface VibrateTime + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * Vibrate continuously for a period of time at the default intensity of the system. + * + * @interface VibrateTime + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +struct VibrateTime { + /** + * The value is "time", which triggers the motor vibration according to the specified duration. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The value is "time", which triggers the motor vibration according to the specified duration. + * + * @type { 'time' } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + type: 'time'; + + /** + * The duration of the vibration, in ms. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The duration of the vibration, in ms. + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + duration: i32; /** The duration of the vibration, in ms */ +} + +/** + * The use of vibration. + * + * @typedef {'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' | + * 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'} + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * The use of vibration. + * + * @typedef {'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' | + * 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'} + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +@!sts_inject(""" + type Usage = 'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' | + 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'; +""") + +/** + * The attribute of vibration. + * + * @interface VibrateAttribute + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * The attribute of vibration. + * + * @interface VibrateAttribute + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +struct VibrateAttribute { + /** + * Vibrator id, default is 0. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * Vibrator id, default is 0. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + id: Optional; + + /** + * The use of vibration. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ + /** + * The use of vibration. + * + * @type { String } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ + usage: String; + + /** + * Indicates whether to bypass system management switches. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @systemapi + * @since 12 + */ + systemUsage: Optional; +} + +/** + * Preset vibration effect string. + * + * @enum { String } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ +enum EffectId: String { + /** + * Describes the vibration effect of the vibrator when a user adjusts the timer. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ + EFFECT_CLOCK_TIMER = 'haptic.clock.timer' +} + +/** + * Vibrator vibration stop mode. + * + * @enum { string } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ +enum VibratorStopMode: String { + /** + * Indicates the mode of stopping a one-shot vibration effect. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ + VIBRATOR_STOP_MODE_TIME = 'time', + + /** + * Indicates the mode of stopping a preset vibration effect. + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 8 + */ + VIBRATOR_STOP_MODE_PRESET = 'preset' +} + +/** + * Trigger motor vibration with custom vibration effects. + * + * @interface VibrateFromPattern + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibrateFromPattern { + /** + * The value is "pattern", which triggers motor vibration based on the combination pattern. + * + * @type { 'pattern' } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + type: 'pattern'; + + /** + * Customize the sequence of motor vibration events, the VibratorPattern object returned by the build() method. + * + * @type { VibratorPattern } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + pattern: VibratorPattern; +} + +/** + * Each 'events' attribute in the vibration sequence represents one vibration event + * + * @interface VibratorPattern + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibratorPattern { + /** + * Absolute starting time of vibration + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + time: i32; + + /** + * Vibration event array, where each 'events' attribute represents one vibration event. + * + * @type { Array } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + events: Array; +} + +/** + * Vibration event. + * + * @interface VibratorEvent + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibratorEvent { + /** + * Types of vibration events + * + * @type { VibratorEventType } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + eventType: VibratorEventType; + + /** + * Relative starting time of vibration + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + time: i32; + + /** + * The duration of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + duration: Optional; + + /** + * Intensity of vibration events + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + + /** + * Vibration event frequency + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; + + /** + * Channel number + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + index: Optional; + + /** + * An array representing vibration adjustment curves. + * + * @type { Optional> } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + points: Optional>; +} + +/** + * Types of vibration events + * + * @enum { number } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +enum VibratorEventType: i32 { + /** + * Steady state long vibration + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + CONTINUOUS = 0, + + /** + * Transient short vibration + * + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + TRANSIENT = 1, +} + +/** + * The vibration curve is valid when the vibration event type is 'continuous' + * + * @interface VibratorCurvePoint + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct VibratorCurvePoint { + /** + * The offset of the starting time of the relative event. + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + time: i32; + + /** + * Gain in relative event vibration intensity + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + /** + * Changes in relative event vibration frequency + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; +} + +/** + * The transient vibration parameters + * + * @interface TransientParam + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct TransientParam { + /** + * Intensity of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + + /** + * Frequency of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; + + /** + * Index of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + index: Optional; +} + +/** + * The continuous vibration parameters + * + * @interface ContinuousParam + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ +struct ContinuousParam { + /** + * Intensity of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + intensity: Optional; + + /** + * Frequency of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + frequency: Optional; + + /** + * The points of vibration + * + * @type { Optional> } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + points: Optional>; + + /** + * Index of vibration + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 18 + */ + index: Optional; +} + +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset | VibrateFromFile } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset | VibrateFromFile } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +/** + * Describes the effect of vibration. + * + * @typedef { VibrateTime | VibratePreset | VibrateFromFile | VibrateFromPattern } + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 18 + */ +union VibrateEffect { + VibrateTime_type: VibrateTime; + VibratePreset_type: VibratePreset; + VibrateFromFile_type: VibrateFromFile; + VibrateFromPattern_type: VibrateFromPattern; +} + +/** + * Custom vibration, vibrate the effect from a haptic file. + * + * @interface VibrateFromFile + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +struct VibrateFromFile { + /** + * The value is "file", which triggers motor vibration according to the vibration profile. + * + * @type { 'file' } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + type: 'file'; + + /** + * Haptic file descriptor, some formats are supported. + * + * @type { HapticFileDescriptor } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + hapticFd: HapticFileDescriptor; +} + +/** + * Haptic file descriptor. The caller needs to ensure that the fd is valid and + * the offset and length are correct. + * + * @interface HapticFileDescriptor + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +struct HapticFileDescriptor { + /** + * The file descriptor of haptic effect source from file system. The caller + * is responsible to close the file descriptor. + * + * @type { i32 } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + fd: i32; + + /** + * The offset into the file where the data to be read, in bytes. By default, + * the offset is zero. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + offset: Optional; + + /** + * The length in bytes of the data to be read. By default, the length is the + * rest of bytes in the file from the offset. + * + * @type { Optional } + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ + length: Optional; +} + +/** + * Stop the vibrator from vibrating. + * + * @permission ohos.permission.VIBRATE + * @param { VibratorStopMode } stopMode - Indicate the stop mode in which the motor vibrates, {@code VibratorStopMode}. + * @returns { void } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +@gen_async("stopVibration") +@gen_promise("stopVibration") +function stopVibrationByModeSync(stopMode: VibratorStopMode): void; + +/** + * Trigger vibrator vibration. + * + * @permission ohos.permission.VIBRATE + * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect}. + * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute}. + * @param { AsyncCallback } callback - The callback of startVibration. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 801 - Capability not supported. + * @throws { BusinessError } 14600101 - Device operation failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 9 + */ +/** + * Trigger vibrator vibration. + * + * @permission ohos.permission.VIBRATE + * @param { VibrateEffect } effect - Indicate vibrate effect, {@code VibrateEffect} + * @param { VibrateAttribute } attribute - Indicate vibrate attribute, {@code VibrateAttribute} + * @param { void } callback - The callback of startVibration + * @throws { BusinessError } 201 - Permission denied + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @throws { BusinessError } 801 - Capability not supported + * @throws { BusinessError } 14600101 - Device operation failed + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 11 + */ +@gen_async("startVibration") +@gen_promise("startVibration") +function startVibrationSync(effect: VibrateEffect, attribute: VibrateAttribute): void; + +/** + * Whether the high-definition haptic is supported. + * + * @returns { bool } Returns whether the high-definition haptic is supported. + * @throws { BusinessError } 14600101 - Device operation failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 12 + */ +function isHdHapticSupported(): bool; + +/** + * Stop any type of vibration. + * + * @permission ohos.permission.VIBRATE + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 14600101 - Device operation failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @atomicservice + * @since 12 + */ +@gen_async("stopVibration") +@gen_promise("stopVibration") +function stopVibrationSync(): void; + +/** + * Whether the preset vibration effect is supported. + * + * @param { String } effectId Indicate the specified effect of the preset, {@code EffectId}. + * @returns { bool } Promise used to return the result. + * @throws { BusinessError } 201 - Permission denied. + * @throws { BusinessError } 401 - Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; + *
2. Incorrect parameter types; 3. Parameter verification failed. + * @syscap SystemCapability.Sensors.MiscDevice + * @since 10 + */ +@gen_async("isSupportEffect") +@gen_promise("isSupportEffect") +function isSupportEffectSync(effectId: String): bool; \ No newline at end of file diff --git a/frameworks/ets/taihe/user/main.ets b/frameworks/ets/taihe/user/main.ets new file mode 100644 index 0000000..754d59f --- /dev/null +++ b/frameworks/ets/taihe/user/main.ets @@ -0,0 +1,81 @@ +import vibrator from "@ohos.vibrator"; +import {BusinessError} from "@ohos.base"; + +loadLibrary("vibrator_taihe_native.z"); + +function testStopVibrator() { + console.log("testStopVibrator begin"); + try { + vibrator.stopVibrationSync(); + } catch (error) { + let e: BusinessError = error as BusinessError; + console.error(`stopVibrationSync failed.Code: ${e.code}, message: ${e.message}`); + } + console.log("testStopVibrator end"); +} + +function testStartPresetVibrator() { + console.log("testStartPresetVibrator begin"); + try { + let preset: vibrator.VibratePreset = { + type: 'preset', + effectId: 'haptic.effect.soft', + count: 15, + intensity: 50, + }; + let attribute: vibrator.VibrateAttribute = { + id: 1, + usage: 'unknown', + }; + vibrator.startVibration(preset, attribute, (error: BusinessError) => { + console.info(`startVibration. Code: ${error.code}, message: ${error.message}`); + }); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`); + } + console.log("testStartPresetVibrator end"); +} + +function testStartTimeVibrator() { + console.log("testStartTimeVibrator begin"); + try { + let effect: vibrator.VibrateTime = { + type: 'time', + duration: 1000, + }; + let attribute: vibrator.VibrateAttribute = { + id: 1, + usage: 'alarm', + }; + vibrator.startVibration(effect, attribute, (error: BusinessError) => { + console.info(`startVibration. Code: ${error.code}, message: ${error.message}`); + }); + } catch (err) { + let e: BusinessError = err as BusinessError; + console.error(`An unexpected error occurred. Code: ${e.code}, message: ${e.message}`); + } + console.log("testStartTimeVibrator end"); +} + +function testIsSupportEffect() { + console.log("testIsSupportEffect begin"); + vibrator.isSupportEffect('haptic.effect.soft', (error: BusinessError, state: boolean) => { + console.info(`isSupportEffect. Code: ${error.code}, message: ${error.message}, state: ${state}`); + }); + console.log("testIsSupportEffect end"); +} + +function testIsHdHapticSupported() { + console.log("testIsHdHapticSupported begin"); + let ret = vibrator.isHdHapticSupported(); + console.log("testIsHdHapticSupported end " + ret); +} + +function main() { + testIsHdHapticSupported(); + testIsSupportEffect(); + testStartTimeVibrator(); + testStartPresetVibrator(); + testStopVibrator(); +} \ No newline at end of file -- Gitee From 3e8829faf5ab82f2c04a74c308ad6b7caf81f3b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=BE=8E=E4=BA=AE?= Date: Tue, 27 May 2025 22:04:14 +0800 Subject: [PATCH 2/4] modify vibrate taihe Signed-off-by:zzzzl-top MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周澎亮 --- .../taihe/author/src/{vibrator_ani.cpp => ani_constructor.cpp} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename frameworks/ets/taihe/author/src/{vibrator_ani.cpp => ani_constructor.cpp} (100%) diff --git a/frameworks/ets/taihe/author/src/vibrator_ani.cpp b/frameworks/ets/taihe/author/src/ani_constructor.cpp similarity index 100% rename from frameworks/ets/taihe/author/src/vibrator_ani.cpp rename to frameworks/ets/taihe/author/src/ani_constructor.cpp -- Gitee From 52a569f5091183b7bef92fb773cd39216d72a0e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=BE=8E=E4=BA=AE?= Date: Wed, 28 May 2025 14:19:00 +0800 Subject: [PATCH 3/4] modify vibrate taihe Signed-off-by:zzzzl-top MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周澎亮 --- frameworks/ets/taihe/idl/ohos.vibrator.taihe | 22 ++++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/frameworks/ets/taihe/idl/ohos.vibrator.taihe b/frameworks/ets/taihe/idl/ohos.vibrator.taihe index 26e6fea..5a90819 100644 --- a/frameworks/ets/taihe/idl/ohos.vibrator.taihe +++ b/frameworks/ets/taihe/idl/ohos.vibrator.taihe @@ -26,11 +26,11 @@ struct VibratePreset { /** * The value is "preset", which triggers motor vibration according to preset vibration effect. * - * @type { 'preset' } + * @type { String } * @syscap SystemCapability.Sensors.MiscDevice * @since 9 */ - type: 'preset'; + type: String; /** * Preset type vibration. @@ -91,12 +91,12 @@ struct VibrateTime { /** * The value is "time", which triggers the motor vibration according to the specified duration. * - * @type { 'time' } + * @type { String } * @syscap SystemCapability.Sensors.MiscDevice * @atomicservice * @since 11 */ - type: 'time'; + type: String; /** * The duration of the vibration, in ms. @@ -210,7 +210,7 @@ enum EffectId: String { * @syscap SystemCapability.Sensors.MiscDevice * @since 8 */ - EFFECT_CLOCK_TIMER = 'haptic.clock.timer' + EFFECT_CLOCK_TIMER = "haptic.clock.timer" } /** @@ -227,7 +227,7 @@ enum VibratorStopMode: String { * @syscap SystemCapability.Sensors.MiscDevice * @since 8 */ - VIBRATOR_STOP_MODE_TIME = 'time', + VIBRATOR_STOP_MODE_TIME = "time", /** * Indicates the mode of stopping a preset vibration effect. @@ -235,7 +235,7 @@ enum VibratorStopMode: String { * @syscap SystemCapability.Sensors.MiscDevice * @since 8 */ - VIBRATOR_STOP_MODE_PRESET = 'preset' + VIBRATOR_STOP_MODE_PRESET = "preset" } /** @@ -249,11 +249,11 @@ struct VibrateFromPattern { /** * The value is "pattern", which triggers motor vibration based on the combination pattern. * - * @type { 'pattern' } + * @type { String } * @syscap SystemCapability.Sensors.MiscDevice * @since 18 */ - type: 'pattern'; + type: String; /** * Customize the sequence of motor vibration events, the VibratorPattern object returned by the build() method. @@ -553,11 +553,11 @@ struct VibrateFromFile { /** * The value is "file", which triggers motor vibration according to the vibration profile. * - * @type { 'file' } + * @type { String } * @syscap SystemCapability.Sensors.MiscDevice * @since 10 */ - type: 'file'; + type: String; /** * Haptic file descriptor, some formats are supported. -- Gitee From ba47d0907c1ea064c9dc3d57d69362a401c9ce2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=A8=E6=BE=8E=E4=BA=AE?= Date: Wed, 28 May 2025 14:55:41 +0800 Subject: [PATCH 4/4] modify vibrate ts Signed-off-by:zzzzl-top MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 周澎亮 --- frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp index 6696463..f03638e 100644 --- a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp +++ b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp @@ -179,11 +179,11 @@ static void PrintVibratorPattern(::ohos::vibrator::VibratorPattern &vibratorPatt MISC_HILOGE("Events is empty"); return; } - MISC_HILOGD("PrintVibratorPattern, time:%{public}d, eventNum:%{public}lu", + MISC_HILOGD("PrintVibratorPattern, time:%{public}d, eventNum:%{public}u", vibratorPattern.time, vibratorPattern.events.size()); for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { MISC_HILOGD("PrintVibratorPattern, type:%{public}d, time:%{public}d, duration:%{public}d, \ - intensity:%{public}d, frequency:%{public}d, index:%{public}d, pointNum:%{public}lu", + intensity:%{public}d, frequency:%{public}d, index:%{public}d, pointNum:%{public}u", static_cast(vibratorPattern.events[i].eventType), vibratorPattern.events[i].time, vibratorPattern.events[i].duration.value(), vibratorPattern.events[i].intensity.value(), vibratorPattern.events[i].frequency.value(), vibratorPattern.events[i].index.value(), @@ -204,7 +204,7 @@ static bool CheckVibratorCurvePoint(const ::ohos::vibrator::VibratorEvent &event { CALL_LOG_ENTER; if ((!event.points.has_value()) || (event.points.value().size() < CURVE_POINT_NUM_MIN) || (event.points.value().size() > CURVE_POINT_NUM_MAX)) { - MISC_HILOGE("The points size is out of range, pointNum:%{public}lu", event.points.value().size()); + MISC_HILOGE("The points size is out of range, pointNum:%{public}u", event.points.value().size()); return false; } for (int32_t j = 0; j < event.points.value().size(); ++j) { @@ -271,7 +271,7 @@ static bool CheckVibratorPatternParameter(::ohos::vibrator::VibratorPattern &vib return false; } if ((vibratorPattern.events.size() <= 0) || (vibratorPattern.events.size() > EVENT_NUM_MAX)) { - MISC_HILOGE("The event num is out of range, eventNum:%{public}lu", vibratorPattern.events.size()); + MISC_HILOGE("The event num is out of range, eventNum:%{public}u", vibratorPattern.events.size()); return false; } for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { -- Gitee