mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
✨ feat: add vibration feedback support for UI events
- Add genericVibration class with 5-second cooldown and 1-second pulse - Integrate vibration triggers for new messages and contact discoveries - Add conditional compilation support with PIN_VIBRATION guard - Implement abstract interface for vibration in UITask system
This commit is contained in:
parent
d86851b881
commit
2da50882c0
6 changed files with 112 additions and 0 deletions
43
src/helpers/ui/vibration.cpp
Normal file
43
src/helpers/ui/vibration.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifdef PIN_VIBRATION
|
||||
#include "vibration.h"
|
||||
|
||||
void genericVibration::begin()
|
||||
{
|
||||
pinMode(PIN_VIBRATION, OUTPUT);
|
||||
digitalWrite(PIN_VIBRATION, LOW);
|
||||
duration = 0;
|
||||
}
|
||||
|
||||
void genericVibration::trigger()
|
||||
{
|
||||
duration = millis();
|
||||
digitalWrite(PIN_VIBRATION, HIGH);
|
||||
}
|
||||
|
||||
void genericVibration::loop()
|
||||
{
|
||||
if (isVibrating()) {
|
||||
if ((millis() / 1000) % 2 == 0) {
|
||||
digitalWrite(PIN_VIBRATION, LOW);
|
||||
} else {
|
||||
digitalWrite(PIN_VIBRATION, HIGH);
|
||||
}
|
||||
|
||||
if (millis() - duration > VIBRATION_TIMEOUT) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool genericVibration::isVibrating()
|
||||
{
|
||||
return duration > 0;
|
||||
}
|
||||
|
||||
void genericVibration::stop()
|
||||
{
|
||||
duration = 0;
|
||||
digitalWrite(PIN_VIBRATION, LOW);
|
||||
}
|
||||
|
||||
#endif // ifdef PIN_VIBRATION
|
||||
34
src/helpers/ui/vibration.h
Normal file
34
src/helpers/ui/vibration.h
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
#pragma once
|
||||
|
||||
#ifdef PIN_VIBRATION
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
* Vibration motor control class
|
||||
*
|
||||
* Provides vibration feedback for events like new messages and new contacts
|
||||
* Features:
|
||||
* - 1-second vibration pulse
|
||||
* - 5-second nag timeout (cooldown between vibrations)
|
||||
* - Non-blocking operation
|
||||
*/
|
||||
|
||||
#ifndef VIBRATION_TIMEOUT
|
||||
#define VIBRATION_TIMEOUT 5000 // 5 seconds default
|
||||
#endif
|
||||
|
||||
class genericVibration
|
||||
{
|
||||
public:
|
||||
void begin(); // set up vibration pin
|
||||
void trigger(); // trigger vibration if cooldown has passed
|
||||
void loop(); // non-blocking timer handling
|
||||
bool isVibrating(); // returns true if currently vibrating
|
||||
void stop(); // stop vibration immediately
|
||||
|
||||
private:
|
||||
unsigned long duration;
|
||||
};
|
||||
|
||||
#endif // ifdef PIN_VIBRATION
|
||||
Loading…
Add table
Add a link
Reference in a new issue