void insertExpoMix(uint8_t expo, uint8_t idx) { pauseMixerCalculations(); if (expo) { ExpoData *expo = expoAddress(idx); memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData)); memclear(expo, sizeof(ExpoData)); expo->srcRaw = (s_currCh > 4 ? MIXSRC_Rud - 1 + s_currCh : MIXSRC_Rud - 1 + channel_order(s_currCh)); expo->curve.type = CURVE_REF_EXPO; expo->mode = 3; // pos&neg expo->chn = s_currCh - 1; expo->weight = 100; } else { MixData *mix = mixAddress(idx); memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData)); memclear(mix, sizeof(MixData)); mix->destCh = s_currCh-1; mix->srcRaw = s_currCh; if (!isSourceAvailable(mix->srcRaw)) { mix->srcRaw = (s_currCh > 4 ? MIXSRC_Rud - 1 + s_currCh : MIXSRC_Rud - 1 + channel_order(s_currCh)); while (!isSourceAvailable(mix->srcRaw)) { mix->srcRaw += 1; } } mix->weight = 100; } resumeMixerCalculations(); eeDirty(EE_MODEL); }
void eeLoadModel(uint8_t id) { if (id<MAX_MODELS) { #if defined(SDCARD) closeLogs(); #endif if (pulsesStarted()) { pausePulses(); } pauseMixerCalculations(); uint32_t size = loadModel(id); #if defined(SIMU) if (sizeof(uint16_t) + sizeof(g_model) > EEPROM_ZONE_SIZE) TRACE("Model data size can't exceed %d bytes (%d bytes)", int(EEPROM_ZONE_SIZE-sizeof(uint16_t)), (int)sizeof(g_model)); if (size > 0 && size != sizeof(g_model)) TRACE("Model data read=%d bytes vs %d bytes\n", size, (int)sizeof(ModelData)); #endif if (size < EEPROM_BUFFER_SIZE) { // if not loaded a fair amount modelDefault(id) ; eeCheck(true); } AUDIO_FLUSH(); flightReset(); logicalSwitchesReset(); if (pulsesStarted()) { checkAll(); resumePulses(); } customFunctionsReset(); restoreTimers(); resumeMixerCalculations(); // TODO pulses should be started after mixer calculations ... #if defined(FRSKY) frskySendAlarms(); #endif #if defined(SDCARD) referenceModelAudioFiles(); #endif LOAD_MODEL_BITMAP(); SEND_FAILSAFE_1S(); PLAY_MODEL_NAME(); } }
void copyExpoMix(uint8_t expo, uint8_t idx) { pauseMixerCalculations(); if (expo) { ExpoData *expo = expoAddress(idx); memmove(expo+1, expo, (MAX_EXPOS-(idx+1))*sizeof(ExpoData)); } else { MixData *mix = mixAddress(idx); memmove(mix+1, mix, (MAX_MIXERS-(idx+1))*sizeof(MixData)); } resumeMixerCalculations(); eeDirty(EE_MODEL); }
void deleteExpoMix(uint8_t expo, uint8_t idx) { pauseMixerCalculations(); if (expo) { ExpoData *expo = expoAddress(idx); int input = expo->chn; memmove(expo, expo+1, (MAX_EXPOS-(idx+1))*sizeof(ExpoData)); memclear(&g_model.expoData[MAX_EXPOS-1], sizeof(ExpoData)); if (!isInputAvailable(input)) { memclear(&g_model.inputNames[input], LEN_INPUT_NAME); } } else { MixData *mix = mixAddress(idx); memmove(mix, mix+1, (MAX_MIXERS-(idx+1))*sizeof(MixData)); memclear(&g_model.mixData[MAX_MIXERS-1], sizeof(MixData)); } resumeMixerCalculations(); eeDirty(EE_MODEL); }
bool swapExpoMix(uint8_t expo, uint8_t &idx, uint8_t up) { void *x, *y; uint8_t size; int8_t tgt_idx = (up ? idx-1 : idx+1); if (expo) { x = (ExpoData *)expoAddress(idx); if (tgt_idx < 0) { if (((ExpoData *)x)->chn == 0) return false; ((ExpoData *)x)->chn--; return true; } if (tgt_idx == MAX_EXPOS) { if (((ExpoData *)x)->chn == NUM_INPUTS-1) return false; ((ExpoData *)x)->chn++; return true; } y = (ExpoData *)expoAddress(tgt_idx); if(((ExpoData *)x)->chn != ((ExpoData *)y)->chn || !EXPO_VALID((ExpoData *)y)) { if (up) { if (((ExpoData *)x)->chn>0) ((ExpoData *)x)->chn--; else return false; } else { if (((ExpoData *)x)->chn<NUM_INPUTS-1) ((ExpoData *)x)->chn++; else return false; } return true; } size = sizeof(ExpoData); } else { x = (MixData *)mixAddress(idx); if (tgt_idx < 0) { if (((MixData *)x)->destCh == 0) return false; ((MixData *)x)->destCh--; return true; } if (tgt_idx == MAX_MIXERS) { if (((MixData *)x)->destCh == NUM_CHNOUT-1) return false; ((MixData *)x)->destCh++; return true; } y = (MixData *)mixAddress(tgt_idx); uint8_t destCh = ((MixData *)x)->destCh; if(!((MixData *)y)->srcRaw || destCh != ((MixData *)y)->destCh) { if (up) { if (destCh>0) ((MixData *)x)->destCh--; else return false; } else { if (destCh<NUM_CHNOUT-1) ((MixData *)x)->destCh++; else return false; } return true; } size = sizeof(MixData); } pauseMixerCalculations(); memswap(x, y, size); resumeMixerCalculations(); idx = tgt_idx; return true; }
void eeLoadModel(uint8_t id) { if (id<MAX_MODELS) { #if defined(SDCARD) closeLogs(); #endif if (pulsesStarted()) { pausePulses(); } pauseMixerCalculations(); uint16_t size = File_system[id+1].size ; memset(&g_model, 0, sizeof(g_model)); #if defined(SIMU) if (sizeof(struct t_eeprom_header) + sizeof(g_model) > 4096) TRACE("Model data size can't exceed %d bytes (%d bytes)", int(4096-sizeof(struct t_eeprom_header)), (int)sizeof(g_model)); else if (size > 0 && size != sizeof(g_model)) TRACE("Model data read=%d bytes vs %d bytes\n", size, (int)sizeof(ModelData)); #endif if (size > sizeof(g_model)) { size = sizeof(g_model) ; } if(size < 256) { // if not loaded a fair amount modelDefault(id) ; eeCheck(true); } else { read32_eeprom_data((File_system[id+1].block_no << 12) + sizeof(struct t_eeprom_header), (uint8_t *)&g_model, size) ; } AUDIO_FLUSH(); flightReset(); logicalSwitchesReset(); if (pulsesStarted()) { checkAll(); resumePulses(); } activeFnSwitches = 0; activeFunctions = 0; memclear(lastFunctionTime, sizeof(lastFunctionTime)); restoreTimers(); resumeMixerCalculations(); // TODO pulses should be started after mixer calculations ... #if defined(FRSKY) frskySendAlarms(); #endif #if defined(CPUARM) && defined(SDCARD) referenceModelAudioFiles(); #endif LOAD_MODEL_BITMAP(); SEND_FAILSAFE_1S(); } }