Associate an ID to each set of prompts played by Function Switches so that if the ID is present in the prompts queue, it is not queued again.

This commit is contained in:
bsongis
2012-08-27 13:24:45 +00:00
parent 9960e84d2d
commit 77571bd9cd
12 changed files with 192 additions and 148 deletions
+14 -3
View File
@@ -411,6 +411,16 @@ void AudioQueue::pause(uint8_t tLen)
play(0, 0, tLen); // a pause
}
bool AudioQueue::isPlaying(uint8_t id)
{
for (uint8_t i=0; i<AUDIO_QUEUE_LENGTH; i++) {
AudioFragment & fragment = fragments[i];
if (fragment.id == id)
return true;
}
return false;
}
#ifndef SIMU
extern OS_MutexID audioMutex;
#endif
@@ -456,7 +466,7 @@ void AudioQueue::play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlag
CoLeaveMutexSection(audioMutex);
}
void AudioQueue::playFile(const char *filename, uint8_t flags)
void AudioQueue::playFile(const char *filename, uint8_t flags, uint8_t id)
{
#ifdef SIMU
printf("playFile(\"%s\")\n", filename); fflush(stdout);
@@ -473,6 +483,7 @@ void AudioQueue::playFile(const char *filename, uint8_t flags)
memset(&fragment, 0, sizeof(fragment));
strcpy(fragment.file, filename);
fragment.repeat = flags & 0x0f;
fragment.id = id;
if (flags & PLAY_NOW)
prioIdx = widx;
widx = next_widx;
@@ -666,7 +677,7 @@ void audioEvent(uint8_t e, uint8_t f)
}
}
void pushPrompt(uint16_t prompt)
void pushPrompt(uint16_t prompt, uint8_t id)
{
#if defined(SDCARD)
@@ -677,7 +688,7 @@ void pushPrompt(uint16_t prompt)
prompt /= 10;
}
audioQueue.playFile(filename);
audioQueue.playFile(filename, id);
#endif
}
+13 -2
View File
@@ -47,6 +47,7 @@ class ToneFragment {
uint8_t pause;
uint8_t repeat;
int8_t freqIncr;
uint8_t id;
};
class AudioFragment : public ToneFragment {
@@ -72,10 +73,12 @@ class AudioQueue {
void play(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tFlags=0, int8_t tFreqIncr=0);
void playFile(const char *filename, uint8_t tFlags=0);
void playFile(const char *filename, uint8_t flags=0, uint8_t id=0);
void pause(uint8_t tLen);
bool isPlaying(uint8_t id);
bool busy()
{
#ifdef SIMU
@@ -134,6 +137,14 @@ void audioEvent(uint8_t e, uint8_t f=BEEP_DEFAULT_FREQ);
#define AUDIO_HEARTBEAT()
extern void pushPrompt(uint16_t prompt);
extern void pushPrompt(uint16_t prompt, uint8_t id=0);
#define PLAY_FUNCTION(x, ...) void x(__VA_ARGS__, uint8_t id)
#define PUSH_PROMPT(p) pushPrompt((p), id)
#define PLAY_NUMBER(n, u, a) playNumber((n), (u), (a), id)
#define PLAY_DURATION(d) playDuration((d), id)
#define IS_PLAYING(id) audioQueue.isPlaying((id))
#define PLAY_VALUE(v, id) playValue((v), (id))
#define PLAY_FILE(f, id) audioQueue.playFile((f), (id))
#endif