mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-22 10:56:48 +00:00
Add RGB LED and haptic notifications for SenseCAP MeshTracker X1
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
#ifdef HAS_DRV2605
|
||||
|
||||
#include "DRV2605Vibration.h"
|
||||
#include <Wire.h>
|
||||
|
||||
void DRV2605Vibration::begin() {
|
||||
#ifdef PIN_DRV_EN
|
||||
pinMode(PIN_DRV_EN, OUTPUT);
|
||||
digitalWrite(PIN_DRV_EN, HIGH); // power up the haptic driver
|
||||
delay(10);
|
||||
#endif
|
||||
if (!drv.begin(&Wire)) {
|
||||
return; // no haptic driver found, stay silent
|
||||
}
|
||||
#ifdef DRV2605_USE_LRA
|
||||
// LRA mode: 4x brake factor, medium loop gain, back-EMF gain 2
|
||||
drv.writeRegister8(DRV2605_REG_FEEDBACK, 0xB6);
|
||||
#endif
|
||||
drv.selectLibrary(1);
|
||||
drv.setMode(DRV2605_MODE_INTTRIG);
|
||||
_ready = true;
|
||||
}
|
||||
|
||||
void DRV2605Vibration::trigger(bool force) {
|
||||
if (!_ready || _quiet) return;
|
||||
unsigned long now = millis();
|
||||
if (!force && _last_trigger != 0 && now - _last_trigger < VIBRATION_TIMEOUT) return;
|
||||
_last_trigger = now;
|
||||
drv.setWaveform(0, DRV2605_EFFECT);
|
||||
drv.setWaveform(1, 0); // pause
|
||||
drv.setWaveform(2, DRV2605_EFFECT);
|
||||
drv.setWaveform(3, 0); // end of sequence
|
||||
drv.go();
|
||||
}
|
||||
|
||||
void DRV2605Vibration::loop() {
|
||||
}
|
||||
|
||||
bool DRV2605Vibration::isVibrating() {
|
||||
return false; // effects are short, treat as instantaneous
|
||||
}
|
||||
|
||||
void DRV2605Vibration::stop() {
|
||||
if (_ready) drv.stop();
|
||||
}
|
||||
|
||||
#endif // ifdef HAS_DRV2605
|
||||
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef HAS_DRV2605
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_DRV2605.h>
|
||||
|
||||
/*
|
||||
* Vibration control class for boards where the motor is behind a
|
||||
* DRV2605 haptic driver on I2C (e.g. Seeed SenseCAP MeshTracker X1).
|
||||
* Same interface as GenericVibration.
|
||||
*/
|
||||
|
||||
#ifndef VIBRATION_TIMEOUT
|
||||
#define VIBRATION_TIMEOUT 5000 // cooldown between vibrations
|
||||
#endif
|
||||
|
||||
#ifndef DRV2605_EFFECT
|
||||
#define DRV2605_EFFECT 16 // "1000 ms alert" from the DRV2605 effect library
|
||||
#endif
|
||||
|
||||
class DRV2605Vibration {
|
||||
public:
|
||||
void begin(); // power up and init the DRV2605
|
||||
void trigger(bool force = false); // trigger vibration; force skips the cooldown
|
||||
void loop(); // no-op, the DRV2605 plays effects autonomously
|
||||
bool isVibrating();
|
||||
void stop(); // stop vibration immediately
|
||||
void quiet(bool q) { _quiet = q; }
|
||||
bool isQuiet() const { return _quiet; }
|
||||
|
||||
private:
|
||||
Adafruit_DRV2605 drv;
|
||||
bool _ready = false;
|
||||
bool _quiet = false;
|
||||
unsigned long _last_trigger = 0;
|
||||
};
|
||||
|
||||
#endif // ifdef HAS_DRV2605
|
||||
Reference in New Issue
Block a user