Issue #713 - Now automatic Switch files are played

This commit is contained in:
Bertrand Songis
2014-02-19 11:30:54 +01:00
parent e38a4d320f
commit ad134173be
3 changed files with 73 additions and 21 deletions
+10
View File
@@ -296,8 +296,18 @@ bool isAudioFileReferenced(uint32_t i, char * filename)
return false;
}
void playModelEvent(uint8_t category, uint8_t index, uint8_t event)
{
char filename[AUDIO_FILENAME_MAXLEN+1];
if (isAudioFileReferenced((category << 24) + (index << 16) + event, filename)) {
audioQueue.playFile(filename);
}
}
#else
#define isAudioFileReferenced(i, f) false
#endif
// TODO should be generated and in flash rather than in ram
+5 -2
View File
@@ -305,11 +305,14 @@ void pushPrompt(uint16_t prompt, uint8_t id=0);
#define AUDIO_RESET() audioQueue.reset()
#if defined(SDCARD)
#define PLAY_PHASE_OFF(phase) do { char filename[AUDIO_FILENAME_MAXLEN+1]; if (isAudioFileReferenced((PHASE_AUDIO_CATEGORY << 24) + (phase << 16) + AUDIO_EVENT_OFF, filename)) audioQueue.playFile(filename); } while (0)
#define PLAY_PHASE_ON(phase) do { char filename[AUDIO_FILENAME_MAXLEN+1]; if (isAudioFileReferenced((PHASE_AUDIO_CATEGORY << 24) + (phase << 16) + AUDIO_EVENT_ON, filename)) audioQueue.playFile(filename); } while (0)
void playModelEvent(uint8_t category, uint8_t index, uint8_t event=0);
#define PLAY_PHASE_OFF(phase) playModelEvent(PHASE_AUDIO_CATEGORY, phase, AUDIO_EVENT_OFF)
#define PLAY_PHASE_ON(phase) playModelEvent(PHASE_AUDIO_CATEGORY, phase, AUDIO_EVENT_ON)
#define PLAY_SWITCH_MOVED(sw) playModelEvent(SWITCH_AUDIO_CATEGORY, sw)
#else
#define PLAY_PHASE_OFF(phase)
#define PLAY_PHASE_ON(phase)
#define PLAY_SWITCH_MOVED(sw)
#endif
void referenceSystemAudioFiles();
+58 -19
View File
@@ -1322,26 +1322,65 @@ tmr10ms_t switchesMidposStart[6] = { 0 };
uint32_t switchesPos = 0;
tmr10ms_t potsLastposStart[NUM_XPOTS];
uint8_t potsPos[NUM_XPOTS];
uint32_t check2PosSwitchPosition(EnumKeys sw)
{
uint32_t result;
uint32_t index;
if (switchState(sw))
index = sw - SW_SA0;
else
index = sw - SW_SA0 + 1;
result = (1 << index);
if (!(switchesPos & result)) {
PLAY_SWITCH_MOVED(index);
}
return result;
}
#define DELAY_SWITCH_3POS 10/*100ms*/
#define CHECK_2POS(sw) newPos |= (switchState(sw ## 0) ? (1 << (sw ## 0 - SW_SA0)) : (1 << (sw ## 0 - SW_SA0 + 1)))
#define CHECK_3POS(idx, sw) if (switchState(sw ## 0)) { \
newPos |= (1 << (sw ## 0 - SW_SA0)); \
switchesMidposStart[idx] = 0; \
} \
else if (switchState(sw ## 2)) { \
newPos |= (1 << (sw ## 0 - SW_SA0 + 2)); \
switchesMidposStart[idx] = 0; \
} \
else if ((switchesPos & (1 << (sw ## 0 - SW_SA0 + 1))) || (switchesMidposStart[idx] && (tmr10ms_t)(get_tmr10ms() - switchesMidposStart[idx]) > DELAY_SWITCH_3POS)) { \
newPos |= (1 << (sw ## 0 - SW_SA0 + 1)); \
switchesMidposStart[idx] = 0; \
} \
else { \
if (!switchesMidposStart[idx]) { \
switchesMidposStart[idx] = get_tmr10ms(); \
} \
newPos |= (switchesPos & (0x7 << (sw ## 0 - SW_SA0))); \
}
uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw)
{
uint32_t result;
uint32_t index;
if (switchState(sw)) {
index = sw - SW_SA0;
result = (1 << index);
switchesMidposStart[idx] = 0;
}
else if (switchState(EnumKeys(sw+2))) {
index = sw - SW_SA0 + 2;
result = (1 << index);
switchesMidposStart[idx] = 0;
}
else if ((switchesPos & (1 << (sw - SW_SA0 + 1))) || (switchesMidposStart[idx] && (tmr10ms_t)(get_tmr10ms() - switchesMidposStart[idx]) > DELAY_SWITCH_3POS)) {
index = sw - SW_SA0 + 1;
result = (1 << index);
switchesMidposStart[idx] = 0;
}
else {
index = sw - SW_SA0 + 1;
if (!switchesMidposStart[idx]) {
switchesMidposStart[idx] = get_tmr10ms();
}
result = (switchesPos & (0x7 << (sw - SW_SA0)));
}
if (!(switchesPos & result)) {
PLAY_SWITCH_MOVED(index);
}
return result;
}
#define CHECK_2POS(sw) newPos |= check2PosSwitchPosition(sw ## 0)
#define CHECK_3POS(idx, sw) newPos |= check3PosSwitchPosition(idx, sw ## 0)
void getSwitchesPosition()
{
uint32_t newPos = 0;