|
SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
|
Abstract base class for haptic drivers. More...
#include <HapticBase.hpp>
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 |
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.
Definition at line 58 of file HapticBase.hpp.
|
virtualdefault |
|
inlineexplicitprotected |
Constructor for derived classes.
| name | Chip name string for getChipName(). |
Definition at line 320 of file HapticBase.hpp.
|
inlinevirtual |
Perform auto-calibration.
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 245 of file HapticBase.hpp.
|
inlinevirtual |
Clear the waveform sequence.
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 192 of file HapticBase.hpp.
|
inlinevirtual |
Play a continuous vibration for specified duration.
Default implementation uses playEffect() in a loop. Subclasses should override for optimized continuous mode.
| duration_ms | Duration in milliseconds. |
| blocking | If true, blocks until vibration completes. |
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 336 of file HapticBase.hpp.
|
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().
|
inlinevirtual |
Deinitialize the haptic driver and release resources.
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 68 of file HapticBase.hpp.
|
pure virtual |
Get the actuator type.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
pure virtual |
Get device capabilities.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
pure virtual |
Get the chip ID.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
pure virtual |
Get the chip name.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
inlinevirtual |
Get the measured resonant frequency (F0).
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 263 of file HapticBase.hpp.
|
pure virtual |
Get the current gain value.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
inlinevirtual |
Get the current operating mode.
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 294 of file HapticBase.hpp.
References INTERNAL_TRIGGER.
|
pure virtual |
Get current playback status.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
inlinevirtual |
Get the battery voltage.
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 272 of file HapticBase.hpp.
|
pure virtual |
Check if haptic is currently playing.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
pure virtual |
Check if the driver is initialized and ready.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
inlinevirtual |
Check if calibration is needed.
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 254 of file HapticBase.hpp.
|
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.
| effect | Effect ID to play (chip-specific mapping). |
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Referenced by playEffectAsync().
|
inlinevirtual |
Play a haptic effect (non-blocking).
Returns immediately; use isPlaying() or vibrationUpdate() to check status.
| effect | Effect ID to play. |
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 149 of file HapticBase.hpp.
References playEffect().
|
inlinevirtual |
Play the waveform sequence.
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 201 of file HapticBase.hpp.
|
pure virtual |
Start haptic playback.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
pure virtual |
Set the actuator type.
| type | Actuator type to set (ERM or LRA). |
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
pure virtual |
Set the gain/amplitude (0x00 to 0xFF).
| gain | Gain value. |
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
|
inlinevirtual |
Set the operating mode.
| mode | Mode to set. |
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 284 of file HapticBase.hpp.
|
inlineprotected |
Set ready state.
| ready | Ready state to set. |
Definition at line 326 of file HapticBase.hpp.
References _isReady.
Referenced by HapticDriver_AW86224::end(), and HapticDriver_DRV2605::end().
|
inlinevirtual |
Set RTP (real-time playback) value.
Only meaningful when in REAL_TIME_PLAYBACK mode.
| value | RTP drive value (0x00 to 0xFF). |
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 309 of file HapticBase.hpp.
|
inlinevirtual |
Set a waveform in the sequence.
| slot | Sequence slot index (0 to maxSequenceLength-1). |
| effect | Effect ID to play at this slot. |
Reimplemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Definition at line 181 of file HapticBase.hpp.
|
pure virtual |
Stop haptic playback immediately.
Implemented in HapticDriver_AW86224, and HapticDriver_DRV2605.
Referenced by emergencyStop().
|
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.
|
protected |
Definition at line 331 of file HapticBase.hpp.
|
protected |
Definition at line 332 of file HapticBase.hpp.
Referenced by HapticDriver_AW86224::calibrate(), HapticDriver_AW86224::getStatus(), HapticDriver_DRV2605::getStatus(), HapticDriver_AW86224::isReady(), HapticDriver_DRV2605::isReady(), HapticDriver_DRV2605::playEffect(), and setReady().