diff --git a/services/miscdevice_service/haptic_matcher/include/custom_vibration_matcher.h b/services/miscdevice_service/haptic_matcher/include/custom_vibration_matcher.h index 60880fc75e7666917bdc556d5cff93a88b1c46c1..7fa74647bd14c3f7e371ee808ae44c9b83fb0518 100644 --- a/services/miscdevice_service/haptic_matcher/include/custom_vibration_matcher.h +++ b/services/miscdevice_service/haptic_matcher/include/custom_vibration_matcher.h @@ -16,6 +16,7 @@ #ifndef CUSTOM_VIBRATION_MATCHER_H #define CUSTOM_VIBRATION_MATCHER_H +#include #include #include #include @@ -46,8 +47,10 @@ private: std::vector &compositeEffects); void ProcessTransientEvent(const VibrateEvent &event, int32_t &preStartTime, int32_t &preDuration, std::vector &compositeEffects); + void NormalizedVibrationInfo(std::vector &waveInfos); std::vector waveInfos_; + std::map> normalizedVibrationInfos_; }; } // namespace Sensors } // namespace OHOS diff --git a/services/miscdevice_service/haptic_matcher/src/custom_vibration_matcher.cpp b/services/miscdevice_service/haptic_matcher/src/custom_vibration_matcher.cpp index 442feb29a08561a709ca74c6c3375cf59501fb3c..6cf8302c110e57631805aa0ade5ea5054f799206 100644 --- a/services/miscdevice_service/haptic_matcher/src/custom_vibration_matcher.cpp +++ b/services/miscdevice_service/haptic_matcher/src/custom_vibration_matcher.cpp @@ -16,7 +16,6 @@ #include "custom_vibration_matcher.h" #include -#include #include "sensors_errors.h" #include "vibrator_hdi_connection.h" @@ -53,6 +52,7 @@ constexpr float CURVE_INTENSITY_SCALE = 100.00; constexpr int32_t SLICE_STEP = 50; constexpr int32_t CONTINUOUS_VIBRATION_DURATION_MIN = 15; constexpr int32_t INDEX_MIN_RESTRICT = 1; +constexpr int32_t DURATION_INDEX = 2; } // namespace CustomVibrationMatcher::CustomVibrationMatcher() @@ -68,6 +68,7 @@ CustomVibrationMatcher::CustomVibrationMatcher() MISC_HILOGD("waveId:%{public}d,intensity:%{public}f, frequency:%{public}f,duration:%{public}d", it->waveId, it->intensity, it->frequency, it->duration); } + NormalizedVibrationInfo(waveInfos_); } } @@ -77,6 +78,33 @@ CustomVibrationMatcher &CustomVibrationMatcher::GetInstance() return instance; } +void CustomVibrationMatcher::NormalizedVibrationInfo(std::vector &waveInfos) +{ + CALL_LOG_ENTER; + float maxIntensity = waveInfos.begin()->intensity; + float minFrequency = waveInfos.begin()->frequency; + float maxFrequency = waveInfos.begin()->frequency; + for (auto it = waveInfos.begin(); it != waveInfos.end(); ++it) { + maxIntensity = (maxIntensity > it->intensity)? maxIntensity : it->intensity; + minFrequency = (minFrequency < it->frequency)? minFrequency : it->frequency; + maxFrequency = (maxFrequency > it->frequency)? maxFrequency : it->frequency; + } + + float intensityEqualValue = maxIntensity / INTENSITY_MAX; + float frequencyEqualValue = (maxFrequency - minFrequency) / FREQUENCY_MAX; + for (auto it = waveInfos.begin(); it != waveInfos.end(); ++it) { + std::vector normalizedValue; + normalizedValue.push_back(static_cast(it->intensity / intensityEqualValue)); + normalizedValue.push_back(static_cast((it->frequency - minFrequency) / frequencyEqualValue)); + normalizedValue.push_back(it->duration); + normalizedVibrationInfos_[it->waveId] = normalizedValue; + } + for (auto it = normalizedVibrationInfos_.begin(); it != normalizedVibrationInfos_.end(); ++it) { + MISC_HILOGD("waveId:%{public}d,intensity:%{public}d, frequency:%{public}d,duration:%{public}d", + it->first, it->second[0], it->second[1], it->second[DURATION_INDEX]); + } +} + int32_t CustomVibrationMatcher::TransformTime(const VibratePackage &package, std::vector &compositeEffects) {