Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: modify playHaptic to accept "intensity" variable #3408

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions radio/src/haptic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
#include "edgetx.h"
#include "haptic.h"

constexpr uint8_t fullHaptic = 255;

hapticQueue::hapticQueue()
{
buzzTimeLeft = 0;
Expand All @@ -31,6 +33,8 @@ hapticQueue::hapticQueue()
t_queueWidx = 0;

hapticTick = 0;

intensity = fullHaptic;
}

void hapticQueue::heartbeat()
Expand All @@ -41,7 +45,11 @@ void hapticQueue::heartbeat()
if (buzzTimeLeft > 0) {
buzzTimeLeft--; // time gets counted down
#if defined(HAPTIC_PWM)
hapticOn(HAPTIC_STRENGTH() * 20);
if (intensity < fullHaptic) {
hapticOn(intensity);
} else {
hapticOn(HAPTIC_STRENGTH() * 20);
}
#else
if (hapticTick-- > 0) {
hapticOn();
Expand Down Expand Up @@ -70,11 +78,20 @@ void hapticQueue::heartbeat()

void hapticQueue::play(uint8_t tLen, uint8_t tPause, uint8_t tFlags)
{
tLen = getHapticLength(tLen);
if(tLen > 0){
tLen = getHapticLength(tLen);
}

if ((tFlags & PLAY_NOW) || (!busy() && empty())) {
buzzTimeLeft = tLen;
buzzPause = tPause;
if (tLen == 0) {
buzzTimeLeft = 250;
intensity = tPause;
buzzPause = 100;
} else {
buzzTimeLeft = tLen;
buzzPause = tPause;
intensity = fullHaptic;
}
t_queueWidx = t_queueRidx;
}
else {
Expand Down
2 changes: 2 additions & 0 deletions radio/src/haptic.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class hapticQueue

uint8_t hapticTick;

uint8_t intensity;

// queue arrays
uint8_t queueHapticLength[HAPTIC_QUEUE_LENGTH];
uint8_t queueHapticPause[HAPTIC_QUEUE_LENGTH];
Expand Down