Add scale factor field to HapticScale
Add extra field scale factor to the ExtenalVibratorService result to
support continuous scaling haptic channels based on a float scale.
The new updated scale function still converges to 1.0 when it's scaling
up the haptic data, but it no longer applies distortion of the vibration
waveform when it scales down the amplitude.
The new scaling is defined as:
(scale_factor * amplitude)
when scale_factor <= 1
(scale_factor * amplitude) / (1 + (scale_factor - 1) * amplitude^2)
when scale_factor > 1
Bug: 356407385
Flag: android.os.vibrator.haptics_scale_v2_enabled
Test: libvibrator_tests
Change-Id: Ibde6699bf23614e27b50e1ff79e364d942499187
diff --git a/libs/vibrator/ExternalVibration.cpp b/libs/vibrator/ExternalVibration.cpp
index c97e496..cae2de2 100644
--- a/libs/vibrator/ExternalVibration.cpp
+++ b/libs/vibrator/ExternalVibration.cpp
@@ -93,8 +93,8 @@
externalVibrationScale.scaleLevel);
}
- return {/*level=*/scaleLevel, /*adaptiveScaleFactor=*/
- externalVibrationScale.adaptiveHapticsScale};
+ return os::HapticScale(scaleLevel, externalVibrationScale.scaleFactor,
+ externalVibrationScale.adaptiveHapticsScale);
}
} // namespace os