HAPTIC is now a compile option

This commit is contained in:
bsongis
2012-01-27 19:22:28 +00:00
parent e6d8648074
commit 7d511b1e13
3 changed files with 101 additions and 68 deletions
+8 -1
View File
@@ -64,6 +64,10 @@ endif
# Values = YES, NO
AUDIO = YES
# HAPTIC Mods
# Values = YES, NO
HAPTIC = NO
# SPLASH on START
SPLASH = YES
@@ -227,7 +231,10 @@ endif
ifeq ($(AUDIO), YES)
CPPDEFS += -DAUDIO
CPPSRC += audio.cpp
CPPSRC += audio.cpp
ifeq ($(HAPTIC), YES)
CPPDEFS += -DHAPTIC
endif
else
CPPSRC += beeper.cpp
endif
+30 -2
View File
@@ -36,7 +36,10 @@ void audioQueue::aqinit()
queueState = 0;
toneRepeatCnt = 0;
inToneRepeat = 0;
#ifdef HAPTIC
hapticTick = 0;
#endif
#ifdef FRSKY
frskySample = 0;
@@ -44,7 +47,6 @@ void audioQueue::aqinit()
heartbeatTimer = 0;
flushTemp();
}
bool audioQueue::busy()
@@ -86,7 +88,9 @@ void audioQueue::commit(uint8_t toneInterupt)
queueToneLength[i] = t_queueToneLength;
queueTonePause[i] = t_queueTonePause;
queueToneRepeat[i] = t_queueToneRepeat;
#ifdef HAPTIC
queueToneHaptic[i] = t_queueToneHaptic;
#endif
flushTemp();
break;
}
@@ -100,7 +104,9 @@ void audioQueue::commit(uint8_t toneInterupt)
queueToneLength[0] = t_queueToneLength;
queueTonePause[0] = t_queueTonePause;
queueToneRepeat[0] = t_queueToneRepeat;
#ifdef HAPTIC
queueToneHaptic[0] = t_queueToneHaptic;
#endif
flushqueue(1); //purge queue on interrupt events to stop broken audio
flushTemp();
@@ -116,7 +122,9 @@ void audioQueue::flushqueue(uint8_t startpos)
queueToneLength[startpos] = 0;
queueTonePause[startpos] = 0;
queueToneRepeat[startpos] = 0;
#ifdef HAPTIC
queueToneHaptic[startpos] = 0;
#endif
}
}
@@ -128,9 +136,13 @@ void audioQueue::flushTemp()
t_queueToneLength = 0;
t_queueTonePause = 0;
t_queueToneRepeat = 0;
#ifdef HAPTIC
t_queueToneHaptic = 0;
#endif
rateOfChange = 0;
#ifdef HAPTIC
toneHaptic = 0;
#endif
}
void audioQueue::restack()
@@ -141,7 +153,9 @@ void audioQueue::restack()
queueToneLength[i] = queueToneLength[i + 1];
queueTonePause[i] = queueTonePause[i + 1];
queueToneRepeat[i] = queueToneRepeat[i + 1];
#ifdef HAPTIC
queueToneHaptic[i] = queueToneHaptic[i + 1];
#endif
}
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;
if (toneHaptic == 1) {
if ((hapticTick <= hapticStrength - 1) && hapticStrength > 0) {
@@ -237,6 +252,7 @@ void audioQueue::heartbeat()
else {
HAPTIC_OFF; // haptic output 'low'
}
#endif
}
else {
@@ -246,7 +262,11 @@ void audioQueue::heartbeat()
//step through array checking if we have any tones to play
//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) {
if (queueToneEnd[0] > 0 && queueToneEnd[0] != queueToneStart[0]) {
if (queueToneStart[0] > queueToneEnd[0]) { //tone going down
@@ -267,7 +287,9 @@ void audioQueue::heartbeat()
toneTimeLeft = z;
tonePause = queueTonePause[0];
toneRepeat = queueToneRepeat[0];
#ifdef HAPTIC
toneHaptic = queueToneHaptic[0];
#endif
}
else {
//simple tone handler
@@ -282,7 +304,9 @@ void audioQueue::heartbeat()
toneTimeLeft = queueToneLength[0];
tonePause = queueTonePause[0];
toneRepeat = queueToneRepeat[0];
#ifdef HAPTIC
toneHaptic = queueToneHaptic[0];
#endif
}
queueState = 1;
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_queueToneLength = tLen;
t_queueTonePause = tPause;
#ifdef HAPTIC
t_queueToneHaptic = tHaptic;
#endif
t_queueToneRepeat = tRepeat;
t_queueToneEnd = tEnd;
commit(1);
@@ -360,7 +386,9 @@ void audioQueue::playASAP(uint8_t tStart, uint8_t tLen, uint8_t tPause,
t_queueToneStart = tStart;
t_queueToneLength = tLen;
t_queueTonePause = tPause;
#ifdef HAPTIC
t_queueToneHaptic = tHaptic;
#endif
t_queueToneRepeat = tRepeat;
t_queueToneEnd = tEnd;
commit(0);
+63 -65
View File
@@ -27,11 +27,13 @@
#define AUDIO_QUEUE_HEARTBEAT_NORM (77) //speaker timing [Norm]
#define AUDIO_QUEUE_HEARTBEAT_LONG (130) //speaker timing [Long]
#define AUDIO_QUEUE_HEARTBEAT_XLONG (200) //speaker timing [xLong]
#ifdef HAPTIC
#define HAPTIC_ON 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 */
#define AU_TADA (0)
@@ -75,8 +77,6 @@
#define AU_FRSKY_HAPTIC3 (15)
#endif
#define BEEP_QUIET (0)
#define BEEP_NOKEYS (1)
#define BEEP_XSHORT (2)
@@ -85,83 +85,84 @@
#define BEEP_LONG (5)
#define BEEP_XLONG (6)
struct audioQueue {
struct audioQueue{
//queue temporaries
uint8_t t_queueToneStart;
uint8_t t_queueToneEnd;
uint8_t t_queueToneLength;
uint8_t t_queueTonePause;
uint8_t t_queueToneRepeat;
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 temporaries
uint8_t t_queueToneStart;
uint8_t t_queueToneEnd;
uint8_t t_queueToneLength;
uint8_t t_queueTonePause;
uint8_t t_queueToneRepeat;
#ifdef HAPTIC
uint8_t t_queueToneHaptic;
#endif
//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
uint8_t frskySample;
uint8_t frskySample;
#endif
//queue arrays
uint8_t queueToneStart[AUDIO_QUEUE_LENGTH];
uint8_t queueToneEnd[AUDIO_QUEUE_LENGTH];
uint8_t queueToneLength[AUDIO_QUEUE_LENGTH];
uint8_t queueTonePause[AUDIO_QUEUE_LENGTH];
uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
uint8_t queueToneHaptic[AUDIO_QUEUE_LENGTH];
//queue arrays
uint8_t queueToneStart[AUDIO_QUEUE_LENGTH];
uint8_t queueToneEnd[AUDIO_QUEUE_LENGTH];
uint8_t queueToneLength[AUDIO_QUEUE_LENGTH];
uint8_t queueTonePause[AUDIO_QUEUE_LENGTH];
uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH];
#ifdef HAPTIC
uint8_t queueToneHaptic[AUDIO_QUEUE_LENGTH];
#endif
//beep length table
// uint8_t beepLenTable[10];
//beep length table
// uint8_t beepLenTable[10];
audioQueue();
public:
//constructor
audioQueue();
void aqinit(); // To stop constructor being compiled twice
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
//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();
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
void frskyevent(uint8_t e);
void frskyeventSample(uint8_t e);
void frskyevent(uint8_t e);
void frskyeventSample(uint8_t e);
#endif
void commit( uint8_t toneInterupt );
//set all temporary buffers to default
void flushTemp();
void flushqueue( uint8_t startpos ) ;
void commit(uint8_t toneInterupt);
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);
//set all temporary buffers to default
void flushTemp();
void flushqueue(uint8_t startpos);
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!!!
extern audioQueue audio;
extern audioQueue audio;
//void audioevent(uint8_t e,uint8_t f=BEEP_DEFAULT_FREQ);
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_3() audioDefevent(AU_MIX_WARNING_3)
#define AUDIO_HEARTBEAT() audio.heartbeat()
#endif // audio_h