/* * Copyright (C) 2017 The Android Open Source Project * * 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. */ #ifndef ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H #define ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H #include #include #include namespace android { namespace hardware { namespace vibrator { namespace V1_3 { namespace implementation { class Vibrator : public IVibrator { public: // APIs for interfacing with the kernel driver. class HwApi { public: virtual ~HwApi() = default; // Stores the COMP, BEMF, and GAIN calibration values to use. // virtual bool setAutocal(std::string value) = 0; // Stores the open-loop LRA frequency to be used. virtual bool setOlLraPeriod(uint32_t value) = 0; // Activates/deactivates the vibrator for durations specified by // setDuration(). virtual bool setActivate(bool value) = 0; // Specifies the vibration duration in milliseconds. virtual bool setDuration(uint32_t value) = 0; // Specifies the active state of the vibrator // (true = enabled, false = disabled). virtual bool setState(bool value) = 0; // Reports whether setRtpInput() is supported. virtual bool hasRtpInput() = 0; // Specifies the playback amplitude of the haptic waveforms in RTP mode. // Negative numbers indicates braking. virtual bool setRtpInput(int8_t value) = 0; // Specifies the mode of operation. // rtp - RTP Mode // waveform - Waveform Sequencer Mode // diag - Diagnostics Routine // autocal - Automatic Level Calibration Routine virtual bool setMode(std::string value) = 0; // Specifies a waveform sequence in index-count pairs. // [ ...] virtual bool setSequencer(std::string value) = 0; // Specifies the scaling of effects in Waveform mode. // 0 - 100% // 1 - 75% // 2 - 50% // 3 - 25% virtual bool setScale(uint8_t value) = 0; // Selects either closed loop or open loop mode. // (true = open, false = closed). virtual bool setCtrlLoop(bool value) = 0; // Specifies waveform index to be played in low-power trigger mode. // 0 - Disabled // 1+ - Waveform Index virtual bool setLpTriggerEffect(uint32_t value) = 0; // Specifies which shape to use for driving the LRA when in open loop // mode. // 0 - Square Wave // 1 - Sine Wave virtual bool setLraWaveShape(uint32_t value) = 0; // Specifies the maximum voltage for automatic overdrive and automatic // braking periods. virtual bool setOdClamp(uint32_t value) = 0; // Get battery temperature sensor value virtual bool getUsbTemp(int32_t *value) = 0; // Emit diagnostic information to the given file. virtual void debug(int fd) = 0; }; // APIs for obtaining calibration/configuration data from persistent memory. class HwCal { public: virtual ~HwCal() = default; // Obtains the COMP, BEMF, and GAIN calibration values to use. virtual bool getAutocal(std::string *value) = 0; // Obtains the open-loop LRA frequency to be used. virtual bool getLraPeriod(uint32_t *value) = 0; // Obtains the effect coeffs to calculate the target voltage virtual bool getEffectCoeffs(std::array *value) = 0; // Obtain the max steady G value virtual bool getSteadyAmpMax(float *value) = 0; // Obtains threshold in ms, above which close-loop should be used. virtual bool getCloseLoopThreshold(uint32_t *value) = 0; // Obtains dynamic/static configuration choice. virtual bool getDynamicConfig(bool *value) = 0; // Obtains LRA frequency shift for long (steady) vibrations. virtual bool getLongFrequencyShift(uint32_t *value) = 0; // Obtains maximum voltage for short (effect) vibrations virtual bool getShortVoltageMax(uint32_t *value) = 0; // Obtains maximum voltage for long (steady) vibrations virtual bool getLongVoltageMax(uint32_t *value) = 0; // Obtains the duration for the click effect virtual bool getClickDuration(uint32_t *value) = 0; // Obtains the duration for the tick effect virtual bool getTickDuration(uint32_t *value) = 0; // Obtains the duration for the double-click effect virtual bool getDoubleClickDuration(uint32_t *value) = 0; // Obtains the duration for the heavy-click effect virtual bool getHeavyClickDuration(uint32_t *value) = 0; // Obtains the wave shape for effect haptics virtual bool getEffectShape(uint32_t *value) = 0; // Obtains the wave shape for steady vibration virtual bool getSteadyShape(uint32_t *value) = 0; // Obtains the trigger effect support virtual bool getTriggerEffectSupport(uint32_t *value) = 0; // Emit diagnostic information to the given file. virtual void debug(int fd) = 0; }; private: enum class LoopControl : bool { CLOSE = false, OPEN = true, }; enum class WaveShape : uint32_t { SQUARE = 0, SINE = 1, }; struct VibrationConfig { WaveShape shape; uint32_t *odClamp; uint32_t olLraPeriod; }; enum OdClampOffset : uint32_t { TEXTURE_TICK, TICK, CLICK, HEAVY_CLICK, }; public: Vibrator(std::unique_ptr hwapi, std::unique_ptr hwcal); // Methods from ::android::hardware::vibrator::V1_0::IVibrator follow. using Status = ::android::hardware::vibrator::V1_0::Status; Return on(uint32_t timeoutMs) override; Return off() override; Return supportsAmplitudeControl() override; Return setAmplitude(uint8_t amplitude) override; // Methods from ::android::hardware::vibrator::V1_3::IVibrator follow. Return supportsExternalControl() override; Return setExternalControl(bool enabled) override; using EffectStrength = ::android::hardware::vibrator::V1_0::EffectStrength; Return perform(V1_0::Effect effect, EffectStrength strength, perform_cb _hidl_cb) override; Return perform_1_1(V1_1::Effect_1_1 effect, EffectStrength strength, perform_cb _hidl_cb) override; Return perform_1_2(V1_2::Effect effect, EffectStrength strength, perform_cb _hidl_cb) override; Return perform_1_3(Effect effect, EffectStrength strength, perform_cb _hidl_cb) override; // Methods from ::android.hidl.base::V1_0::IBase follow. Return debug(const hidl_handle &handle, const hidl_vec &options) override; private: Return on(uint32_t timeoutMs, const char mode[], const std::unique_ptr &config, const int8_t volOffset); template Return performWrapper(T effect, EffectStrength strength, perform_cb _hidl_cb); Return performEffect(Effect effect, EffectStrength strength, perform_cb _hidl_cb); std::unique_ptr mHwApi; std::unique_ptr mHwCal; uint32_t mCloseLoopThreshold; std::unique_ptr mSteadyConfig; std::unique_ptr mEffectConfig; uint32_t mClickDuration; uint32_t mTickDuration; uint32_t mDoubleClickDuration; uint32_t mHeavyClickDuration; std::array mEffectTargetOdClamp; uint32_t mSteadyTargetOdClamp; uint32_t mSteadyOlLraPeriod; uint32_t mSteadyOlLraPeriodShift; bool mDynamicConfig; }; } // namespace implementation } // namespace V1_3 } // namespace vibrator } // namespace hardware } // namespace android #endif // ANDROID_HARDWARE_VIBRATOR_V1_3_VIBRATOR_H