SensorLib 0.5.0
Multi-platform sensor driver library for Arduino, PlatformIO, and ESP-IDF
Loading...
Searching...
No Matches
HapticDriver_DRV2605.hpp
Go to the documentation of this file.
1
29#pragma once
30
31#include "../SensorBuildOpt.h"
32#if !SENSORLIB_EXCLUDE_HAPTIC_DRV2605
33
35#include "HapticBase.hpp"
36
40static constexpr uint8_t DRV2605_SLAVE_ADDRESS = 0x5A;
41
116{
117public:
122
126 ~HapticDriver_DRV2605() override;
127
128 // ==================== HapticBase Interface - Lifecycle ====================
129
133 void end() override;
134
139 bool isReady() const override;
140
145 const char *getChipName() const override;
146
147 // ==================== HapticBase Interface - Playback Control ====================
148
153 bool run() override;
154
159 bool stop() override;
160
165 bool isPlaying() const override;
166
171 HapticStatus getStatus() const override;
172
177 void emergencyStop() override;
178
179 // ==================== HapticBase Interface - Gain Control ====================
180
191 bool setGain(uint8_t gain) override;
192
200 uint8_t getGain() const override;
201
202 // ==================== HapticBase Interface - Effect Playback ====================
203
212 bool playEffect(HapticEffectId effect) override;
213
223 bool playEffectAsync(HapticEffectId effect) override;
224
235 void continuousVibration(uint32_t duration_ms, bool blocking = true) override;
236
243 void vibrationUpdate() override;
244
245 // ==================== HapticBase Interface - Waveform Sequence ====================
246
254 bool setSequence(uint8_t slot, HapticEffectId effect) override;
255
260 bool clearSequence() override;
261
266 bool playSequence() override;
267
268 // ==================== HapticBase Interface - Device Information ====================
269
277 HapticCapabilities getCapabilities() const override;
278
283 uint8_t getChipID() const override;
284
289 HapticActuatorType getActuatorType() const override;
290
301 bool setActuatorType(HapticActuatorType type) override;
302
303 // ==================== HapticBase Interface - Mode Control ====================
304
320 bool setMode(HapticMode mode) override;
321
326 HapticMode getMode() const override;
327
328 // ==================== HapticBase Interface - RTP ====================
329
338 bool setRealtimeValue(uint8_t value) override;
339
340 // ==================== HapticBase Interface - Calibration ====================
341
349 bool calibrate() override;
350
355 bool needsCalibration() const override;
356
365 uint32_t getF0() const override;
366
371 uint32_t getVbat() override;
372
373 // ==================== Extended API ====================
374
384 void setWaveform(uint8_t slot, uint8_t w);
385
396 void selectLibrary(uint8_t lib);
397
402 bool isDone() const;
403
410 void trigger();
411
416 uint8_t getRealtimeValue() const;
417
425 void setRatedVoltage(uint8_t value);
426
434 void setOverdriveClamp(uint8_t value);
435
444 int autoCal();
445
454 void setAutoBrake(bool enable);
455
464 void setOverdriveTime(uint8_t cycles);
465
473 void setBrakeTime(uint8_t time);
474
483 void setRtpOverdrive(bool enable);
484
492 void setERMLRA(bool erm);
493
502 void setCtrl4(uint8_t value);
503
509 uint8_t getLRAFrequency() const;
510
511private:
512 bool initImpl(uint8_t param) override;
513
514 void afterInitSuccess(uint8_t param) override
515 {
516 setReady(true);
517 }
518 uint8_t _currentLibrary;
519 uint8_t _waveformSeq[8];
520 uint8_t _waveformCount;
521 uint8_t _gain;
522 bool _isERM;
523 bool _isStandby;
524};
525
526#endif
@license MIT License
HapticStatus
Vibration playback status.
HapticActuatorType
Actuator type.
HapticMode
Generic haptic operating mode.
uint16_t HapticEffectId
Haptic effect ID type.
@license MIT License
Abstract base class for haptic drivers.
void setReady(bool ready)
Set ready state.
Driver for the TI DRV2605/DRV2604 haptic motor controller.
bool isDone() const
Check if playback is done.
uint32_t getVbat() override
Get the battery voltage.
void setAutoBrake(bool enable)
Enable/disable automatic braking.
void setRtpOverdrive(bool enable)
Enable/disable RTP overdrive.
bool setActuatorType(HapticActuatorType type) override
Set the actuator type.
HapticActuatorType getActuatorType() const override
Get the actuator type.
bool calibrate() override
Perform auto-calibration.
uint32_t getF0() const override
Get the measured resonant frequency (F0).
void setCtrl4(uint8_t value)
Set the control4 register value.
bool run() override
Start haptic playback.
~HapticDriver_DRV2605() override
Destructor.
void setRatedVoltage(uint8_t value)
Set the rated voltage for auto-calibration.
bool isReady() const override
Check if the driver is initialized and ready.
bool playEffectAsync(HapticEffectId effect) override
Play a haptic effect (non-blocking).
void selectLibrary(uint8_t lib)
Select the ROM waveform library.
void setBrakeTime(uint8_t time)
Set the brake time offset.
bool isPlaying() const override
Check if haptic is currently playing.
void end() override
Deinitialize the driver and release resources.
void continuousVibration(uint32_t duration_ms, bool blocking=true) override
Play a continuous vibration for specified duration.
void emergencyStop() override
Emergency stop - stops all vibration immediately.
int autoCal()
Perform auto-calibration and return compensation result.
void setOverdriveClamp(uint8_t value)
Set the overdrive clamp voltage for auto-calibration.
void setOverdriveTime(uint8_t cycles)
Set the number of overdrive cycles.
uint8_t getRealtimeValue() const
Get the current RTP value.
bool setMode(HapticMode mode) override
Set the operating mode.
void vibrationUpdate() override
Update vibration state (for non-blocking mode).
bool setSequence(uint8_t slot, HapticEffectId effect) override
Set a waveform in the sequence.
HapticStatus getStatus() const override
Get current playback status.
uint8_t getChipID() const override
Get the chip ID.
bool setGain(uint8_t gain) override
Set the gain/amplitude.
bool playSequence() override
Play the waveform sequence.
uint8_t getGain() const override
Get the current gain value.
void setERMLRA(bool erm)
Enable/disable ERM/LRA mode.
bool playEffect(HapticEffectId effect) override
Play a haptic effect.
const char * getChipName() const override
Get the chip name.
HapticMode getMode() const override
Get the current operating mode.
bool stop() override
Stop haptic playback immediately.
bool clearSequence() override
Clear the waveform sequence.
HapticDriver_DRV2605()
Construct an uninitialized driver instance.
void trigger()
Trigger a single playback cycle.
HapticCapabilities getCapabilities() const override
Get device capabilities.
bool setRealtimeValue(uint8_t value) override
Set RTP (real-time playback) value.
uint8_t getLRAFrequency() const
Read the LRA resonance period (for LRA calibration).
bool needsCalibration() const override
Check if calibration is needed.
void setWaveform(uint8_t slot, uint8_t w)
Set a waveform entry in the playback sequence table.
Device capability flags.