41static const char *effectList[] = {
42 "1 - Strong Click 100%",
"2 - Strong Click 60%",
"3 - Strong Click 30%",
43 "4 - Sharp Click 100%",
"5 - Sharp Click 60%",
"6 - Sharp Click 30%",
44 "7 - Soft Bump 100%",
"8 - Soft Bump 60%",
"9 - Soft Bump 30%",
45 "10 - Double Click 100%",
"11 - Double Click 60%",
"12 - Triple Click 100%",
46 "13 - Soft Fuzz 60%",
"14 - Strong Buzz 100%",
"15 - Alert 750ms 100%",
47 "16 - Alert 1000ms 100%"
53 Serial.println(
"╔══════════════════════════════════════════╗");
54 Serial.println(
"║ DRV2605 Haptic Driver Test ║");
55 Serial.println(
"╚══════════════════════════════════════════╝");
61 Serial.println(
"\n========== Commands ==========");
62 Serial.println(
"1-16 : Play effect (ERM Library 1)");
63 Serial.println(
"e : List all effects (1-117)");
64 Serial.println(
"l 1-6 : Select ROM library");
65 Serial.println(
"a : Toggle ERM/LRA mode");
66 Serial.println(
"s : Stop playback");
67 Serial.println(
"r : RTP test (0-255)");
68 Serial.println(
"c : Calibrate");
69 Serial.println(
"h : Help");
70 Serial.println(
"==============================");
80 Serial.println(
"\n=== Driver Initialization ===");
83 Serial.println(
"[FATAL] DRV2605 init failed!");
84 while (1) delay(1000);
87 Serial.println(
"[OK] Driver initialized");
91 Serial.print(
" VBAT: "); Serial.print(
haptic.
getVbat()); Serial.println(
" mV");
92 Serial.print(
" Mode: "); Serial.println(
static_cast<uint8_t
>(
haptic.
getMode()));
98 if (Serial.available()) {
99 char cmd = Serial.read();
101 if (
cmd >=
'1' &&
cmd <=
'9') {
102 uint8_t idx =
cmd -
'1';
103 Serial.print(
"Playing: "); Serial.println(effectList[idx]);
105 }
else if (
cmd ==
'e' ||
cmd ==
'E') {
106 Serial.println(
"\n--- Effect List (1-117) ---");
107 Serial.println(
"ERM Library 1: Strong/Sharp/Soft Click, Double/Triple Click, Buzz");
108 Serial.println(
"ERM Library 2-5: Various click patterns");
109 Serial.println(
"ERM Library 6: LRA Library (use 'l 6')");
110 Serial.println(
"Send number 1-117 to play effect");
111 }
else if (
cmd ==
'l' ||
cmd ==
'L') {
113 while (Serial.available() == 0) delay(10);
114 char lib = Serial.read();
115 uint8_t libNum = lib -
'0';
116 if (libNum >= 1 && libNum <= 6) {
118 Serial.print(
"Library set to: "); Serial.println(libNum);
120 }
else if (
cmd ==
'a' ||
cmd ==
'A') {
124 }
else if (
cmd ==
's' ||
cmd ==
'S') {
126 Serial.println(
"Stopped");
127 }
else if (
cmd ==
'r' ||
cmd ==
'R') {
129 Serial.println(
"RTP Mode: Send 0-255 for intensity");
130 while (Serial.available() == 0) delay(10);
131 int val = Serial.parseInt();
132 if (val >= 0 && val <= 255) {
134 Serial.print(
"RTP Value: "); Serial.println(val);
137 }
else if (
cmd ==
'c' ||
cmd ==
'C') {
138 Serial.println(
"Calibrating...");
140 Serial.println(
"[OK] Calibration done");
142 Serial.println(
"[FAIL] Calibration failed");
144 }
else if (
cmd ==
'h' ||
cmd ==
'H' ||
cmd ==
'?') {
146 }
else if (
cmd >=
'0' &&
cmd <=
'9') {
148 String numStr = String(
cmd);
149 while (Serial.available()) {
150 char c = Serial.peek();
151 if (c >=
'0' && c <=
'9') {
152 numStr += Serial.read();
158 uint8_t effectNum = numStr.toInt();
159 if (effectNum >= 1 && effectNum <= 117) {
160 Serial.print(
"Playing effect: "); Serial.println(effectNum);
163 Serial.print(
"Invalid: "); Serial.print(effectNum); Serial.println(
" (range 1-117)");
165 }
else if (
cmd !=
'\n' &&
cmd !=
'\r' &&
cmd !=
' ') {
166 Serial.print(
"[?] Unknown: '"); Serial.println(
cmd);
@ LRA
Linear Resonant Actuator.
@ ERM
Eccentric Rotating Mass motor.
@ INTERNAL_TRIGGER
Play by selecting waveforms/effects and calling run()
@ REAL_TIME_PLAYBACK
RTP mode (direct drive value)
Driver for the TI DRV2605/DRV2604 haptic motor controller.
uint32_t getVbat() override
Get the battery voltage.
bool setActuatorType(HapticActuatorType type) override
Set the actuator type.
HapticActuatorType getActuatorType() const override
Get the actuator type.
bool calibrate() override
Perform auto-calibration.
void selectLibrary(uint8_t lib)
Select the ROM waveform library.
bool setMode(HapticMode mode) override
Set the operating mode.
uint8_t getChipID() const override
Get the chip ID.
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 setRealtimeValue(uint8_t value) override
Set RTP (real-time playback) value.
bool begin(SensorCommCustom::CustomCallback cb, SensorCommCustomHal::CustomHalCallback hal_cb, uint8_t addr)
Initialize the sensor using custom callback interface.
HapticDriver_DRV2605 haptic