From 5fe9522e317a1ba13c499379ec079744eed896ff Mon Sep 17 00:00:00 2001 From: lixiangpeng5 Date: Tue, 21 Feb 2023 11:55:37 +0000 Subject: [PATCH] add event count to 1024 Signed-off-by: lixiangpeng5 Change-Id: I324df1a989eec02edd56a07e193ebc841a4c8f07 --- .../src/default_vibrator_decoder.cpp | 2 +- .../include/miscdevice_service.h | 1 + .../src/miscdevice_service.cpp | 61 ++++++++++++------- 3 files changed, 42 insertions(+), 22 deletions(-) diff --git a/services/miscdevice_service/custom_vibrate_decode/src/default_vibrator_decoder.cpp b/services/miscdevice_service/custom_vibrate_decode/src/default_vibrator_decoder.cpp index 4ceb6d7..969e2fe 100755 --- a/services/miscdevice_service/custom_vibrate_decode/src/default_vibrator_decoder.cpp +++ b/services/miscdevice_service/custom_vibrate_decode/src/default_vibrator_decoder.cpp @@ -30,7 +30,7 @@ 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 EVENT_NUM_MAX = 128; +constexpr int32_t EVENT_NUM_MAX = 1024; constexpr double SUPPORT_JSON_VERSION = 1.0; constexpr int32_t SUPPORT_CHANNEL_NUMBER = 1; constexpr HiLogLabel LABEL = { LOG_CORE, MISC_LOG_DOMAIN, "DefaultVibratorDecoder" }; diff --git a/services/miscdevice_service/include/miscdevice_service.h b/services/miscdevice_service/include/miscdevice_service.h index 91c2f7d..595f651 100644 --- a/services/miscdevice_service/include/miscdevice_service.h +++ b/services/miscdevice_service/include/miscdevice_service.h @@ -79,6 +79,7 @@ private: bool InitLightList(); #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM int32_t DecodeCustomEffect(const RawFileDescriptor &rawFd, std::set &vibrateSequence); + int32_t StartCustomVibration(const RawFileDescriptor &rawFd); #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM VibratorHdiConnection &vibratorHdiConnection_ = VibratorHdiConnection::GetInstance(); LightHdiConnection &lightHdiConnection_ = LightHdiConnection::GetInstance(); diff --git a/services/miscdevice_service/src/miscdevice_service.cpp b/services/miscdevice_service/src/miscdevice_service.cpp index 6840363..c66093e 100644 --- a/services/miscdevice_service/src/miscdevice_service.cpp +++ b/services/miscdevice_service/src/miscdevice_service.cpp @@ -16,6 +16,7 @@ #include "miscdevice_service.h" #include +#include #include #include "sensors_errors.h" @@ -44,7 +45,8 @@ constexpr int32_t MIN_VIBRATOR_TIME = 0; constexpr int32_t MAX_VIBRATOR_TIME = 1800000; #ifdef OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM -constexpr int32_t MAX_JSON_FILE_SIZE = 64000; +constexpr int32_t MAX_JSON_FILE_SIZE = 512000; +constexpr int32_t PART_SIZE = 128; const std::string PHONE_TYPE = "phone"; #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM } // namespace @@ -326,41 +328,58 @@ int32_t MiscdeviceService::DecodeCustomEffect(const RawFileDescriptor &rawFd, st return NO_ERROR; } -int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) +int32_t MiscdeviceService::StartCustomVibration(const RawFileDescriptor &rawFd) { - if (OHOS::system::GetDeviceType() != PHONE_TYPE) { - MISC_HILOGE("the device does not support this operation"); - return IS_NOT_SUPPORTED; - } - if ((usage >= USAGE_MAX) || (usage < 0)) { - MISC_HILOGE("invalid parameter, usage:%{public}d", usage); - return PARAMETER_ERROR; - } - if ((rawFd.fd < 0) || (rawFd.offset < 0) || (rawFd.length <= 0) || (rawFd.length > MAX_JSON_FILE_SIZE)) { - MISC_HILOGE("invalid file descriptor, fd:%{public}d, offset:%{public}lld, length:%{public}lld", - rawFd.fd, static_cast(rawFd.offset), static_cast(rawFd.length)); - return PARAMETER_ERROR; - } std::set vibrateSet; int32_t ret = DecodeCustomEffect(rawFd, vibrateSet); if (ret != SUCCESS) { MISC_HILOGE("decoder custom effect error"); return ERROR; } - HdfCompositeEffect vibratorCompositeEffect; - vibratorCompositeEffect.type = HDF_EFFECT_TYPE_PRIMITIVE; CustomVibrationMatcher matcher; - ret = matcher.TransformEffect(vibrateSet, vibratorCompositeEffect.compositeEffects); + std::vector compositeEffects; + ret = matcher.TransformEffect(vibrateSet, compositeEffects); if (ret != SUCCESS) { MISC_HILOGE("transform custom effect error"); return ERROR; } - auto& compositeEffects = vibratorCompositeEffect.compositeEffects; size_t size = compositeEffects.size(); MISC_HILOGD("the count of match result:%{public}zu", size); for (size_t i = 0; i < size; ++i) { MISC_HILOGD("match result at %{public}zu th, delay:%{public}d, effectId:%{public}d", - i, compositeEffects[i].primitiveEffect.delay, compositeEffects[i].primitiveEffect.effectId); + i, compositeEffects[i].primitiveEffect.delay, compositeEffects[i].primitiveEffect.effectId); + } + size_t sendTimes = std::ceil(static_cast(size) / PART_SIZE); + for (size_t i = 0; i < sendTimes; ++i) { + auto left = compositeEffects.begin() + PART_SIZE * i; + auto right = std::min(compositeEffects.begin() + PART_SIZE * (i + 1), compositeEffects.end()); + HdfCompositeEffect hdfCompositeEffect = { + .type = HDF_EFFECT_TYPE_PRIMITIVE, + .compositeEffects = std::vector(left, right) + }; + ret = vibratorHdiConnection_.EnableCompositeEffect(hdfCompositeEffect); + if (ret != ERR_OK) { + MISC_HILOGE("EnableCompositeEffect error, times:%{public}zu", i); + return ERROR; + } + } + return NO_ERROR; +} + +int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileDescriptor &rawFd, int32_t usage) +{ + if (OHOS::system::GetDeviceType() != PHONE_TYPE) { + MISC_HILOGE("the device does not support this operation"); + return IS_NOT_SUPPORTED; + } + if ((usage >= USAGE_MAX) || (usage < 0)) { + MISC_HILOGE("invalid parameter, usage:%{public}d", usage); + return PARAMETER_ERROR; + } + if ((rawFd.fd < 0) || (rawFd.offset < 0) || (rawFd.length <= 0) || (rawFd.length > MAX_JSON_FILE_SIZE)) { + MISC_HILOGE("invalid file descriptor, fd:%{public}d, offset:%{public}lld, length:%{public}lld", + rawFd.fd, static_cast(rawFd.offset), static_cast(rawFd.length)); + return PARAMETER_ERROR; } VibrateInfo info = { .mode = "custom", @@ -375,7 +394,7 @@ int32_t MiscdeviceService::PlayVibratorCustom(int32_t vibratorId, const RawFileD return ERROR; } StartVibrateThread(info); - return vibratorHdiConnection_.EnableCompositeEffect(vibratorCompositeEffect); + return StartCustomVibration(rawFd); } #endif // OHOS_BUILD_ENABLE_VIBRATOR_CUSTOM -- Gitee