SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
HapticBase Class Referenceabstract

Abstract base class for haptic drivers. More...

#include <HapticBase.hpp>

Inheritance diagram for HapticBase:
[legend]

Public Member Functions

virtual ~HapticBase ()=default
 
virtual void end ()
 Deinitialize the haptic driver and release resources.
 
virtual bool isReady () const =0
 Check if the driver is initialized and ready.
 
virtual bool run ()=0
 Start haptic playback.
 
virtual bool stop ()=0
 Stop haptic playback immediately.
 
virtual bool isPlaying () const =0
 Check if haptic is currently playing.
 
virtual HapticStatus getStatus () const =0
 Get current playback status.
 
virtual void emergencyStop ()
 Emergency stop - stops all vibration immediately.
 
virtual bool setGain (uint8_t gain)=0
 Set the gain/amplitude (0x00 to 0xFF).
 
virtual uint8_t getGain () const =0
 Get the current gain value.
 
virtual bool playEffect (HapticEffectId effect)=0
 Play a haptic effect.
 
virtual bool playEffectAsync (HapticEffectId effect)
 Play a haptic effect (non-blocking).
 
virtual void continuousVibration (uint32_t duration_ms, bool blocking=true)
 Play a continuous vibration for specified duration.
 
virtual void vibrationUpdate ()
 Update vibration state (for non-blocking mode).
 
virtual bool setSequence (uint8_t slot, HapticEffectId effect)
 Set a waveform in the sequence.
 
virtual bool clearSequence ()
 Clear the waveform sequence.
 
virtual bool playSequence ()
 Play the waveform sequence.
 
virtual const char * getChipName () const =0
 Get the chip name.
 
virtual uint8_t getChipID () const =0
 Get the chip ID.
 
virtual HapticActuatorType getActuatorType () const =0
 Get the actuator type.
 
virtual bool setActuatorType (HapticActuatorType type)=0
 Set the actuator type.
 
virtual HapticCapabilities getCapabilities () const =0
 Get device capabilities.
 
virtual bool calibrate ()
 Perform auto-calibration.
 
virtual bool needsCalibration () const
 Check if calibration is needed.
 
virtual uint32_t getF0 () const
 Get the measured resonant frequency (F0).
 
virtual uint32_t getVbat ()
 Get the battery voltage.
 
virtual bool setMode (HapticMode mode)
 Set the operating mode.
 
virtual HapticMode getMode () const
 Get the current operating mode.
 
virtual bool setRealtimeValue (uint8_t value)
 Set RTP (real-time playback) value.
 

Protected Member Functions

 HapticBase (const char *name)
 Constructor for derived classes.
 
void setReady (bool ready)
 Set ready state.
 

Protected Attributes

const char * _chipName
 
bool _isReady
 

Detailed Description

Abstract base class for haptic drivers.

This class provides a unified interface for different haptic motor drivers (e.g., DRV2605, AW86224, AW86225). It allows users to write platform-independent haptic control code while each driver handles chip-specific details.

Usage Example

// Works with any HapticBase-compatible driver
// Query capabilities
auto cap = haptic->getCapabilities();
if (cap.hasContinuousMode) {
haptic->continuousVibration(1000); // 1 second
}
HapticDriver_AW86224 haptic
Abstract base class for haptic drivers.
void continuousVibration(uint32_t duration_ms, bool blocking=true) override
Play a continuous vibration for specified duration.
HapticCapabilities getCapabilities() const override
Get device capabilities.

Design Principles

  • Feature probing: Return false or default values for unsupported operations
  • Unified API: Same method names across different chips
  • Optional features: Subclasses can override default implementations

Definition at line 58 of file HapticBase.hpp.

Constructor & Destructor Documentation

◆ ~HapticBase()

virtual HapticBase::~HapticBase ( )
virtualdefault

◆ HapticBase()

HapticBase::HapticBase ( const char *  name)
inlineexplicitprotected

Constructor for derived classes.

Parameters
nameChip name string for getChipName().

Definition at line 320 of file HapticBase.hpp.

Member Function Documentation

◆ calibrate()

virtual bool HapticBase::calibrate ( )
inlinevirtual

Perform auto-calibration.

Returns
true if successful, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 245 of file HapticBase.hpp.

◆ clearSequence()

virtual bool HapticBase::clearSequence ( )
inlinevirtual

Clear the waveform sequence.

Returns
true if successful, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 192 of file HapticBase.hpp.

◆ continuousVibration()

void HapticBase::continuousVibration ( uint32_t  duration_ms,
bool  blocking = true 
)
inlinevirtual

Play a continuous vibration for specified duration.

Default implementation uses playEffect() in a loop. Subclasses should override for optimized continuous mode.

Parameters
duration_msDuration in milliseconds.
blockingIf true, blocks until vibration completes.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 336 of file HapticBase.hpp.

◆ emergencyStop()

virtual void HapticBase::emergencyStop ( )
inlinevirtual

Emergency stop - stops all vibration immediately.

Default implementation calls stop(). Subclasses can override for chip-specific emergency handling.

Reimplemented in HapticDriver_DRV2605.

Definition at line 108 of file HapticBase.hpp.

References stop().

◆ end()

virtual void HapticBase::end ( )
inlinevirtual

Deinitialize the haptic driver and release resources.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 68 of file HapticBase.hpp.

◆ getActuatorType()

virtual HapticActuatorType HapticBase::getActuatorType ( ) const
pure virtual

Get the actuator type.

Returns
Current actuator type (ERM or LRA).

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ getCapabilities()

virtual HapticCapabilities HapticBase::getCapabilities ( ) const
pure virtual

Get device capabilities.

Returns
HapticCapabilities struct describing supported features.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ getChipID()

virtual uint8_t HapticBase::getChipID ( ) const
pure virtual

Get the chip ID.

Returns
Chip identifier value.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ getChipName()

virtual const char * HapticBase::getChipName ( ) const
pure virtual

Get the chip name.

Returns
Null-terminated string with chip name.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ getF0()

virtual uint32_t HapticBase::getF0 ( ) const
inlinevirtual

Get the measured resonant frequency (F0).

Returns
F0 in Hz, or 0 if not available.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 263 of file HapticBase.hpp.

◆ getGain()

virtual uint8_t HapticBase::getGain ( ) const
pure virtual

Get the current gain value.

Returns
Current gain (0x00 to 0xFF), or 0 if unsupported.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ getMode()

virtual HapticMode HapticBase::getMode ( ) const
inlinevirtual

Get the current operating mode.

Returns
Current HapticMode.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 294 of file HapticBase.hpp.

References INTERNAL_TRIGGER.

◆ getStatus()

virtual HapticStatus HapticBase::getStatus ( ) const
pure virtual

Get current playback status.

Returns
Current HapticStatus.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ getVbat()

virtual uint32_t HapticBase::getVbat ( )
inlinevirtual

Get the battery voltage.

Returns
Voltage in mV, or 0 if unsupported.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 272 of file HapticBase.hpp.

◆ isPlaying()

virtual bool HapticBase::isPlaying ( ) const
pure virtual

Check if haptic is currently playing.

Returns
true if playing, false otherwise.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ isReady()

virtual bool HapticBase::isReady ( ) const
pure virtual

Check if the driver is initialized and ready.

Returns
true if ready, false otherwise.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ needsCalibration()

virtual bool HapticBase::needsCalibration ( ) const
inlinevirtual

Check if calibration is needed.

Returns
true if calibration is required, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 254 of file HapticBase.hpp.

◆ playEffect()

virtual bool HapticBase::playEffect ( HapticEffectId  effect)
pure virtual

Play a haptic effect.

This is a blocking call - it returns only after the effect completes. For chips that don't support blocking, use playEffectAsync() instead.

Parameters
effectEffect ID to play (chip-specific mapping).
Returns
true if successful, false otherwise.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Referenced by playEffectAsync().

◆ playEffectAsync()

virtual bool HapticBase::playEffectAsync ( HapticEffectId  effect)
inlinevirtual

Play a haptic effect (non-blocking).

Returns immediately; use isPlaying() or vibrationUpdate() to check status.

Parameters
effectEffect ID to play.
Returns
true if started successfully, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 149 of file HapticBase.hpp.

References playEffect().

◆ playSequence()

virtual bool HapticBase::playSequence ( )
inlinevirtual

Play the waveform sequence.

Returns
true if successful, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 201 of file HapticBase.hpp.

◆ run()

virtual bool HapticBase::run ( )
pure virtual

Start haptic playback.

Returns
true if successful, false otherwise.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ setActuatorType()

virtual bool HapticBase::setActuatorType ( HapticActuatorType  type)
pure virtual

Set the actuator type.

Parameters
typeActuator type to set (ERM or LRA).
Returns
true if successful, false otherwise.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ setGain()

virtual bool HapticBase::setGain ( uint8_t  gain)
pure virtual

Set the gain/amplitude (0x00 to 0xFF).

Parameters
gainGain value.
Returns
true if successful, false otherwise.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

◆ setMode()

virtual bool HapticBase::setMode ( HapticMode  mode)
inlinevirtual

Set the operating mode.

Parameters
modeMode to set.
Returns
true if successful, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 284 of file HapticBase.hpp.

◆ setReady()

void HapticBase::setReady ( bool  ready)
inlineprotected

Set ready state.

Parameters
readyReady state to set.

Definition at line 326 of file HapticBase.hpp.

References _isReady.

Referenced by HapticDriver_AW86224::end(), and HapticDriver_DRV2605::end().

◆ setRealtimeValue()

virtual bool HapticBase::setRealtimeValue ( uint8_t  value)
inlinevirtual

Set RTP (real-time playback) value.

Only meaningful when in REAL_TIME_PLAYBACK mode.

Parameters
valueRTP drive value (0x00 to 0xFF).
Returns
true if successful, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 309 of file HapticBase.hpp.

◆ setSequence()

virtual bool HapticBase::setSequence ( uint8_t  slot,
HapticEffectId  effect 
)
inlinevirtual

Set a waveform in the sequence.

Parameters
slotSequence slot index (0 to maxSequenceLength-1).
effectEffect ID to play at this slot.
Returns
true if successful, false otherwise.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 181 of file HapticBase.hpp.

◆ stop()

virtual bool HapticBase::stop ( )
pure virtual

Stop haptic playback immediately.

Returns
true if successful, false otherwise.

Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Referenced by emergencyStop().

◆ vibrationUpdate()

virtual void HapticBase::vibrationUpdate ( )
inlinevirtual

Update vibration state (for non-blocking mode).

Call this periodically in your main loop when using non-blocking vibration functions. Default implementation does nothing.

Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.

Definition at line 171 of file HapticBase.hpp.

Member Data Documentation

◆ _chipName

const char* HapticBase::_chipName
protected

Definition at line 331 of file HapticBase.hpp.

◆ _isReady


The documentation for this class was generated from the following file: