From f2f9579b77763026c815042bd6ab7e2d00819a46 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 19:51:32 +0100 Subject: [PATCH] Automatic sounds for multipos switches --- radio/src/audio_arm.h | 6 +++--- radio/src/opentx.cpp | 8 ++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/radio/src/audio_arm.h b/radio/src/audio_arm.h index 41a170d7b..8c67fad5e 100644 --- a/radio/src/audio_arm.h +++ b/radio/src/audio_arm.h @@ -306,9 +306,9 @@ void pushPrompt(uint16_t prompt, uint8_t id=0); #if defined(SDCARD) 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) + #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) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index ff8a7c1d8..7955f57b4 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1400,13 +1400,17 @@ void getSwitchesPosition(bool play) if (calib->count>0 && calib->countcount); uint8_t previousPos = potsPos[i] >> 4; + uint8_t previousStoredPos = potsPos[i] & 0x0F; if (pos != previousPos) { potsLastposStart[i] = get_tmr10ms(); - potsPos[i] = (pos << 4) | (potsPos[i] & 0x0f); + potsPos[i] = (pos << 4) | previousStoredPos; } else if ((tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { potsLastposStart[i] = 0; - potsPos[i] = (pos << 4) | (pos); + potsPos[i] = (pos << 4) | pos; + if (play && previousStoredPos != pos) { + PLAY_SWITCH_MOVED(SWSRC_LAST_SWITCH+i*POTS_POS_COUNT+pos); + } } } }