From fbd07444314d7bf23dcfdcf711cd52bb046f102e Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Tue, 18 Feb 2014 22:43:17 +0100 Subject: [PATCH 01/28] Issue #713 - 64 custom functions instead of 32. 8chars only filenames in PlayTrack function --- companion/src/eeprominterface.h | 2 +- companion/src/firmwares/opentx/opentxeeprom.cpp | 6 ++++-- companion/src/firmwares/opentx/opentxinterface.cpp | 4 ++-- radio/src/eeprom_conversions.cpp | 6 +++--- radio/src/myeeprom.h | 6 +++--- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 60f99b41a..14dc0d7ac 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -74,7 +74,7 @@ const uint8_t modn12x3[4][4]= { #define C9X_MAX_ENCODERS 2 #define C9X_NUM_CHNOUT 32 // number of real output channels #define C9X_NUM_CSW 32 // number of custom switches -#define C9X_MAX_CUSTOM_FUNCTIONS 32 // number of functions assigned to switches +#define C9X_MAX_CUSTOM_FUNCTIONS 64 // number of functions assigned to switches #define C9X_NUM_MODULES 2 #define STK_RUD 1 diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 92b5c4b3e..c078e6009 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -20,7 +20,7 @@ #define MAX_CHANNELS(board, version) (IS_ARM(board) ? 32 : 16) #define MAX_EXPOS(board, version) (IS_ARM(board) ? ((IS_TARANIS(board) && version >= 216) ? 64 : 32) : (IS_DBLRAM(board, version) ? 16 : 14)) #define MAX_CUSTOM_SWITCHES(board, version) (IS_ARM(board) ? 32 : (IS_DBLEEPROM(board, version) ? 15 : 12)) -#define MAX_CUSTOM_FUNCTIONS(board, version) (IS_ARM(board) ? 32 : (IS_DBLEEPROM(board, version) ? 24 : 16)) +#define MAX_CUSTOM_FUNCTIONS(board, version) (IS_ARM(board) ? (version >= 216 ? 64 : 32) : (IS_DBLEEPROM(board, version) ? 24 : 16)) #define MAX_CURVES(board, version) (IS_ARM(board) ? ((IS_TARANIS(board) && version >= 216) ? 32 : 16) : O9X_MAX_CURVES) #define MAX_GVARS(board, version) ((IS_ARM(board) && version >= 216) ? 9 : 5) @@ -1424,7 +1424,9 @@ class ArmCustomFunctionField: public TransformedField { internalField.Append(new SwitchField<8>(fn.swtch, board, version)); internalField.Append(new ConversionField< UnsignedField<8> >((unsigned int &)fn.func, &functionsConversionTable, "Function", ::QObject::tr("OpenTX on this board doesn't accept this function"))); - if (IS_TARANIS(board)) + if (IS_TARANIS(board) && version >= 216) + internalField.Append(new CharField<8>(_param, false)); + else if (IS_TARANIS(board)) internalField.Append(new CharField<10>(_param, false)); else internalField.Append(new CharField<6>(_param, false)); diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index 16dbfeca9..d61ef76f6 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -521,7 +521,7 @@ int Open9xInterface::getCapability(const Capability capability) return (IS_TARANIS(board) ? 22 : 9); case CustomFunctions: if (IS_ARM(board)) - return 32; + return 64; else if (board==BOARD_GRUVIN9X||board==BOARD_M128) return 24; else @@ -554,7 +554,7 @@ int Open9xInterface::getCapability(const Capability capability) case VoicesAsNumbers: return (IS_ARM(board) ? 0 : 1); case VoicesMaxLength: - return (IS_ARM(board) ? (IS_TARANIS(board) ? 10 : 6) : 0); + return (IS_ARM(board) ? (IS_TARANIS(board) ? 8 : 6) : 0); case MultiLangVoice: return (IS_ARM(board) ? 1 : 0); case SoundPitch: diff --git a/radio/src/eeprom_conversions.cpp b/radio/src/eeprom_conversions.cpp index 8a0e6bac9..6e1a5924b 100644 --- a/radio/src/eeprom_conversions.cpp +++ b/radio/src/eeprom_conversions.cpp @@ -144,7 +144,7 @@ PACK(typedef struct { int8_t swtch; uint8_t func; PACK(union { - char name[LEN_CFN_NAME]; + char name[10]; struct { int16_t val; int16_t ext1; @@ -193,7 +193,7 @@ PACK(typedef struct { int8_t points[NUM_POINTS]; LogicalSwitchData_v215 customSw[NUM_CSW]; - CustomFnData_v215 funcSw[NUM_CFN]; + CustomFnData_v215 funcSw[32]; SwashRingData swashR; PhaseData_v215 phaseData[MAX_PHASES]; @@ -575,7 +575,7 @@ void ConvertModel_215_to_216(ModelData &model) } if (fn.func == FUNC_PLAY_TRACK || fn.func == FUNC_BACKGND_MUSIC) { - memcpy(fn.play.name, oldModel.funcSw[i].param.name, LEN_CFN_NAME); + memcpy(fn.play.name, oldModel.funcSw[i].param.name, 8); } else { fn.all.val = oldModel.funcSw[i].param.composite.val; diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index fed0158f4..0f2e0076b 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -74,7 +74,7 @@ #define MAX_MIXERS 64 #define MAX_EXPOS 64 #define NUM_CSW 32 // number of custom switches - #define NUM_CFN 32 // number of functions assigned to switches + #define NUM_CFN 64 // number of functions assigned to switches #define MAX_SCRIPTS 3 #define MAX_INPUTS 32 #elif defined(CPUARM) @@ -84,7 +84,7 @@ #define MAX_MIXERS 64 #define MAX_EXPOS 32 #define NUM_CSW 32 // number of custom switches - #define NUM_CFN 32 // number of functions assigned to switches + #define NUM_CFN 64 // number of functions assigned to switches #elif defined(CPUM2560) || defined(CPUM2561) #define MAX_MODELS 30 #define NUM_CHNOUT 16 // number of real output channels CH1-CH16 @@ -806,7 +806,7 @@ enum AdjustGvarFunctionParam { #if defined(CPUARM) #if defined(PCBTARANIS) - #define LEN_CFN_NAME 10 + #define LEN_CFN_NAME 8 #else #define LEN_CFN_NAME 6 #endif From e38a4d320f4e7e2378563ebafaa9cac0e8336a76 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 19 Feb 2014 10:41:03 +0100 Subject: [PATCH 02/28] Issue #713 - Automatic Switch Audio Files (part 1) --- radio/src/audio_arm.cpp | 219 +++++++++++++++++---------- radio/src/audio_arm.h | 32 ++-- radio/src/eeprom_raw.cpp | 2 +- radio/src/eeprom_rlc.cpp | 2 +- radio/src/opentx.h | 3 +- radio/src/simpgmspace.cpp | 7 +- radio/src/targets/sky9x/diskio.cpp | 4 +- radio/src/targets/taranis/diskio.cpp | 2 +- 8 files changed, 166 insertions(+), 105 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 5d2fb1be9..ea4af817c 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -117,132 +117,190 @@ const char * audioFilenames[] = { }; uint64_t sdAvailableSystemAudioFiles = 0; -uint8_t sdAvailablePhaseAudioFiles[MAX_PHASES] = { 0 }; -uint8_t sdAvailableMixerAudioFiles[MAX_MIXERS] = { 0 }; +uint32_t sdAvailablePhaseAudioFiles = 0; +uint32_t sdAvailableSwitchAudioFiles = 0; +uint64_t sdAvailableLogicalSwitchAudioFiles = 0; -void refreshSystemAudioFiles() +#define MASK_SYSTEM_AUDIO_FILE(index) ((uint64_t)1 << index) +#define MASK_PHASE_AUDIO_FILE(index, event) ((uint32_t)1 << (2*index+event)) +#define MASK_SWITCH_AUDIO_FILE(index) ((uint32_t)1 << index) +#define MASK_LOGICAL_SWITCH_AUDIO_FILE(index, event) ((uint64_t)1 << (2*index+event)) + +bool isFileAvailable(const char * filename) { FILINFO info; -#if _USE_LFN TCHAR lfn[_MAX_LFN + 1]; info.lfname = lfn; info.lfsize = sizeof(lfn); -#endif + return f_stat(filename, &info) == FR_OK; +} - char filename[32] = SYSTEM_SOUNDS_PATH "/"; +void getSystemAudioFile(char * filename, int index) +{ + strcpy(filename, SYSTEM_SOUNDS_PATH "/"); strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); + strcpy(filename+sizeof(SYSTEM_SOUNDS_PATH), audioFilenames[index]); + strcat(filename+sizeof(SYSTEM_SOUNDS_PATH), SOUNDS_EXT); +} + +void referenceSystemAudioFiles() +{ + char filename[AUDIO_FILENAME_MAXLEN+1]; + uint64_t availableAudioFiles = 0; assert(sizeof(audioFilenames)==AU_FRSKY_FIRST*sizeof(char *)); assert(sizeof(sdAvailableSystemAudioFiles)*8 >= AU_FRSKY_FIRST); - uint64_t availableAudioFiles = 0; - - for (uint32_t i=0; iid, 2); - - if (sdMounted()) { - char *buf = strcat_modelname(&filename[sizeof(SOUNDS_PATH)], g_eeGeneral.currModel); - *buf++ = '/'; + char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); + *str++ = '/'; + char * tmp = strcat_phasename(str, index); + strcpy(tmp, suffixes[event]); + strcat(tmp, SOUNDS_EXT); +} - for (uint32_t i=0; iid, 2); + char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); + *str++ = '/'; + int len = STR_VSWITCHES[0]; + strncpy(str, &STR_VSWITCHES[1+len*index], len); + str += len-1; + if (*str == '\300') { + strcpy(str, "-up"); + str += 3; + } + else if (*str == '-') { + strcpy(str, "-mid"); + str += 4; + } + else if (*str == '\301') { + strcpy(str, "-down"); + str += 5; + } + else { + str += 1; + } + strcat(str, SOUNDS_EXT); +} + +void getLogicalSwitchAudioFile(char * filename, int index, unsigned int event) +{ + strcpy(filename, SOUNDS_PATH "/"); + strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); + char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); + *str++ = '/'; + int len = STR_VSWITCHES[0]; + strncpy(str, &STR_VSWITCHES[1+len*(index+SWSRC_FIRST_CSW-1)], len); + str += len; + strcpy(str, suffixes[event]); + strcat(str, SOUNDS_EXT); +} + +void referenceModelAudioFiles() +{ + char filename[AUDIO_FILENAME_MAXLEN+1]; + + { + // Phases Audio Files -[on|off].wav + uint32_t mask = 0; + for (int i=0; i-[up|mid|down].wav + uint32_t mask = 0; + for (int i=0; i-[on|off].wav + uint64_t mask = 0; + for (int i=0; i> 24); uint8_t index = (i >> 16) & 0xFF; uint8_t event = i & 0xFF; #if 0 - printf("isAudioFileAvailable(%08x)\n", i); fflush(stdout); + printf("isAudioFileReferenced(%08x)\n", i); fflush(stdout); #endif if (category == SYSTEM_AUDIO_CATEGORY) { - if (sdAvailableSystemAudioFiles & ((uint64_t)1 << event)) { - strcpy(filename, SYSTEM_SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - strcpy(filename+sizeof(SYSTEM_SOUNDS_PATH), audioFilenames[i]); - strcat(filename+sizeof(SYSTEM_SOUNDS_PATH), SOUNDS_EXT); + if (sdAvailableSystemAudioFiles & MASK_SYSTEM_AUDIO_FILE(index)) { + getSystemAudioFile(filename, index); return true; } } else if (category == PHASE_AUDIO_CATEGORY) { - if (sdAvailablePhaseAudioFiles[index] & ((uint32_t)1 << event)) { - strcpy(filename, SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); - *str++ = '/'; - char * tmp = strcat_phasename(str, index); - if (tmp != str) { - strcpy(tmp, suffixes[event]); - strcat(tmp, SOUNDS_EXT); - return true; - } + if (sdAvailablePhaseAudioFiles & MASK_PHASE_AUDIO_FILE(index, event)) { + getPhaseAudioFile(filename, index, event); + return true; } } - else if (category == MIXER_AUDIO_CATEGORY) { - if (sdAvailableMixerAudioFiles[index] & ((uint32_t)1 << event)) { - strcpy(filename, SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); - *str++ = '/'; - char * tmp = strcat_mixername(str, index); - if (tmp != str) { - strcpy(tmp, suffixes[event]); - strcat(tmp, SOUNDS_EXT); - return true; - } + else if (category == SWITCH_AUDIO_CATEGORY) { + if (sdAvailableSwitchAudioFiles & MASK_SWITCH_AUDIO_FILE(index)) { + getSwitchAudioFile(filename, index); + return true; + } + } + else if (category == LOGICAL_SWITCH_AUDIO_CATEGORY) { + if (sdAvailableLogicalSwitchAudioFiles & MASK_LOGICAL_SWITCH_AUDIO_FILE(index, event)) { + getLogicalSwitchAudioFile(filename, index, event); + return true; } } return false; } #else -#define isAudioFileAvailable(i, f) false +#define isAudioFileReferenced(i, f) false #endif +// TODO should be generated and in flash rather than in ram int16_t alawTable[256]; int16_t ulawTable[256]; @@ -757,10 +815,6 @@ void AudioQueue::reset() void audioEvent(uint8_t e, uint16_t f) { -#if defined(SDCARD) - char filename[AUDIO_FILENAME_MAXLEN+1]; -#endif - #if defined(HAPTIC) haptic.event(e); //do this before audio to help sync timings #endif @@ -773,7 +827,8 @@ void audioEvent(uint8_t e, uint16_t f) if (g_eeGeneral.beepMode>0 || (g_eeGeneral.beepMode==0 && e>=AU_TRIM_MOVE) || (g_eeGeneral.beepMode>=-1 && e<=AU_ERROR)) { #if defined(SDCARD) - if (e < AU_FRSKY_FIRST && isAudioFileAvailable(e, filename)) { + char filename[AUDIO_FILENAME_MAXLEN+1]; + if (e < AU_FRSKY_FIRST && isAudioFileReferenced(e, filename)) { audioQueue.playFile(filename); } else diff --git a/radio/src/audio_arm.h b/radio/src/audio_arm.h index 9b45187b0..b96808426 100644 --- a/radio/src/audio_arm.h +++ b/radio/src/audio_arm.h @@ -277,16 +277,21 @@ void audioStart(); #define AUDIO_HEARTBEAT() -#define SYSTEM_AUDIO_CATEGORY 0 -#define MODEL_AUDIO_CATEGORY 1 -#define PHASE_AUDIO_CATEGORY 2 -#define MIXER_AUDIO_CATEGORY 3 +enum AutomaticPromptsCategories { + SYSTEM_AUDIO_CATEGORY, + MODEL_AUDIO_CATEGORY, + PHASE_AUDIO_CATEGORY, + SWITCH_AUDIO_CATEGORY, + LOGICAL_SWITCH_AUDIO_CATEGORY, +}; -#define AUDIO_EVENT_OFF 0 -#define AUDIO_EVENT_ON 1 -#define AUDIO_EVENT_BG 2 +enum AutomaticPromptsEvents { + AUDIO_EVENT_OFF, + AUDIO_EVENT_ON, + AUDIO_EVENT_MID, +}; -extern void pushPrompt(uint16_t prompt, uint8_t id=0); +void pushPrompt(uint16_t prompt, uint8_t id=0); #define I18N_PLAY_FUNCTION(lng, x, ...) void lng ## _ ## x(__VA_ARGS__, uint8_t id) #define PLAY_FUNCTION(x, ...) void x(__VA_ARGS__, uint8_t id) @@ -300,15 +305,16 @@ extern 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 (isAudioFileAvailable((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 (isAudioFileAvailable((PHASE_AUDIO_CATEGORY << 24) + (phase << 16) + AUDIO_EVENT_ON, filename)) audioQueue.playFile(filename); } while (0) + #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) #else #define PLAY_PHASE_OFF(phase) #define PLAY_PHASE_ON(phase) #endif -extern void refreshSystemAudioFiles(); -extern void refreshModelAudioFiles(); -extern bool isAudioFileAvailable(uint32_t i, char * filename); +void referenceSystemAudioFiles(); +void referenceModelAudioFiles(); + +bool isAudioFileReferenced(uint32_t i, char * filename/*at least AUDIO_FILENAME_MAXLEN+1 long*/); #endif diff --git a/radio/src/eeprom_raw.cpp b/radio/src/eeprom_raw.cpp index 718fe3558..5050f7cbb 100644 --- a/radio/src/eeprom_raw.cpp +++ b/radio/src/eeprom_raw.cpp @@ -404,7 +404,7 @@ void eeLoadModel(uint8_t id) #endif #if defined(CPUARM) && defined(SDCARD) - refreshModelAudioFiles(); + referenceModelAudioFiles(); #endif LOAD_MODEL_BITMAP(); diff --git a/radio/src/eeprom_rlc.cpp b/radio/src/eeprom_rlc.cpp index f6f62502e..190dcdbe8 100644 --- a/radio/src/eeprom_rlc.cpp +++ b/radio/src/eeprom_rlc.cpp @@ -978,7 +978,7 @@ void eeLoadModel(uint8_t id) #endif #if defined(CPUARM) && defined(SDCARD) - refreshModelAudioFiles(); + referenceModelAudioFiles(); #endif LOAD_MODEL_BITMAP(); diff --git a/radio/src/opentx.h b/radio/src/opentx.h index dcfed29a4..b6a555b11 100644 --- a/radio/src/opentx.h +++ b/radio/src/opentx.h @@ -1616,8 +1616,7 @@ uint8_t zlen(const char *str, uint8_t size); bool zexist(const char *str, uint8_t size); char * strcat_zchar(char * dest, char * name, uint8_t size, const char *defaultName, uint8_t defaultNameSize, uint8_t defaultIdx); #define strcat_modelname(dest, idx) strcat_zchar(dest, modelHeaders[idx].name, LEN_MODEL_NAME, STR_MODEL, PSIZE(TR_MODEL), idx+1) -#define strcat_phasename(dest, idx) strcat_zchar(dest, g_model.phaseData[idx].name, LEN_FP_NAME, NULL, 0, 0) -#define strcat_mixername(dest, idx) strcat_zchar(dest, g_model.mixData[idx].name, LEN_EXPOMIX_NAME, NULL, 0, 0) +#define strcat_phasename(dest, idx) strcat_zchar(dest, g_model.phaseData[idx].name, LEN_FP_NAME, STR_FP, PSIZE(TR_FP), idx+1) #define ZLEN(s) zlen(s, sizeof(s)) #define ZEXIST(s) zexist(s, sizeof(s)) #endif diff --git a/radio/src/simpgmspace.cpp b/radio/src/simpgmspace.cpp index cd3fb4803..0b5deb589 100644 --- a/radio/src/simpgmspace.cpp +++ b/radio/src/simpgmspace.cpp @@ -300,7 +300,7 @@ void *main_thread(void *) eeReadAll(); // load general setup and selected model #if defined(CPUARM) && defined(SDCARD) - refreshSystemAudioFiles(); + referenceSystemAudioFiles(); #endif if (g_eeGeneral.backlightMode != e_backlight_mode_off) backlightOn(); // on Tx start turn the light on @@ -473,9 +473,10 @@ char *convertSimuPath(const char *path) FRESULT f_stat (const TCHAR * name, FILINFO *) { + char *path = convertSimuPath(name); struct stat tmp; - // printf("f_stat(%s)\n", path); fflush(stdout); - return stat(convertSimuPath(name), &tmp) ? FR_INVALID_NAME : FR_OK; + TRACE("f_stat(%s)", path); + return stat(path, &tmp) ? FR_INVALID_NAME : FR_OK; } FRESULT f_mount (BYTE, FATFS*) diff --git a/radio/src/targets/sky9x/diskio.cpp b/radio/src/targets/sky9x/diskio.cpp index d7f60e900..8d9ff5cfc 100644 --- a/radio/src/targets/sky9x/diskio.cpp +++ b/radio/src/targets/sky9x/diskio.cpp @@ -1014,7 +1014,7 @@ void sdMountPoll() case SD_ST_DATA: if (!usbPlugged() && f_mount(0, &g_FATFS_Obj) == FR_OK) { - refreshSystemAudioFiles(); + referenceSystemAudioFiles(); Card_state = SD_ST_MOUNTED; } break; @@ -1082,7 +1082,7 @@ void sdInit() Card_state = SD_ST_DATA; if (f_mount(0, &g_FATFS_Obj) == FR_OK) { - refreshSystemAudioFiles(); + referenceSystemAudioFiles(); Card_state = SD_ST_MOUNTED; } diff --git a/radio/src/targets/taranis/diskio.cpp b/radio/src/targets/taranis/diskio.cpp index b1d2dea7e..d9586804f 100644 --- a/radio/src/targets/taranis/diskio.cpp +++ b/radio/src/targets/taranis/diskio.cpp @@ -969,7 +969,7 @@ FIL g_telemetryFile = {0}; void sdInit() { if (f_mount(0, &g_FATFS_Obj) == FR_OK) { - refreshSystemAudioFiles(); + referenceSystemAudioFiles(); #if defined(DEBUG) f_open(&g_telemetryFile, LOGS_PATH "/sport.log", FA_OPEN_ALWAYS | FA_WRITE); From ad134173be5e70692d31bc99e0f56b4786906e1f Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 19 Feb 2014 11:30:54 +0100 Subject: [PATCH 03/28] Issue #713 - Now automatic Switch files are played --- radio/src/audio_arm.cpp | 10 ++++++ radio/src/audio_arm.h | 7 ++-- radio/src/opentx.cpp | 77 +++++++++++++++++++++++++++++++---------- 3 files changed, 73 insertions(+), 21 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index ea4af817c..0dc92a1e3 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -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 diff --git a/radio/src/audio_arm.h b/radio/src/audio_arm.h index b96808426..41a170d7b 100644 --- a/radio/src/audio_arm.h +++ b/radio/src/audio_arm.h @@ -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(); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 320421007..49d8c94ff 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -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; From 7c4214d5b9305cc9f713232cf36b63bb32b7aa94 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 19 Feb 2014 16:41:18 +0100 Subject: [PATCH 04/28] More custom scripts (7 instead of 3) --- companion/src/eeprominterface.h | 2 +- radio/src/.gitignore | 1 + radio/src/gui/menu_model.cpp | 6 +++--- radio/src/lua.cpp | 4 ++-- radio/src/myeeprom.h | 2 +- radio/src/sdcard.h | 1 - 6 files changed, 8 insertions(+), 8 deletions(-) diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 14dc0d7ac..05d871592 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -856,7 +856,7 @@ class ModuleData { void clear() { memset(this, 0, sizeof(ModuleData)); } }; -#define C9X_MAX_SCRIPTS 3 +#define C9X_MAX_SCRIPTS 7 #define C9X_MAX_SCRIPT_INPUTS 10 class ScriptData { public: diff --git a/radio/src/.gitignore b/radio/src/.gitignore index 3a16d35fe..ecb3765ab 100644 --- a/radio/src/.gitignore +++ b/radio/src/.gitignore @@ -14,3 +14,4 @@ /SOUNDS /LOGS /*.bat +/TEMPLATES diff --git a/radio/src/gui/menu_model.cpp b/radio/src/gui/menu_model.cpp index 8d271aa56..9b79f61d9 100644 --- a/radio/src/gui/menu_model.cpp +++ b/radio/src/gui/menu_model.cpp @@ -5139,8 +5139,8 @@ void onModelCustomScriptMenu(const char *result) ScriptData &sd = g_model.scriptsData[s_currIdx]; if (result == STR_UPDATE_LIST) { - if (!listSdFiles(SCRIPTS_PATH, MIXES_EXT, sizeof(sd.file), NULL)) { - POPUP_WARNING(STR_NO_BITMAPS_ON_SD); + if (!listSdFiles(SCRIPTS_PATH, SCRIPTS_EXT, sizeof(sd.file), NULL)) { + POPUP_WARNING(STR_NO_SCRIPTS_ON_SD); s_menu_flags = 0; } } @@ -5187,7 +5187,7 @@ void menuModelCustomScriptOne(uint8_t event) lcd_putsiAtt(SCRIPT_ONE_2ND_COLUMN_POS, y, STR_VCSWFUNC, 0, attr); if (attr && event==EVT_KEY_BREAK(KEY_ENTER) && !READ_ONLY()) { s_editMode = 0; - if (listSdFiles(SCRIPTS_PATH, MIXES_EXT, sizeof(sd.file), sd.file, LIST_NONE_SD_FILE)) { + if (listSdFiles(SCRIPTS_PATH, SCRIPTS_EXT, sizeof(sd.file), sd.file, LIST_NONE_SD_FILE)) { menuHandler = onModelCustomScriptMenu; } else { diff --git a/radio/src/lua.cpp b/radio/src/lua.cpp index 0e18824fa..1a2ab9e1a 100644 --- a/radio/src/lua.cpp +++ b/radio/src/lua.cpp @@ -935,10 +935,10 @@ void luaLoadModelScript(uint8_t index) sid.state = SCRIPT_NOFILE; if (ZEXIST(sd.file)) { - char filename[sizeof(SCRIPTS_PATH)+sizeof(sd.file)+sizeof(MIXES_EXT)] = SCRIPTS_PATH "/"; + char filename[sizeof(SCRIPTS_PATH)+sizeof(sd.file)+sizeof(SCRIPTS_EXT)] = SCRIPTS_PATH "/"; strncpy(filename+sizeof(SCRIPTS_PATH), sd.file, sizeof(sd.file)); filename[sizeof(SCRIPTS_PATH)+sizeof(sd.file)] = '\0'; - strcat(filename+sizeof(SCRIPTS_PATH), MIXES_EXT); + strcat(filename+sizeof(SCRIPTS_PATH), SCRIPTS_EXT); luaLoad(filename, sid); } } diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index 0f2e0076b..bcfa22a20 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -75,7 +75,7 @@ #define MAX_EXPOS 64 #define NUM_CSW 32 // number of custom switches #define NUM_CFN 64 // number of functions assigned to switches - #define MAX_SCRIPTS 3 + #define MAX_SCRIPTS 7 #define MAX_INPUTS 32 #elif defined(CPUARM) #define MAX_MODELS 60 diff --git a/radio/src/sdcard.h b/radio/src/sdcard.h index 4e6c446d7..07e528a68 100644 --- a/radio/src/sdcard.h +++ b/radio/src/sdcard.h @@ -53,7 +53,6 @@ #define SOUNDS_EXT ".wav" #define BITMAPS_EXT ".bmp" #define SCRIPTS_EXT ".lua" -#define MIXES_EXT ".mix" #define TEXT_EXT ".txt" extern FATFS g_FATFS_Obj; From b3e2e8e32128b53ee6ca39dbd9aae15070119c21 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 19 Feb 2014 16:57:02 +0100 Subject: [PATCH 05/28] Compilation failure. Thanks Jenkins! --- radio/src/gui/menus.cpp | 4 ++-- radio/src/myeeprom.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/radio/src/gui/menus.cpp b/radio/src/gui/menus.cpp index b760f3e22..dfc74980e 100644 --- a/radio/src/gui/menus.cpp +++ b/radio/src/gui/menus.cpp @@ -778,7 +778,7 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t vertpos_t realPgOfs = s_pgOfs; vertpos_t realMaxrow = maxrow; for (vertpos_t i=1; i<=maxrow; i++) { - if (MAXCOL_RAW(i) == HIDDEN_ROW) { + if (MAXCOL(i) == HIDDEN_ROW) { realMaxrow--; if (i < l_posVert) realPosVert--; @@ -790,7 +790,7 @@ bool check(check_event_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t else if (realPosVert<1+realPgOfs) realPgOfs = realPosVert-1; s_pgOfs = realPgOfs; for (vertpos_t i=1; i<=realPgOfs; i++) { - if (MAXCOL_RAW(i) == HIDDEN_ROW) { + if (MAXCOL(i) == HIDDEN_ROW) { s_pgOfs++; } } diff --git a/radio/src/myeeprom.h b/radio/src/myeeprom.h index bcfa22a20..ab7073e18 100644 --- a/radio/src/myeeprom.h +++ b/radio/src/myeeprom.h @@ -323,8 +323,9 @@ enum BacklightMode { #define SPLASH_MODE uint8_t splashMode:1; uint8_t spare4:2 #endif -#if defined(PCBTARANIS) #define POTS_POS_COUNT 6 + +#if defined(PCBTARANIS) PACK(typedef struct { uint8_t count; uint8_t steps[POTS_POS_COUNT-1]; From 82348f7e059571432e193e1b124eb8604d5c3b1a Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Wed, 19 Feb 2014 21:39:39 +0100 Subject: [PATCH 06/28] Import/Export broken in Companion (7scripts instead of 3) --- companion/src/firmwares/opentx/opentxeeprom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index c078e6009..3b3259803 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -2205,7 +2205,7 @@ Open9xModelDataNew::Open9xModelDataNew(ModelData & modelData, BoardEnum board, u } if (IS_TARANIS(board) && version >= 216) { - for (int i=0; i<3; i++) { + for (int i=0; i<7; i++) { ScriptData & script = modelData.scriptData[i]; internalField.Append(new ZCharField<10>(script.filename)); internalField.Append(new ZCharField<10>(script.name)); From 7e0a30c08fc302608d45b63813fab67507eb2639 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 16:21:04 +0100 Subject: [PATCH 07/28] Reduces the duration of SD search for automatic model files --- radio/src/audio_arm.cpp | 115 +++++++++++++++++++++++----------------- 1 file changed, 67 insertions(+), 48 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 0dc92a1e3..4161778d8 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -163,12 +163,18 @@ void referenceSystemAudioFiles() const char * suffixes[] = { "-off", "-on" }; +char * getModelPath(char * path) +{ + strcpy(path, SOUNDS_PATH "/"); + strncpy(path+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); + char * result = strcat_modelname(path+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); + *result++ = '/'; + return result; +} + void getPhaseAudioFile(char * filename, int index, unsigned int event) { - strcpy(filename, SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); - *str++ = '/'; + char * str = getModelPath(filename); char * tmp = strcat_phasename(str, index); strcpy(tmp, suffixes[event]); strcat(tmp, SOUNDS_EXT); @@ -176,10 +182,7 @@ void getPhaseAudioFile(char * filename, int index, unsigned int event) void getSwitchAudioFile(char * filename, int index) { - strcpy(filename, SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); - *str++ = '/'; + char * str = getModelPath(filename); int len = STR_VSWITCHES[0]; strncpy(str, &STR_VSWITCHES[1+len*index], len); str += len-1; @@ -203,10 +206,7 @@ void getSwitchAudioFile(char * filename, int index) void getLogicalSwitchAudioFile(char * filename, int index, unsigned int event) { - strcpy(filename, SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - char *str = strcat_modelname(filename+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); - *str++ = '/'; + char * str = getModelPath(filename); int len = STR_VSWITCHES[0]; strncpy(str, &STR_VSWITCHES[1+len*(index+SWSRC_FIRST_CSW-1)], len); str += len; @@ -216,46 +216,65 @@ void getLogicalSwitchAudioFile(char * filename, int index, unsigned int event) void referenceModelAudioFiles() { - char filename[AUDIO_FILENAME_MAXLEN+1]; + char path[AUDIO_FILENAME_MAXLEN+1]; + FILINFO fno; + DIR dir; + char *fn; /* This function is assuming non-Unicode cfg. */ + TCHAR lfn[_MAX_LFN + 1]; + fno.lfname = lfn; + fno.lfsize = sizeof(lfn); - { - // Phases Audio Files -[on|off].wav - uint32_t mask = 0; - for (int i=0; i-[on|off].wav + for (int i=0; i-[up|mid|down].wav + for (int i=0; i-[on|off].wav + for (int i=0; i-[up|mid|down].wav - uint32_t mask = 0; - for (int i=0; i-[on|off].wav - uint64_t mask = 0; - for (int i=0; i Date: Thu, 20 Feb 2014 16:57:36 +0100 Subject: [PATCH 08/28] All alerts are TADA :) --- radio/src/audio_arm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 4161778d8..7942b6e5f 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -289,7 +289,7 @@ bool isAudioFileReferenced(uint32_t i, char * filename) #endif if (category == SYSTEM_AUDIO_CATEGORY) { - if (sdAvailableSystemAudioFiles & MASK_SYSTEM_AUDIO_FILE(index)) { + if (sdAvailableSystemAudioFiles & MASK_SYSTEM_AUDIO_FILE(event)) { getSystemAudioFile(filename, index); return true; } From 444fc8571044f1f1500c1f85eabe5f7251db85ef Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 16:57:36 +0100 Subject: [PATCH 09/28] All alerts are TADA :) --- radio/src/audio_arm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 4161778d8..1b95e8281 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -267,7 +267,7 @@ void referenceModelAudioFiles() for (int i=0; i Date: Thu, 20 Feb 2014 18:00:14 +0100 Subject: [PATCH 10/28] Again the TADA on all alerts --- radio/src/audio_arm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index eb87d20b9..2f6636203 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -290,7 +290,7 @@ bool isAudioFileReferenced(uint32_t i, char * filename) if (category == SYSTEM_AUDIO_CATEGORY) { if (sdAvailableSystemAudioFiles & MASK_SYSTEM_AUDIO_FILE(event)) { - getSystemAudioFile(filename, index); + getSystemAudioFile(filename, event); return true; } } From a91bfbba9e6f28ed95671ac8d119afa2a0e0a3bd Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 18:15:24 +0100 Subject: [PATCH 11/28] Bug in SD audio parse --- radio/src/audio_arm.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 2f6636203..977774357 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -169,6 +169,7 @@ char * getModelPath(char * path) strncpy(path+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); char * result = strcat_modelname(path+sizeof(SOUNDS_PATH), g_eeGeneral.currModel); *result++ = '/'; + *result = '\0'; return result; } @@ -229,6 +230,7 @@ void referenceModelAudioFiles() sdAvailableLogicalSwitchAudioFiles = 0; char * filename = getModelPath(path); +// TODO au cas ou ... *(filename-1) = '\0'; FRESULT res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { From 91bec1e4d967a96927a97cfd987e1ac11de91a7c Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 19:07:39 +0100 Subject: [PATCH 12/28] Now it works. No hashed sounds at startup. --- radio/src/audio_arm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 977774357..7f1d92d52 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -230,7 +230,7 @@ void referenceModelAudioFiles() sdAvailableLogicalSwitchAudioFiles = 0; char * filename = getModelPath(path); -// TODO au cas ou ... *(filename-1) = '\0'; + *(filename-1) = '\0'; FRESULT res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { From 65e6814b2851a7fd809529832f4a94c8eabd7426 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 19:25:08 +0100 Subject: [PATCH 13/28] Switches positions not played at startup --- radio/src/opentx.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 49d8c94ff..a086d8764 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1323,7 +1323,7 @@ uint32_t switchesPos = 0; tmr10ms_t potsLastposStart[NUM_XPOTS]; uint8_t potsPos[NUM_XPOTS]; -uint32_t check2PosSwitchPosition(EnumKeys sw) +uint32_t check2PosSwitchPosition(EnumKeys sw, bool play) { uint32_t result; uint32_t index; @@ -1335,7 +1335,7 @@ uint32_t check2PosSwitchPosition(EnumKeys sw) result = (1 << index); - if (!(switchesPos & result)) { + if (play && !(switchesPos & result)) { PLAY_SWITCH_MOVED(index); } @@ -1343,7 +1343,7 @@ uint32_t check2PosSwitchPosition(EnumKeys sw) } #define DELAY_SWITCH_3POS 10/*100ms*/ -uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw) +uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw, bool play) { uint32_t result; uint32_t index; @@ -1371,17 +1371,17 @@ uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw) result = (switchesPos & (0x7 << (sw - SW_SA0))); } - if (!(switchesPos & result)) { + if (play && !(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) +#define CHECK_2POS(sw) newPos |= check2PosSwitchPosition(sw ## 0, play) +#define CHECK_3POS(idx, sw) newPos |= check3PosSwitchPosition(idx, sw ## 0, play) -void getSwitchesPosition() +void getSwitchesPosition(bool play) { uint32_t newPos = 0; CHECK_3POS(0, SW_SA); @@ -1415,7 +1415,7 @@ void getSwitchesPosition() #define SWITCH_POSITION(sw) (switchesPos & (1<<(sw))) #define POT_POSITION(sw) ((potsPos[(sw)/POTS_POS_COUNT] & 0x0f) == ((sw) % POTS_POS_COUNT)) #else -#define getSwitchesPosition() +#define getSwitchesPosition(...) #define SWITCH_POSITION(idx) switchState((EnumKeys)(SW_BASE+(idx))) #endif @@ -3903,17 +3903,25 @@ void doMixerCalculations() PORTH |= 0x40; // PORTH:6 LOW->HIGH signals start of mixer interrupt #endif - static tmr10ms_t lastTMR; + static tmr10ms_t lastTMR = 0; tmr10ms_t tmr10ms = get_tmr10ms(); - uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); // handle tick10ms overrun - //@@@ open.20.fsguruh: correct overflow handling costs a lot of code; happens only each 11 min; + uint8_t tick10ms = (tmr10ms >= lastTMR ? tmr10ms - lastTMR : 1); + // handle tick10ms overrun + // correct overflow handling costs a lot of code; happens only each 11 min; // therefore forget the exact calculation and use only 1 instead; good compromise + +#if !defined(CPUARM) lastTMR = tmr10ms; +#endif getADC(); - getSwitchesPosition(); + getSwitchesPosition(lastTMR != 0); + +#if defined(CPUARM) + lastTMR = tmr10ms; +#endif #if defined(PCBSKY9X) && !defined(REVA) && !defined(SIMU) Current_analogue = (Current_analogue*31 + s_anaFilt[8] ) >> 5 ; From e5f336fba1c3f775fc5919cfee5c51f56955082c Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 19:33:09 +0100 Subject: [PATCH 14/28] Indentation --- radio/src/opentx.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index a086d8764..ff8a7c1d8 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2419,8 +2419,8 @@ void checkSwitches() case 1: lcd_putc(60+i*(5*FW)+2*FW+2, 6*FH-2, g_model.potPosition[i] > (getValue(MIXSRC_FIRST_POT+i) >> 3) ? 126 : 127); break; - case 2: - case 3: + case 2: + case 3: lcd_putc(60+i*(5*FW)+2*FW+2, 6*FH-2, g_model.potPosition[i] > (getValue(MIXSRC_FIRST_POT+i) >> 3) ? '\300' : '\301'); break; } @@ -2438,11 +2438,11 @@ void checkSwitches() for (uint8_t i=0; i0?(i+3):(states&0x3)+1), attr); + attr = (states & (1 << (i+1))) == (switches_states & (1 << (i+1))) ? 0 : INVERS; + if (!(g_model.nSwToWarn & (1<0?(i+3):(states&0x3)+1), attr); x += 3*FW+FW/2; } #endif From f2f9579b77763026c815042bd6ab7e2d00819a46 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 20 Feb 2014 19:51:32 +0100 Subject: [PATCH 15/28] 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); + } } } } From bb774648ff594238bb85cb9ddbde9375f5c147a7 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 12:16:05 +0100 Subject: [PATCH 16/28] P25 and P26 automatic prompts were not played --- radio/src/audio_arm.cpp | 4 ++-- radio/src/opentx.cpp | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 7f1d92d52..6a6d84010 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -118,12 +118,12 @@ const char * audioFilenames[] = { uint64_t sdAvailableSystemAudioFiles = 0; uint32_t sdAvailablePhaseAudioFiles = 0; -uint32_t sdAvailableSwitchAudioFiles = 0; +uint64_t sdAvailableSwitchAudioFiles = 0; uint64_t sdAvailableLogicalSwitchAudioFiles = 0; #define MASK_SYSTEM_AUDIO_FILE(index) ((uint64_t)1 << index) #define MASK_PHASE_AUDIO_FILE(index, event) ((uint32_t)1 << (2*index+event)) -#define MASK_SWITCH_AUDIO_FILE(index) ((uint32_t)1 << index) +#define MASK_SWITCH_AUDIO_FILE(index) ((uint64_t)1 << index) #define MASK_LOGICAL_SWITCH_AUDIO_FILE(index, event) ((uint64_t)1 << (2*index+event)) bool isFileAvailable(const char * filename) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 7955f57b4..7b5a609de 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1309,7 +1309,6 @@ getvalue_t getValue(uint8_t i) volatile GETSWITCH_RECURSIVE_TYPE s_last_switch_used = 0; volatile GETSWITCH_RECURSIVE_TYPE s_last_switch_value = 0; -/* recursive function. stack as of today (16/03/2012) grows by 8bytes at each call, which is ok! */ #if defined(CPUARM) uint32_t cswDelays[NUM_CSW]; @@ -1425,6 +1424,8 @@ void getSwitchesPosition(bool play) int16_t csLastValue[NUM_CSW]; #define CS_LAST_VALUE_INIT -32768 + +/* recursive function. stack as of today (16/03/2012) grows by 8bytes at each call, which is ok! */ bool getSwitch(int8_t swtch) { bool result; From 5dbf2063f81665acf39148528627765348b9e702 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 14:47:38 +0100 Subject: [PATCH 17/28] 6-pos and 3-pos switches shouldn't be played at startup now --- radio/src/opentx.cpp | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 0f84855d8..c35f84ccb 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1327,7 +1327,7 @@ uint32_t switchesPos = 0; tmr10ms_t potsLastposStart[NUM_XPOTS]; uint8_t potsPos[NUM_XPOTS]; -uint32_t check2PosSwitchPosition(EnumKeys sw, bool play) +uint32_t check2PosSwitchPosition(EnumKeys sw, bool startup) { uint32_t result; uint32_t index; @@ -1339,7 +1339,7 @@ uint32_t check2PosSwitchPosition(EnumKeys sw, bool play) result = (1 << index); - if (play && !(switchesPos & result)) { + if (!startup && !(switchesPos & result)) { PLAY_SWITCH_MOVED(index); } @@ -1347,7 +1347,7 @@ uint32_t check2PosSwitchPosition(EnumKeys sw, bool play) } #define DELAY_SWITCH_3POS 10/*100ms*/ -uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw, bool play) +uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw, bool startup) { uint32_t result; uint32_t index; @@ -1362,7 +1362,7 @@ uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw, bool play) 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)) { + else if (startup || (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; @@ -1375,17 +1375,17 @@ uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw, bool play) result = (switchesPos & (0x7 << (sw - SW_SA0))); } - if (play && !(switchesPos & result)) { + if (!startup && !(switchesPos & result)) { PLAY_SWITCH_MOVED(index); } return result; } -#define CHECK_2POS(sw) newPos |= check2PosSwitchPosition(sw ## 0, play) -#define CHECK_3POS(idx, sw) newPos |= check3PosSwitchPosition(idx, sw ## 0, play) +#define CHECK_2POS(sw) newPos |= check2PosSwitchPosition(sw ## 0, startup) +#define CHECK_3POS(idx, sw) newPos |= check3PosSwitchPosition(idx, sw ## 0, startup) -void getSwitchesPosition(bool play) +void getSwitchesPosition(bool startup) { uint32_t newPos = 0; CHECK_3POS(0, SW_SA); @@ -1409,10 +1409,10 @@ void getSwitchesPosition(bool play) potsLastposStart[i] = get_tmr10ms(); potsPos[i] = (pos << 4) | previousStoredPos; } - else if ((tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { + else if (startup || (tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { potsLastposStart[i] = 0; potsPos[i] = (pos << 4) | pos; - if (play && previousStoredPos != pos) { + if (!startup && previousStoredPos != pos) { PLAY_SWITCH_MOVED(SWSRC_LAST_SWITCH+i*POTS_POS_COUNT+pos); } } @@ -2460,14 +2460,15 @@ void checkSwitches() } } uint8_t potMode = g_model.nPotsToWarn >> 6; - if(potMode) { + if (potMode) { perOut(e_perout_mode_normal, 0); bad_pots = 0; - for (uint8_t i=0; i> 3)) > 2)) { - warn = true; - bad_pots |= (1<> 3)) > 2)) { + warn = true; + bad_pots |= (1<> (i*2)]; @@ -4018,7 +4019,7 @@ void doMixerCalculations() getADC(); - getSwitchesPosition(lastTMR != 0); + getSwitchesPosition(lastTMR == 0); #if defined(CPUARM) lastTMR = tmr10ms; From 095bb38c0375476d7397445a85df1ec0cbca075e Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 15:18:05 +0100 Subject: [PATCH 18/28] Now logical switches automatic prompts --- radio/src/audio_arm.cpp | 4 +++- radio/src/audio_arm.h | 13 ++++++++++--- radio/src/opentx.cpp | 23 +++++++++++++++-------- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 6a6d84010..686c000f3 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -318,10 +318,12 @@ bool isAudioFileReferenced(uint32_t i, char * filename) return false; } +tmr10ms_t timeAutomaticPromptsSilence = 0; + 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)) { + if ((get_tmr10ms()-timeAutomaticPromptsSilence > 10) && isAudioFileReferenced((category << 24) + (index << 16) + event, filename)) { audioQueue.playFile(filename); } } diff --git a/radio/src/audio_arm.h b/radio/src/audio_arm.h index 8c67fad5e..3f5ee974c 100644 --- a/radio/src/audio_arm.h +++ b/radio/src/audio_arm.h @@ -305,14 +305,21 @@ void pushPrompt(uint16_t prompt, uint8_t id=0); #define AUDIO_RESET() audioQueue.reset() #if defined(SDCARD) + extern tmr10ms_t timeAutomaticPromptsSilence; 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) + #define PLAY_LOGICAL_SWITCH_OFF(sw) playModelEvent(LOGICAL_SWITCH_AUDIO_CATEGORY, sw, AUDIO_EVENT_OFF) + #define PLAY_LOGICAL_SWITCH_ON(sw) playModelEvent(LOGICAL_SWITCH_AUDIO_CATEGORY, sw, AUDIO_EVENT_ON) + #define SKIP_AUTOMATIC_PROMPTS() timeAutomaticPromptsSilence = get_tmr10ms() #else #define PLAY_PHASE_OFF(phase) #define PLAY_PHASE_ON(phase) #define PLAY_SWITCH_MOVED(sw) + #define PLAY_LOGICAL_SWITCH_OFF(sw) + #define PLAY_LOGICAL_SWITCH_ON(sw) + #define SKIP_AUTOMATIC_PROMPTS() #endif void referenceSystemAudioFiles(); diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index c35f84ccb..2cb2b37a8 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1327,7 +1327,7 @@ uint32_t switchesPos = 0; tmr10ms_t potsLastposStart[NUM_XPOTS]; uint8_t potsPos[NUM_XPOTS]; -uint32_t check2PosSwitchPosition(EnumKeys sw, bool startup) +uint32_t check2PosSwitchPosition(EnumKeys sw) { uint32_t result; uint32_t index; @@ -1339,7 +1339,7 @@ uint32_t check2PosSwitchPosition(EnumKeys sw, bool startup) result = (1 << index); - if (!startup && !(switchesPos & result)) { + if (!(switchesPos & result)) { PLAY_SWITCH_MOVED(index); } @@ -1375,14 +1375,14 @@ uint32_t check3PosSwitchPosition(uint8_t idx, EnumKeys sw, bool startup) result = (switchesPos & (0x7 << (sw - SW_SA0))); } - if (!startup && !(switchesPos & result)) { + if (!(switchesPos & result)) { PLAY_SWITCH_MOVED(index); } return result; } -#define CHECK_2POS(sw) newPos |= check2PosSwitchPosition(sw ## 0, startup) +#define CHECK_2POS(sw) newPos |= check2PosSwitchPosition(sw ## 0) #define CHECK_3POS(idx, sw) newPos |= check3PosSwitchPosition(idx, sw ## 0, startup) void getSwitchesPosition(bool startup) @@ -1412,7 +1412,7 @@ void getSwitchesPosition(bool startup) else if (startup || (tmr10ms_t)(get_tmr10ms() - potsLastposStart[i]) > DELAY_SWITCH_3POS) { potsLastposStart[i] = 0; potsPos[i] = (pos << 4) | pos; - if (!startup && previousStoredPos != pos) { + if (previousStoredPos != pos) { PLAY_SWITCH_MOVED(SWSRC_LAST_SWITCH+i*POTS_POS_COUNT+pos); } } @@ -1650,10 +1650,14 @@ bool getSwitch(int8_t swtch) } #endif - if (result) + if (result) { + PLAY_LOGICAL_SWITCH_ON(cs_idx); s_last_switch_value |= mask; - else + } + else { + PLAY_LOGICAL_SWITCH_OFF(cs_idx); s_last_switch_value &= ~mask; + } } } @@ -2998,11 +3002,14 @@ void resetAll() #if defined(FRSKY) resetTelemetry(); #endif - for (uint8_t i=0; i Date: Fri, 21 Feb 2014 15:54:53 +0100 Subject: [PATCH 19/28] Compilation was broken --- radio/src/audio_avr.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/radio/src/audio_avr.h b/radio/src/audio_avr.h index 6302c13f4..691305655 100644 --- a/radio/src/audio_avr.h +++ b/radio/src/audio_avr.h @@ -157,5 +157,9 @@ void audioDefevent(uint8_t e); #define PLAY_PHASE_OFF(phase) #define PLAY_PHASE_ON(phase) +#define PLAY_SWITCH_MOVED(sw) +#define PLAY_LOGICAL_SWITCH_OFF(sw) +#define PLAY_LOGICAL_SWITCH_ON(sw) +#define SKIP_AUTOMATIC_PROMPTS() #endif From 5f560e8d1b2815267f118be59c9269ed42357d66 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 15:57:00 +0100 Subject: [PATCH 20/28] No more parsing of all system sounds. Automatic prompts silent after alerts --- radio/src/audio_arm.cpp | 66 +++++++++++++++++++++++++++++++---------- radio/src/buzzer.h | 4 +++ radio/src/opentx.cpp | 2 ++ radio/src/sdcard.h | 2 +- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 686c000f3..671547add 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -135,26 +135,63 @@ bool isFileAvailable(const char * filename) return f_stat(filename, &info) == FR_OK; } +char * getAudioPath(char * path) +{ + strcpy(path, SOUNDS_PATH "/"); + strncpy(path+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); + return path + sizeof(SOUNDS_PATH); +} + +char * getSystemAudioPath(char * path) +{ + char * str = getAudioPath(path); + strcpy(path, SYSTEM_SUBDIR "/"); + return str + sizeof(SYSTEM_SUBDIR); +} + void getSystemAudioFile(char * filename, int index) { - strcpy(filename, SYSTEM_SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - strcpy(filename+sizeof(SYSTEM_SOUNDS_PATH), audioFilenames[index]); - strcat(filename+sizeof(SYSTEM_SOUNDS_PATH), SOUNDS_EXT); + char * str = getAudioPath(filename); + strcpy(str, audioFilenames[index]); + strcat(str, SOUNDS_EXT); } void referenceSystemAudioFiles() { - char filename[AUDIO_FILENAME_MAXLEN+1]; + char path[AUDIO_FILENAME_MAXLEN+1]; + FILINFO fno; + DIR dir; + char *fn; /* This function is assuming non-Unicode cfg. */ + TCHAR lfn[_MAX_LFN + 1]; + fno.lfname = lfn; + fno.lfsize = sizeof(lfn); + uint64_t availableAudioFiles = 0; assert(sizeof(audioFilenames)==AU_FRSKY_FIRST*sizeof(char *)); assert(sizeof(sdAvailableSystemAudioFiles)*8 >= AU_FRSKY_FIRST); - for (int i=0; iid, 2); - + char filename[AUDIO_FILENAME_MAXLEN+1]; + char * str = getSystemAudioPath(filename); + strcpy(str, "0000" SOUNDS_EXT); for (int8_t i=3; i>=0; i--) { - filename[sizeof(SYSTEM_SOUNDS_PATH)+i] = '0' + (prompt%10); + str[i] = '0' + (prompt%10); prompt /= 10; } - audioQueue.playFile(filename, 0, id); - #endif } diff --git a/radio/src/buzzer.h b/radio/src/buzzer.h index cbb4d5717..6d901bbbb 100644 --- a/radio/src/buzzer.h +++ b/radio/src/buzzer.h @@ -102,6 +102,10 @@ void beep(uint8_t val); #define PLAY_PHASE_OFF(phase) #define PLAY_PHASE_ON(phase) + #define PLAY_SWITCH_MOVED(sw) + #define PLAY_LOGICAL_SWITCH_OFF(sw) + #define PLAY_LOGICAL_SWITCH_ON(sw) + #define SKIP_AUTOMATIC_PROMPTS() #endif #if !defined(CPUARM) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 2cb2b37a8..44cdcf50a 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2347,6 +2347,8 @@ void checkAll() #endif clearKeyEvents(); + + SKIP_AUTOMATIC_PROMPTS(); } #if defined(MODULE_ALWAYS_SEND_PULSES) diff --git a/radio/src/sdcard.h b/radio/src/sdcard.h index 07e528a68..ccbad5fa6 100644 --- a/radio/src/sdcard.h +++ b/radio/src/sdcard.h @@ -44,7 +44,7 @@ #define LOGS_PATH ROOT_PATH "LOGS" // no trailing slash = important #define SOUNDS_PATH ROOT_PATH "SOUNDS/en" // no trailing slash = important #define SOUNDS_PATH_LNG_OFS (sizeof(SOUNDS_PATH)-3) -#define SYSTEM_SOUNDS_PATH SOUNDS_PATH "/SYSTEM" // no trailing slash = important +#define SYSTEM_SUBDIR "SYSTEM" // no trailing slash = important #define BITMAPS_PATH ROOT_PATH "BMP" #define SCRIPTS_PATH ROOT_PATH "SCRIPTS" From 03451730396f901983e0c2db891f5f5cdac5c88a Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 15:57:00 +0100 Subject: [PATCH 21/28] No more parsing of all system sounds. Automatic prompts silent after alerts --- radio/src/audio_arm.cpp | 66 +++++++++++++++++++++++++++++++---------- radio/src/buzzer.h | 4 +++ radio/src/opentx.cpp | 2 ++ radio/src/sdcard.h | 2 +- 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 686c000f3..b1229f1cc 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -135,26 +135,63 @@ bool isFileAvailable(const char * filename) return f_stat(filename, &info) == FR_OK; } +char * getAudioPath(char * path) +{ + strcpy(path, SOUNDS_PATH "/"); + strncpy(path+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); + return path + sizeof(SOUNDS_PATH); +} + +char * getSystemAudioPath(char * path) +{ + char * str = getAudioPath(path); + strcpy(str, SYSTEM_SUBDIR "/"); + return str + sizeof(SYSTEM_SUBDIR); +} + void getSystemAudioFile(char * filename, int index) { - strcpy(filename, SYSTEM_SOUNDS_PATH "/"); - strncpy(filename+SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - strcpy(filename+sizeof(SYSTEM_SOUNDS_PATH), audioFilenames[index]); - strcat(filename+sizeof(SYSTEM_SOUNDS_PATH), SOUNDS_EXT); + char * str = getAudioPath(filename); + strcpy(str, audioFilenames[index]); + strcat(str, SOUNDS_EXT); } void referenceSystemAudioFiles() { - char filename[AUDIO_FILENAME_MAXLEN+1]; + char path[AUDIO_FILENAME_MAXLEN+1]; + FILINFO fno; + DIR dir; + char *fn; /* This function is assuming non-Unicode cfg. */ + TCHAR lfn[_MAX_LFN + 1]; + fno.lfname = lfn; + fno.lfsize = sizeof(lfn); + uint64_t availableAudioFiles = 0; assert(sizeof(audioFilenames)==AU_FRSKY_FIRST*sizeof(char *)); assert(sizeof(sdAvailableSystemAudioFiles)*8 >= AU_FRSKY_FIRST); - for (int i=0; iid, 2); - + char filename[AUDIO_FILENAME_MAXLEN+1]; + char * str = getSystemAudioPath(filename); + strcpy(str, "0000" SOUNDS_EXT); for (int8_t i=3; i>=0; i--) { - filename[sizeof(SYSTEM_SOUNDS_PATH)+i] = '0' + (prompt%10); + str[i] = '0' + (prompt%10); prompt /= 10; } - audioQueue.playFile(filename, 0, id); - #endif } diff --git a/radio/src/buzzer.h b/radio/src/buzzer.h index cbb4d5717..6d901bbbb 100644 --- a/radio/src/buzzer.h +++ b/radio/src/buzzer.h @@ -102,6 +102,10 @@ void beep(uint8_t val); #define PLAY_PHASE_OFF(phase) #define PLAY_PHASE_ON(phase) + #define PLAY_SWITCH_MOVED(sw) + #define PLAY_LOGICAL_SWITCH_OFF(sw) + #define PLAY_LOGICAL_SWITCH_ON(sw) + #define SKIP_AUTOMATIC_PROMPTS() #endif #if !defined(CPUARM) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 2cb2b37a8..44cdcf50a 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -2347,6 +2347,8 @@ void checkAll() #endif clearKeyEvents(); + + SKIP_AUTOMATIC_PROMPTS(); } #if defined(MODULE_ALWAYS_SEND_PULSES) diff --git a/radio/src/sdcard.h b/radio/src/sdcard.h index 07e528a68..ccbad5fa6 100644 --- a/radio/src/sdcard.h +++ b/radio/src/sdcard.h @@ -44,7 +44,7 @@ #define LOGS_PATH ROOT_PATH "LOGS" // no trailing slash = important #define SOUNDS_PATH ROOT_PATH "SOUNDS/en" // no trailing slash = important #define SOUNDS_PATH_LNG_OFS (sizeof(SOUNDS_PATH)-3) -#define SYSTEM_SOUNDS_PATH SOUNDS_PATH "/SYSTEM" // no trailing slash = important +#define SYSTEM_SUBDIR "SYSTEM" // no trailing slash = important #define BITMAPS_PATH ROOT_PATH "BMP" #define SCRIPTS_PATH ROOT_PATH "SCRIPTS" From d02912577b22462c491ddd78d8f328d84e3577c0 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 16:51:51 +0100 Subject: [PATCH 22/28] Merge problem :( --- radio/src/audio_arm.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 678d173e0..b1229f1cc 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -145,11 +145,7 @@ char * getAudioPath(char * path) char * getSystemAudioPath(char * path) { char * str = getAudioPath(path); -<<<<<<< HEAD strcpy(str, SYSTEM_SUBDIR "/"); -======= - strcpy(path, SYSTEM_SUBDIR "/"); ->>>>>>> 5f560e8d1b2815267f118be59c9269ed42357d66 return str + sizeof(SYSTEM_SUBDIR); } From a7bba2a578b1f6a42b44169d3988b7feeeaa12d9 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 16:55:43 +0100 Subject: [PATCH 23/28] Logical switches automatic prompts bugfix --- radio/src/opentx.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 44cdcf50a..6ce62a3f6 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1651,11 +1651,11 @@ bool getSwitch(int8_t swtch) #endif if (result) { - PLAY_LOGICAL_SWITCH_ON(cs_idx); + if (!(s_last_switch_value&mask)) PLAY_LOGICAL_SWITCH_ON(cs_idx); s_last_switch_value |= mask; } else { - PLAY_LOGICAL_SWITCH_OFF(cs_idx); + if (s_last_switch_value&mask) PLAY_LOGICAL_SWITCH_OFF(cs_idx); s_last_switch_value &= ~mask; } } @@ -3405,7 +3405,7 @@ void evalFunctions() if (active || IS_PLAY_BOTH_FUNC(CFN_FUNC(sd))) { - switch(CFN_FUNC(sd)) { + switch (CFN_FUNC(sd)) { case FUNC_SAFETY_CHANNEL: safetyCh[CFN_CH_INDEX(sd)] = CFN_PARAM(sd); From 9b5b22658a392759e3a9863225b6b22e502ba262 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 17:09:03 +0100 Subject: [PATCH 24/28] Cosmetics --- radio/src/opentx.cpp | 43 +++++++------------------------------------ 1 file changed, 7 insertions(+), 36 deletions(-) diff --git a/radio/src/opentx.cpp b/radio/src/opentx.cpp index 6ce62a3f6..4d49662cf 100644 --- a/radio/src/opentx.cpp +++ b/radio/src/opentx.cpp @@ -1688,53 +1688,24 @@ int8_t getMovedSwitch() } } #else - // saves about 50 bytes flash // return delivers 1 to 3 for ID1 to ID3 // 4..8 for all other switches if changed to true // -4..-8 for all other switches if changed to false // 9 for Trainer switch if changed to true; Change to false is ignored - - swstate_t mask=0x80; + swstate_t mask = 0x80; for (uint8_t i=NUM_PSWITCH; i>1; i--) { bool prev; - // mask= (1<<(i-2)); - prev=(switches_states & mask); + prev = (switches_states & mask); // don't use getSwitch here to always get the proper value, even getSwitch manipulates - // bool next = getSwitch(i); - bool next = switchState((EnumKeys)(SW_BASE+i-1)); - if (prev!=next) { - if (((i3)) || next==true) - result = next ? i : -i; - if ((i<=3) && (result==0)) result=1; - switches_states ^= mask; - } - mask>>=1; - } //endfor - -/* - for (uint8_t i=NUM_PSWITCH; i>0; i--) { - bool prev; - swstate_t mask = 0; - if (i <= 3) { - prev = ((switches_states & 0x03) == (i-1)); - } - else { - mask = (1<<(i-2)); - prev = (switches_states & mask); - } - // don't use getSwitch here to always get the proper value, because getSwitch manipulates - // bool next = getSwitch(i); bool next = switchState((EnumKeys)(SW_BASE+i-1)); if (prev != next) { - if (i!=NUM_PSWITCH || next==true) + if (((i3)) || next==true) result = next ? i : -i; - if (mask) - switches_states ^= mask; - else { - switches_states = (switches_states & 0xFC) | (i-1); - } + if (i<=3 && result==0) result = 1; + switches_states ^= mask; } - } //endfor */ + mask >>= 1; + } #endif if ((tmr10ms_t)(get_tmr10ms() - s_move_last_time) > 10) From 9c38236a30139eefdafd3b06ea94540e8266e2cb Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Fri, 21 Feb 2014 17:50:34 +0100 Subject: [PATCH 25/28] Another bug in system prompts referencing --- radio/src/audio_arm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index b1229f1cc..4ecc3f499 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -151,7 +151,7 @@ char * getSystemAudioPath(char * path) void getSystemAudioFile(char * filename, int index) { - char * str = getAudioPath(filename); + char * str = getSystemAudioPath(filename); strcpy(str, audioFilenames[index]); strcat(str, SOUNDS_EXT); } From 92a5429ce0b5c8c58b0d9e4bf1e124c505476242 Mon Sep 17 00:00:00 2001 From: Andre Bernet Date: Fri, 21 Feb 2014 23:22:06 +0100 Subject: [PATCH 26/28] Longer inhibition time for automatic switch prompts at power up --- radio/src/audio_arm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/radio/src/audio_arm.cpp b/radio/src/audio_arm.cpp index 4ecc3f499..8e9f4a741 100644 --- a/radio/src/audio_arm.cpp +++ b/radio/src/audio_arm.cpp @@ -360,7 +360,7 @@ tmr10ms_t timeAutomaticPromptsSilence = 0; void playModelEvent(uint8_t category, uint8_t index, uint8_t event) { char filename[AUDIO_FILENAME_MAXLEN+1]; - if ((get_tmr10ms()-timeAutomaticPromptsSilence > 10) && isAudioFileReferenced((category << 24) + (index << 16) + event, filename)) { + if ((get_tmr10ms()-timeAutomaticPromptsSilence > 50) && isAudioFileReferenced((category << 24) + (index << 16) + event, filename)) { audioQueue.playFile(filename); } } From 82e74a72e6afc6b33d3db52070e1112802bd1443 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 22 Feb 2014 11:13:42 +0100 Subject: [PATCH 27/28] Shift in sources when 7 Lua scripts allowed --- companion/src/firmwares/opentx/opentxeeprom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/companion/src/firmwares/opentx/opentxeeprom.cpp b/companion/src/firmwares/opentx/opentxeeprom.cpp index 3b3259803..ef971d41e 100644 --- a/companion/src/firmwares/opentx/opentxeeprom.cpp +++ b/companion/src/firmwares/opentx/opentxeeprom.cpp @@ -164,7 +164,7 @@ class SourcesConversionTable: public ConversionTable { if (IS_TARANIS(board) && version >= 216) { for (int i=0; i<32; i++) addConversion(RawSource(SOURCE_TYPE_VIRTUAL_INPUT, i), val++); - for (int i=0; i<3; i++) { + for (int i=0; i<7; i++) { for (int j=0; j<6; j++) { addConversion(RawSource(SOURCE_TYPE_LUA_INPUT, i*16+j), val++); } From f3b9135a09becce7d32440a9ae7351cfcbdfc876 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sat, 22 Feb 2014 12:32:28 +0100 Subject: [PATCH 28/28] Core in Custom Functions Panel --- companion/src/modeledit/customfunctions.cpp | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/companion/src/modeledit/customfunctions.cpp b/companion/src/modeledit/customfunctions.cpp index c9ba53ba5..b1805df46 100644 --- a/companion/src/modeledit/customfunctions.cpp +++ b/companion/src/modeledit/customfunctions.cpp @@ -162,7 +162,8 @@ CustomFunctionsPanel::CustomFunctionsPanel(QWidget * parent, ModelData & model, #ifdef PHONON playBT[i] = new QPushButton(this); - playBT[i]->setObjectName(QString("play_%1").arg(i)); + playBT[i]->setProperty("index", i); + playBT[i]->setProperty("state", "play"); playBT[i]->setIcon(CompanionIcon("play.png")); paramLayout->addWidget(playBT[i]); connect(playBT[i], SIGNAL(pressed()), this, SLOT(playMusic())); @@ -222,42 +223,43 @@ void CustomFunctionsPanel::mediaPlayer_state(Phonon::State newState, Phonon::Sta void CustomFunctionsPanel::playMusic() { - QPushButton *playButton = qobject_cast(sender()); - int index=playButton->objectName().mid(5,2).toInt(); - QString function=playButton->objectName().left(4); - QString path = g.profile[g.id()].sdPath(); + QPushButton * button = qobject_cast(sender()); + int index = button->property("index").toInt(); + QString function = button->property("state").toString(); + QString path = g.profile[g.id()].sdPath(); QDir qd(path); QString track; if (qd.exists()) { if (GetEepromInterface()->getCapability(VoicesAsNumbers)) { - track=path+QString("/%1.wav").arg(int(fswtchParam[index]->value()),4,10,(const QChar)'0'); + track = path + QString("/%1.wav").arg(int(fswtchParam[index]->value()), 4, 10, (const QChar)'0'); } else { path.append("/SOUNDS/"); QString lang = generalSettings.ttsLanguage; if (lang.isEmpty()) - lang="en"; + lang = "en"; path.append(lang); - if (fswtchParamArmT[index]->currentText()!="----") { - track=path+"/"+fswtchParamArmT[index]->currentText()+".wav"; + if (fswtchParamArmT[index]->currentText() != "----") { + track = path + "/" + fswtchParamArmT[index]->currentText() + ".wav"; } } QFile file(track); if (!file.exists()) { QMessageBox::critical(this, tr("Error"), tr("Unable to find sound file %1!").arg(track)); - track.clear(); + return; } #ifdef PHONON - if (function=="play" && !track.isEmpty()) { + if (function=="play") { clickObject->clear(); clickObject->setCurrentSource(Phonon::MediaSource(track)); clickObject->play(); - playBT[index]->setObjectName(QString("stop_%1").arg(index)); + playBT[index]->setProperty("state", "stop"); playBT[index]->setIcon(CompanionIcon("stop.png")); - } else { + } + else { clickObject->stop(); clickObject->clear(); - playBT[index]->setObjectName(QString("play_%1").arg(index)); + playBT[index]->setProperty("state", "play"); playBT[index]->setIcon(CompanionIcon("play.png")); } #endif