HAPTIC is now a compile option
This commit is contained in:
+8
-1
@@ -64,6 +64,10 @@ endif
|
|||||||
# Values = YES, NO
|
# Values = YES, NO
|
||||||
AUDIO = YES
|
AUDIO = YES
|
||||||
|
|
||||||
|
# HAPTIC Mods
|
||||||
|
# Values = YES, NO
|
||||||
|
HAPTIC = NO
|
||||||
|
|
||||||
# SPLASH on START
|
# SPLASH on START
|
||||||
SPLASH = YES
|
SPLASH = YES
|
||||||
|
|
||||||
@@ -227,7 +231,10 @@ endif
|
|||||||
|
|
||||||
ifeq ($(AUDIO), YES)
|
ifeq ($(AUDIO), YES)
|
||||||
CPPDEFS += -DAUDIO
|
CPPDEFS += -DAUDIO
|
||||||
CPPSRC += audio.cpp
|
CPPSRC += audio.cpp
|
||||||
|
ifeq ($(HAPTIC), YES)
|
||||||
|
CPPDEFS += -DHAPTIC
|
||||||
|
endif
|
||||||
else
|
else
|
||||||
CPPSRC += beeper.cpp
|
CPPSRC += beeper.cpp
|
||||||
endif
|
endif
|
||||||
|
|||||||
+30
-2
@@ -36,7 +36,10 @@ void audioQueue::aqinit()
|
|||||||
queueState = 0;
|
queueState = 0;
|
||||||
toneRepeatCnt = 0;
|
toneRepeatCnt = 0;
|
||||||
inToneRepeat = 0;
|
inToneRepeat = 0;
|
||||||
|
|
||||||
|
#ifdef HAPTIC
|
||||||
hapticTick = 0;
|
hapticTick = 0;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef FRSKY
|
#ifdef FRSKY
|
||||||
frskySample = 0;
|
frskySample = 0;
|
||||||
@@ -44,7 +47,6 @@ void audioQueue::aqinit()
|
|||||||
|
|
||||||
heartbeatTimer = 0;
|
heartbeatTimer = 0;
|
||||||
flushTemp();
|
flushTemp();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool audioQueue::busy()
|
bool audioQueue::busy()
|
||||||
@@ -86,7 +88,9 @@ void audioQueue::commit(uint8_t toneInterupt)
|
|||||||
queueToneLength[i] = t_queueToneLength;
|
queueToneLength[i] = t_queueToneLength;
|
||||||
queueTonePause[i] = t_queueTonePause;
|
queueTonePause[i] = t_queueTonePause;
|
||||||
queueToneRepeat[i] = t_queueToneRepeat;
|
queueToneRepeat[i] = t_queueToneRepeat;
|
||||||
|
#ifdef HAPTIC
|
||||||
queueToneHaptic[i] = t_queueToneHaptic;
|
queueToneHaptic[i] = t_queueToneHaptic;
|
||||||
|
#endif
|
||||||
flushTemp();
|
flushTemp();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -100,7 +104,9 @@ void audioQueue::commit(uint8_t toneInterupt)
|
|||||||
queueToneLength[0] = t_queueToneLength;
|
queueToneLength[0] = t_queueToneLength;
|
||||||
queueTonePause[0] = t_queueTonePause;
|
queueTonePause[0] = t_queueTonePause;
|
||||||
queueToneRepeat[0] = t_queueToneRepeat;
|
queueToneRepeat[0] = t_queueToneRepeat;
|
||||||
|
#ifdef HAPTIC
|
||||||
queueToneHaptic[0] = t_queueToneHaptic;
|
queueToneHaptic[0] = t_queueToneHaptic;
|
||||||
|
#endif
|
||||||
|
|
||||||
flushqueue(1); //purge queue on interrupt events to stop broken audio
|
flushqueue(1); //purge queue on interrupt events to stop broken audio
|
||||||
flushTemp();
|
flushTemp();
|
||||||
@@ -116,7 +122,9 @@ void audioQueue::flushqueue(uint8_t startpos)
|
|||||||
queueToneLength[startpos] = 0;
|
queueToneLength[startpos] = 0;
|
||||||
queueTonePause[startpos] = 0;
|
queueTonePause[startpos] = 0;
|
||||||
queueToneRepeat[startpos] = 0;
|
queueToneRepeat[startpos] = 0;
|
||||||
|
#ifdef HAPTIC
|
||||||
queueToneHaptic[startpos] = 0;
|
queueToneHaptic[startpos] = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -128,9 +136,13 @@ void audioQueue::flushTemp()
|
|||||||
t_queueToneLength = 0;
|
t_queueToneLength = 0;
|
||||||
t_queueTonePause = 0;
|
t_queueTonePause = 0;
|
||||||
t_queueToneRepeat = 0;
|
t_queueToneRepeat = 0;
|
||||||
|
#ifdef HAPTIC
|
||||||
t_queueToneHaptic = 0;
|
t_queueToneHaptic = 0;
|
||||||
|
#endif
|
||||||
rateOfChange = 0;
|
rateOfChange = 0;
|
||||||
|
#ifdef HAPTIC
|
||||||
toneHaptic = 0;
|
toneHaptic = 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void audioQueue::restack()
|
void audioQueue::restack()
|
||||||
@@ -141,7 +153,9 @@ void audioQueue::restack()
|
|||||||
queueToneLength[i] = queueToneLength[i + 1];
|
queueToneLength[i] = queueToneLength[i + 1];
|
||||||
queueTonePause[i] = queueTonePause[i + 1];
|
queueTonePause[i] = queueTonePause[i + 1];
|
||||||
queueToneRepeat[i] = queueToneRepeat[i + 1];
|
queueToneRepeat[i] = queueToneRepeat[i + 1];
|
||||||
|
#ifdef HAPTIC
|
||||||
queueToneHaptic[i] = queueToneHaptic[i + 1];
|
queueToneHaptic[i] = queueToneHaptic[i + 1];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
flushqueue(AUDIO_QUEUE_LENGTH - 1); //set the last entry to 0 as nothing in stack to add too!
|
flushqueue(AUDIO_QUEUE_LENGTH - 1); //set the last entry to 0 as nothing in stack to add too!
|
||||||
}
|
}
|
||||||
@@ -223,6 +237,7 @@ void audioQueue::heartbeat()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAPTIC
|
||||||
uint8_t hapticStrength = g_eeGeneral.hapticStrength;
|
uint8_t hapticStrength = g_eeGeneral.hapticStrength;
|
||||||
if (toneHaptic == 1) {
|
if (toneHaptic == 1) {
|
||||||
if ((hapticTick <= hapticStrength - 1) && hapticStrength > 0) {
|
if ((hapticTick <= hapticStrength - 1) && hapticStrength > 0) {
|
||||||
@@ -237,6 +252,7 @@ void audioQueue::heartbeat()
|
|||||||
else {
|
else {
|
||||||
HAPTIC_OFF; // haptic output 'low'
|
HAPTIC_OFF; // haptic output 'low'
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -246,7 +262,11 @@ void audioQueue::heartbeat()
|
|||||||
|
|
||||||
//step through array checking if we have any tones to play
|
//step through array checking if we have any tones to play
|
||||||
//next heartbeat will play whatever we put in queue
|
//next heartbeat will play whatever we put in queue
|
||||||
if ((queueToneStart[0] > 0 || queueToneHaptic[0] == 1) && toneTimeLeft <= 0
|
if ((queueToneStart[0] > 0
|
||||||
|
#ifdef HAPTIC
|
||||||
|
|| queueToneHaptic[0] == 1
|
||||||
|
#endif
|
||||||
|
) && toneTimeLeft <= 0
|
||||||
&& queueState == 0) {
|
&& queueState == 0) {
|
||||||
if (queueToneEnd[0] > 0 && queueToneEnd[0] != queueToneStart[0]) {
|
if (queueToneEnd[0] > 0 && queueToneEnd[0] != queueToneStart[0]) {
|
||||||
if (queueToneStart[0] > queueToneEnd[0]) { //tone going down
|
if (queueToneStart[0] > queueToneEnd[0]) { //tone going down
|
||||||
@@ -267,7 +287,9 @@ void audioQueue::heartbeat()
|
|||||||
toneTimeLeft = z;
|
toneTimeLeft = z;
|
||||||
tonePause = queueTonePause[0];
|
tonePause = queueTonePause[0];
|
||||||
toneRepeat = queueToneRepeat[0];
|
toneRepeat = queueToneRepeat[0];
|
||||||
|
#ifdef HAPTIC
|
||||||
toneHaptic = queueToneHaptic[0];
|
toneHaptic = queueToneHaptic[0];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//simple tone handler
|
//simple tone handler
|
||||||
@@ -282,7 +304,9 @@ void audioQueue::heartbeat()
|
|||||||
toneTimeLeft = queueToneLength[0];
|
toneTimeLeft = queueToneLength[0];
|
||||||
tonePause = queueTonePause[0];
|
tonePause = queueTonePause[0];
|
||||||
toneRepeat = queueToneRepeat[0];
|
toneRepeat = queueToneRepeat[0];
|
||||||
|
#ifdef HAPTIC
|
||||||
toneHaptic = queueToneHaptic[0];
|
toneHaptic = queueToneHaptic[0];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
queueState = 1;
|
queueState = 1;
|
||||||
if (toneRepeat != 0 && inToneRepeat == 0) {
|
if (toneRepeat != 0 && inToneRepeat == 0) {
|
||||||
@@ -348,7 +372,9 @@ void audioQueue::playNow(uint8_t tStart, uint8_t tLen, uint8_t tPause,
|
|||||||
t_queueToneStart = tStart;
|
t_queueToneStart = tStart;
|
||||||
t_queueToneLength = tLen;
|
t_queueToneLength = tLen;
|
||||||
t_queueTonePause = tPause;
|
t_queueTonePause = tPause;
|
||||||
|
#ifdef HAPTIC
|
||||||
t_queueToneHaptic = tHaptic;
|
t_queueToneHaptic = tHaptic;
|
||||||
|
#endif
|
||||||
t_queueToneRepeat = tRepeat;
|
t_queueToneRepeat = tRepeat;
|
||||||
t_queueToneEnd = tEnd;
|
t_queueToneEnd = tEnd;
|
||||||
commit(1);
|
commit(1);
|
||||||
@@ -360,7 +386,9 @@ void audioQueue::playASAP(uint8_t tStart, uint8_t tLen, uint8_t tPause,
|
|||||||
t_queueToneStart = tStart;
|
t_queueToneStart = tStart;
|
||||||
t_queueToneLength = tLen;
|
t_queueToneLength = tLen;
|
||||||
t_queueTonePause = tPause;
|
t_queueTonePause = tPause;
|
||||||
|
#ifdef HAPTIC
|
||||||
t_queueToneHaptic = tHaptic;
|
t_queueToneHaptic = tHaptic;
|
||||||
|
#endif
|
||||||
t_queueToneRepeat = tRepeat;
|
t_queueToneRepeat = tRepeat;
|
||||||
t_queueToneEnd = tEnd;
|
t_queueToneEnd = tEnd;
|
||||||
commit(0);
|
commit(0);
|
||||||
|
|||||||
+63
-65
@@ -27,11 +27,13 @@
|
|||||||
#define AUDIO_QUEUE_HEARTBEAT_NORM (77) //speaker timing [Norm]
|
#define AUDIO_QUEUE_HEARTBEAT_NORM (77) //speaker timing [Norm]
|
||||||
#define AUDIO_QUEUE_HEARTBEAT_LONG (130) //speaker timing [Long]
|
#define AUDIO_QUEUE_HEARTBEAT_LONG (130) //speaker timing [Long]
|
||||||
#define AUDIO_QUEUE_HEARTBEAT_XLONG (200) //speaker timing [xLong]
|
#define AUDIO_QUEUE_HEARTBEAT_XLONG (200) //speaker timing [xLong]
|
||||||
|
#ifdef HAPTIC
|
||||||
|
|
||||||
|
|
||||||
#define HAPTIC_ON PORTG |= (1<<2)
|
#define HAPTIC_ON PORTG |= (1<<2)
|
||||||
#define HAPTIC_OFF PORTG &= ~(1<<2)
|
#define HAPTIC_OFF PORTG &= ~(1<<2)
|
||||||
|
#else
|
||||||
|
#define HAPTIC_ON
|
||||||
|
#define HAPTIC_OFF
|
||||||
|
#endif
|
||||||
|
|
||||||
/* make sure the defines below always go in numeric order */
|
/* make sure the defines below always go in numeric order */
|
||||||
#define AU_TADA (0)
|
#define AU_TADA (0)
|
||||||
@@ -75,8 +77,6 @@
|
|||||||
#define AU_FRSKY_HAPTIC3 (15)
|
#define AU_FRSKY_HAPTIC3 (15)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define BEEP_QUIET (0)
|
#define BEEP_QUIET (0)
|
||||||
#define BEEP_NOKEYS (1)
|
#define BEEP_NOKEYS (1)
|
||||||
#define BEEP_XSHORT (2)
|
#define BEEP_XSHORT (2)
|
||||||
@@ -85,83 +85,84 @@
|
|||||||
#define BEEP_LONG (5)
|
#define BEEP_LONG (5)
|
||||||
#define BEEP_XLONG (6)
|
#define BEEP_XLONG (6)
|
||||||
|
|
||||||
|
struct audioQueue {
|
||||||
|
|
||||||
struct audioQueue{
|
//queue temporaries
|
||||||
|
uint8_t t_queueToneStart;
|
||||||
|
uint8_t t_queueToneEnd;
|
||||||
//queue temporaries
|
uint8_t t_queueToneLength;
|
||||||
uint8_t t_queueToneStart;
|
uint8_t t_queueTonePause;
|
||||||
uint8_t t_queueToneEnd;
|
uint8_t t_queueToneRepeat;
|
||||||
uint8_t t_queueToneLength;
|
#ifdef HAPTIC
|
||||||
uint8_t t_queueTonePause;
|
uint8_t t_queueToneHaptic;
|
||||||
uint8_t t_queueToneRepeat;
|
#endif
|
||||||
uint8_t t_queueToneHaptic;
|
|
||||||
|
|
||||||
//queue general vars
|
|
||||||
uint8_t toneFreq;
|
|
||||||
uint8_t toneFreqEnd;
|
|
||||||
uint8_t toneTimeLeft;
|
|
||||||
int8_t rateOfChange;
|
|
||||||
uint8_t tonePause;
|
|
||||||
uint8_t queueState;
|
|
||||||
uint8_t toneRepeat;
|
|
||||||
uint8_t toneRepeatCnt;
|
|
||||||
uint8_t inToneRepeat;
|
|
||||||
uint8_t toneHaptic;
|
|
||||||
uint8_t hapticTick;
|
|
||||||
uint8_t heartbeatTimer;
|
|
||||||
|
|
||||||
|
//queue general vars
|
||||||
|
uint8_t toneFreq;
|
||||||
|
uint8_t toneFreqEnd;
|
||||||
|
uint8_t toneTimeLeft;
|
||||||
|
int8_t rateOfChange;
|
||||||
|
uint8_t tonePause;
|
||||||
|
uint8_t queueState;
|
||||||
|
uint8_t toneRepeat;
|
||||||
|
uint8_t toneRepeatCnt;
|
||||||
|
uint8_t inToneRepeat;
|
||||||
|
#ifdef HAPTIC
|
||||||
|
uint8_t toneHaptic;
|
||||||
|
uint8_t hapticTick;
|
||||||
|
#endif
|
||||||
|
uint8_t heartbeatTimer;
|
||||||
|
|
||||||
#ifdef FRSKY
|
#ifdef FRSKY
|
||||||
uint8_t frskySample;
|
uint8_t frskySample;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//queue arrays
|
//queue arrays
|
||||||
uint8_t queueToneStart[AUDIO_QUEUE_LENGTH];
|
uint8_t queueToneStart[AUDIO_QUEUE_LENGTH];
|
||||||
uint8_t queueToneEnd[AUDIO_QUEUE_LENGTH];
|
uint8_t queueToneEnd[AUDIO_QUEUE_LENGTH];
|
||||||
uint8_t queueToneLength[AUDIO_QUEUE_LENGTH];
|
uint8_t queueToneLength[AUDIO_QUEUE_LENGTH];
|
||||||
uint8_t queueTonePause[AUDIO_QUEUE_LENGTH];
|
uint8_t queueTonePause[AUDIO_QUEUE_LENGTH];
|
||||||
uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
|
uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
|
||||||
uint8_t queueToneHaptic[AUDIO_QUEUE_LENGTH];
|
#ifdef HAPTIC
|
||||||
|
uint8_t queueToneHaptic[AUDIO_QUEUE_LENGTH];
|
||||||
|
#endif
|
||||||
|
|
||||||
//beep length table
|
//beep length table
|
||||||
// uint8_t beepLenTable[10];
|
// uint8_t beepLenTable[10];
|
||||||
|
|
||||||
|
audioQueue();
|
||||||
|
|
||||||
public:
|
void aqinit(); // To stop constructor being compiled twice
|
||||||
//constructor
|
|
||||||
audioQueue();
|
|
||||||
|
|
||||||
void aqinit() ; // To stop constructor being compiled twice
|
//only difference between these two functions is that one does the
|
||||||
|
//interupt queue (Now) and the other queues for playing ASAP.
|
||||||
|
void playNow(uint8_t tStart,uint8_t tLen,uint8_t tPause,uint8_t tRepeat=0,uint8_t tHaptic=0,uint8_t tEnd=0);
|
||||||
|
void playASAP(uint8_t tStart,uint8_t tLen,uint8_t tPause,uint8_t tRepeat=0,uint8_t tHaptic=0,uint8_t tEnd=0);
|
||||||
|
|
||||||
//only difference between these two functions is that one does the
|
bool busy();
|
||||||
//interupt queue (Now) and the other queues for playing ASAP.
|
|
||||||
void playNow(uint8_t tStart,uint8_t tLen,uint8_t tPause,uint8_t tRepeat=0,uint8_t tHaptic=0,uint8_t tEnd=0);
|
|
||||||
void playASAP(uint8_t tStart,uint8_t tLen,uint8_t tPause,uint8_t tRepeat=0,uint8_t tHaptic=0,uint8_t tEnd=0);
|
|
||||||
bool busy();
|
|
||||||
|
|
||||||
void event(uint8_t e,uint8_t f=BEEP_DEFAULT_FREQ);
|
void event(uint8_t e,uint8_t f=BEEP_DEFAULT_FREQ);
|
||||||
|
|
||||||
#ifdef FRSKY
|
#ifdef FRSKY
|
||||||
void frskyevent(uint8_t e);
|
void frskyevent(uint8_t e);
|
||||||
void frskyeventSample(uint8_t e);
|
void frskyeventSample(uint8_t e);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void commit( uint8_t toneInterupt );
|
void commit(uint8_t toneInterupt);
|
||||||
|
|
||||||
//set all temporary buffers to default
|
|
||||||
void flushTemp();
|
|
||||||
void flushqueue( uint8_t startpos ) ;
|
|
||||||
|
|
||||||
void restack();
|
//set all temporary buffers to default
|
||||||
//heartbeat is responsibile for issueing the audio tones and general square waves
|
void flushTemp();
|
||||||
// it is essentially the life of the class.
|
void flushqueue(uint8_t startpos);
|
||||||
void heartbeat();
|
|
||||||
bool freeslots(uint8_t slots);
|
void restack();
|
||||||
|
//heartbeat is responsibile for issueing the audio tones and general square waves
|
||||||
|
// it is essentially the life of the class.
|
||||||
|
void heartbeat();
|
||||||
|
bool freeslots(uint8_t slots);
|
||||||
};
|
};
|
||||||
|
|
||||||
//wrapper function - dirty but results in a space saving!!!
|
//wrapper function - dirty but results in a space saving!!!
|
||||||
extern audioQueue audio;
|
extern audioQueue audio;
|
||||||
//void audioevent(uint8_t e,uint8_t f=BEEP_DEFAULT_FREQ);
|
//void audioevent(uint8_t e,uint8_t f=BEEP_DEFAULT_FREQ);
|
||||||
void audioDefevent(uint8_t e);
|
void audioDefevent(uint8_t e);
|
||||||
|
|
||||||
@@ -185,9 +186,6 @@ void audioError();
|
|||||||
#define AUDIO_MIX_WARNING_1() audioDefevent(AU_MIX_WARNING_1)
|
#define AUDIO_MIX_WARNING_1() audioDefevent(AU_MIX_WARNING_1)
|
||||||
#define AUDIO_MIX_WARNING_3() audioDefevent(AU_MIX_WARNING_3)
|
#define AUDIO_MIX_WARNING_3() audioDefevent(AU_MIX_WARNING_3)
|
||||||
|
|
||||||
|
|
||||||
#define AUDIO_HEARTBEAT() audio.heartbeat()
|
#define AUDIO_HEARTBEAT() audio.heartbeat()
|
||||||
|
|
||||||
|
|
||||||
#endif // audio_h
|
#endif // audio_h
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user