@ -31,6 +31,14 @@ static std::map<Effect, int> CP_TRIGGER_EFFECTS {
{ Effect : : TICK , 50 }
} ;
# ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL
static std : : map < EffectStrength , float > DURATION_AMPLITUDE = {
{ EffectStrength : : LIGHT , DURATION_AMPLITUDE_LIGHT } ,
{ EffectStrength : : MEDIUM , DURATION_AMPLITUDE_MEDIUM } ,
{ EffectStrength : : STRONG , DURATION_AMPLITUDE_STRONG }
} ;
# endif
/*
* Write value to path and close file .
*/
@ -73,10 +81,12 @@ ndk::ScopedAStatus Vibrator::getCapabilities(int32_t* _aidl_return) {
IVibrator : : CAP_EXTERNAL_CONTROL /*| IVibrator::CAP_COMPOSE_EFFECTS |
IVibrator : : CAP_ALWAYS_ON_CONTROL */ ;
if ( mHasTimedOutIntensity ) {
* _aidl_return = * _aidl_return | IVibrator : : CAP_AMPLITUDE_CONTROL |
IVibrator : : CAP_EXTERNAL_AMPLITUDE_CONTROL ;
}
# ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL
* _aidl_return | = IVibrator : : CAP_AMPLITUDE_CONTROL | IVibrator : : CAP_EXTERNAL_AMPLITUDE_CONTROL ;
# else
if ( mHasTimedOutIntensity )
* _aidl_return | = IVibrator : : CAP_AMPLITUDE_CONTROL | IVibrator : : CAP_EXTERNAL_AMPLITUDE_CONTROL ;
# endif
return ndk : : ScopedAStatus : : ok ( ) ;
}
@ -91,6 +101,10 @@ ndk::ScopedAStatus Vibrator::on(int32_t timeoutMs, const std::shared_ptr<IVibrat
if ( mHasTimedOutEffect )
writeNode ( VIBRATOR_CP_TRIGGER_PATH , 0 ) ; // Clear all effects
# ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL
timeoutMs * = mDurationAmplitude ;
# endif
status = activate ( timeoutMs ) ;
if ( callback ! = nullptr ) {
@ -130,6 +144,10 @@ ndk::ScopedAStatus Vibrator::perform(Effect effect, EffectStrength strength, con
return status ;
}
# ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL
ms * = DURATION_AMPLITUDE [ strength ] ;
# endif
status = activate ( ms ) ;
if ( callback ! = nullptr ) {
@ -163,15 +181,21 @@ ndk::ScopedAStatus Vibrator::setAmplitude(float amplitude) {
return ndk : : ScopedAStatus ( AStatus_fromExceptionCode ( EX_ILLEGAL_ARGUMENT ) ) ;
}
# ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL
mDurationAmplitude = durationAmplitude ( amplitude ) ;
# endif
LOG ( DEBUG ) < < " Setting amplitude: " < < amplitude ;
intensity = amplitude * INTENSITY_MAX ;
# ifndef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL
LOG ( DEBUG ) < < " Setting intensity: " < < intensity ;
if ( mHasTimedOutIntensity ) {
return writeNode ( VIBRATOR_INTENSITY_PATH , intensity ) ;
}
# endif
return ndk : : ScopedAStatus : : ok ( ) ;
}
@ -297,6 +321,18 @@ uint32_t Vibrator::effectToMs(Effect effect, ndk::ScopedAStatus* status) {
return 0 ;
}
# ifdef VIBRATOR_SUPPORTS_DURATION_AMPLITUDE_CONTROL
float Vibrator : : durationAmplitude ( float amplitude ) {
if ( amplitude = = 1 ) {
return DURATION_AMPLITUDE_STRONG ;
} else if ( amplitude > = 0.5 ) {
return DURATION_AMPLITUDE_MEDIUM ;
}
return DURATION_AMPLITUDE_LIGHT ;
}
# endif
} // namespace vibrator
} // namespace hardware
} // namespace android