From b496e1fba8a6abbfe6bee2dd18e253ba8e40e81e Mon Sep 17 00:00:00 2001 From: bsongis Date: Fri, 13 Jan 2012 17:55:23 +0000 Subject: [PATCH] Tx modes should be handled the right way Throttle trace configuration Timers updated New splash 100% CPU in alert (SIMU) RPM sensor used in custom switches --- src/Makefile | 8 -- src/eeprom_v3.h | 156 ------------------------------------ src/eeprom_v4.h | 179 ------------------------------------------ src/general_menus.cpp | 4 +- src/gruvin9x.cpp | 113 ++++++++++++++++---------- src/gruvin9x.h | 11 ++- src/lcd.cpp | 17 ++-- src/model_menus.cpp | 34 +++++++- src/myeeprom.h | 8 +- src/pers.cpp | 170 --------------------------------------- src/s9xsplash.lbm | 16 ++-- src/s9xsplash.xbm | 178 ++++++++++++++++++++--------------------- src/simpgmspace.cpp | 8 -- src/simpgmspace.h | 8 ++ 14 files changed, 230 insertions(+), 680 deletions(-) delete mode 100644 src/eeprom_v3.h delete mode 100644 src/eeprom_v4.h diff --git a/src/Makefile b/src/Makefile index b8f98eade..26a3059cd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -81,10 +81,6 @@ BATT = BANDGAP # Values = YES, NO DECIMALS = NO -# TRANSLATIONS from previous EEPROM formats -# Values = YES, NO -TRANSLATIONS = YES - # DISPLAY_USER_DATA to display on screen data from FrSky module (testing/demo purpose) # Values = YES, NO DISPLAY_USER_DATA = NO @@ -319,10 +315,6 @@ ifeq ($(DECIMALS), YES) CPPDEFS += -DDECIMALS_DISPLAYED endif -ifeq ($(TRANSLATIONS), YES) - CPPDEFS += -DTRANSLATIONS -endif - ifeq ($(HELI), YES) MODS += H CPPDEFS += -DHELI diff --git a/src/eeprom_v3.h b/src/eeprom_v3.h deleted file mode 100644 index 5eeed2f24..000000000 --- a/src/eeprom_v3.h +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Authors (alphabetical order) - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - * gruvin9x is based on code named er9x by - * Author - Erez Raviv , which is in turn - * was based on the original (and ongoing) project by Thomas Husterer, - * th9x -- http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#ifndef eepromv3_h -#define eepromv3_h - -#include - -namespace EEPROM_V3 { - - typedef struct t_TrainerMix { - uint8_t srcChn:3; //0-7 = ch1-8 - int8_t swtch:5; - int8_t studWeight:6; - uint8_t mode:2; //off,add-mode,subst-mode - } __attribute__((packed)) TrainerMix; // - - typedef struct t_TrainerData { - int16_t calib[4]; - TrainerMix mix[4]; - } __attribute__((packed)) TrainerData; - - typedef struct t_EEGeneral { - uint8_t myVers; - int16_t calibMid[7]; - int16_t calibSpanNeg[7]; - int16_t calibSpanPos[7]; - uint16_t chkSum; - uint8_t currModel; //0..15 - uint8_t contrast; - uint8_t vBatWarn; - int8_t vBatCalib; - int8_t lightSw; - TrainerData trainer; - uint8_t view; //index of subview in main scrren - // uint8_t warnOpts; //bitset for several warnings - uint8_t disableThrottleWarning:1; - uint8_t disableSwitchWarning:1; - uint8_t disableMemoryWarning:1; - uint8_t beeperVal:3; - uint8_t reserveWarning:1; - uint8_t disableAlarmWarning:1; - uint8_t stickMode; - uint8_t inactivityTimer; - uint8_t throttleReversed:1; - uint8_t minuteBeep:1; - uint8_t preBeep:1; - uint8_t flashBeep:1; - uint8_t disableSplashScreen:1; - uint8_t res1:3; - uint8_t filterInput; - uint8_t lightAutoOff; - uint8_t templateSetup; //RETA order according to chout_ar array - int8_t PPM_Multiplier; - uint8_t res[1]; - } __attribute__((packed)) EEGeneral; - - - - //eeprom modelspec - //expo[3][2][2] //[Norm/Dr][expo/weight][R/L] - - typedef struct t_ExpoData { - int8_t expo[3][2][2]; - int8_t drSw1; - int8_t drSw2; - } __attribute__((packed)) ExpoData; - - - typedef struct t_LimitData { - int8_t min; - int8_t max; - bool revert; - int16_t offset; - } __attribute__((packed)) LimitData; - - - typedef struct t_MixData { - uint8_t destCh; // 1..NUM_CHNOUT - uint8_t srcRaw; // - int8_t weight; - int8_t swtch; - uint8_t curve; //0=symmetrisch 1=no neg 2=no pos - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint8_t carryTrim:1; - uint8_t mltpx:3; // multiplex method 0=+ 1=* 2=replace - uint8_t mixWarn:4; // mixer warning - int8_t sOffset; - int8_t res; - } __attribute__((packed)) MixData; - - - typedef struct t_CSwData { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; - } __attribute__((packed)) CSwData; - - - typedef struct t_SwashRingData { // Swash Ring data - uint8_t lim; // 0 mean off 100 full deflection - uint8_t chX; // 2 channels to limit - uint8_t chY; // 2 channels to limit - } __attribute__((packed)) SwashRingData; - - typedef struct t_ModelData { - char name[10]; // 10 must be first for eeLoadModelName - uint8_t mdVers; - int8_t tmrMode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint8_t tmrDir; // 0=>Count Down, 1=>Count Up - uint16_t tmrVal; - uint8_t protocol; - int8_t ppmNCH; - int8_t thrTrim:4; // Enable Throttle Trim - int8_t thrExpo:4; // Enable Throttle Expo - int8_t trimInc; // Trim Increments - int8_t ppmDelay; - int8_t trimSw; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - uint8_t pulsePol; - char res[3]; - MixData mixData[32]; - LimitData limitData[16]; - ExpoData expoData[4]; - int8_t trim[4]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - CSwData customSw[6]; - SwashRingData swashR; - } __attribute__((packed)) ModelData; - -} - -#endif - diff --git a/src/eeprom_v4.h b/src/eeprom_v4.h deleted file mode 100644 index 817c52d93..000000000 --- a/src/eeprom_v4.h +++ /dev/null @@ -1,179 +0,0 @@ -/* - * Authors (alphabetical order) - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - * gruvin9x is based on code named er9x by - * Author - Erez Raviv , which is in turn - * was based on the original (and ongoing) project by Thomas Husterer, - * th9x -- http://code.google.com/p/th9x/ - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#ifndef eepromv4_h -#define eepromv4_h - -#include - -namespace EEPROM_V4 { - -typedef struct t_TrainerMix { - uint8_t srcChn:3; //0-7 = ch1-8 - int8_t swtch:5; - int8_t studWeight:6; - uint8_t mode:2; //off,add-mode,subst-mode -} __attribute__((packed)) TrainerMix; // - -typedef struct t_TrainerData { - int16_t calib[4]; - TrainerMix mix[4]; -} __attribute__((packed)) TrainerData; - -typedef struct t_EEGeneral { - uint8_t myVers; - int16_t calibMid[7]; - int16_t calibSpanNeg[7]; - int16_t calibSpanPos[7]; - uint16_t chkSum; - uint8_t currModel; //0..15 - uint8_t contrast; - uint8_t vBatWarn; - int8_t vBatCalib; - int8_t lightSw; - TrainerData trainer; - uint8_t view; //index of subview in main scrren - uint8_t disableThrottleWarning:1; - uint8_t disableSwitchWarning:1; - uint8_t disableMemoryWarning:1; - uint8_t beeperVal:3; - uint8_t reserveWarning:1; - uint8_t disableAlarmWarning:1; - uint8_t stickMode; - uint8_t inactivityTimer; - uint8_t throttleReversed:1; - uint8_t minuteBeep:1; - uint8_t preBeep:1; - uint8_t flashBeep:1; - uint8_t disableSplashScreen:1; - uint8_t res1:3; - uint8_t filterInput; - uint8_t lightAutoOff; - uint8_t templateSetup; //RETA order according to chout_ar array - int8_t PPM_Multiplier; - uint8_t res[1]; -} __attribute__((packed)) EEGeneral; - -//eeprom modelspec - -typedef struct t_ExpoData { - int8_t expo[3][2][2]; //[Norm/Dr][expo/weight][R/L] - int8_t drSw1; - int8_t drSw2; -} __attribute__((packed)) ExpoData; - -typedef struct t_LimitData { - int8_t min; - int8_t max; - bool revert; - int16_t offset; -} __attribute__((packed)) LimitData; - -typedef struct t_MixData { - uint8_t destCh; // 1..NUM_CHNOUT - uint8_t srcRaw; // - int8_t weight; - int8_t swtch; - uint8_t curve; //0=symmetrisch 1=no neg 2=no pos - uint8_t delayUp:4; - uint8_t delayDown:4; - uint8_t speedUp:4; // Servogeschwindigkeit aus Tabelle (10ms Cycle) - uint8_t speedDown:4; // 0 nichts - uint8_t carryTrim:1; - uint8_t mltpx:3; // multiplex method 0=+ 1=* 2=replace - uint8_t mixWarn:4; // mixer warning - int8_t sOffset; - int8_t res; -} __attribute__((packed)) MixData; - -typedef struct t_CSwData { // Custom Switches data - int8_t v1; //input - int8_t v2; //offset - uint8_t func; -} __attribute__((packed)) CSwData; - - -typedef struct t_SwashRingData { // Swash Ring data - uint8_t lim; // 0 mean off 100 full deflection - uint8_t chX; // 2 channels to limit - uint8_t chY; // 2 channels to limit -} __attribute__((packed)) SwashRingData; - -typedef struct t_SafetySwData { // Custom Switches data - int8_t swtch; - int8_t val; -} __attribute__((packed)) SafetySwData; - -typedef struct t_FrSkyChannelData { - uint8_t ratio; // 0.0 means not used, 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_value[2]; // 0.1V steps EG. 6.6 Volts = 66. 25.1V = 251, etc. - uint8_t alarms_level:4; - uint8_t alarms_greater:2; // 0=LT(<), 1=GT(>) - uint8_t type:2; // future use: 0=volts, ... -} __attribute__((packed)) FrSkyChannelData; - -typedef struct t_FrSkyData { - FrSkyChannelData channels[2]; -} __attribute__((packed)) FrSkyData; - -typedef struct t_ModelData { - char name[10]; // 10 must be first for eeLoadModelName - uint8_t mdVers; - int8_t tmrMode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw - uint8_t tmrDir:1; //0=>Count Down, 1=>Count Up - uint8_t traineron:1; // 0 disable trainer, 1 allow trainer - uint8_t spare:6; - uint16_t tmrVal; - uint8_t protocol; - int8_t ppmNCH; - int8_t thrTrim:4; // Enable Throttle Trim - int8_t thrExpo:4; // Enable Throttle Expo - int8_t trimInc; // Trim Increments - int8_t ppmDelay; - int8_t trimSw; - uint8_t beepANACenter; // 1<<0->A1.. 1<<6->A7 - uint8_t pulsePol:1; - uint8_t extendedLimits:1; - uint8_t swashInvertELE:1; - uint8_t swashInvertAIL:1; - uint8_t swashInvertCOL:1; - uint8_t swashType:3; - uint8_t swashCollectiveSource; - uint8_t swashRingValue; - char res1; - MixData mixData[32]; - LimitData limitData[16]; - ExpoData expoData[4]; - int8_t trim[4]; - int8_t curves5[8][5]; - int8_t curves9[8][9]; - CSwData customSw[12/*er9x=12, gruvin9x=6*/]; - /* er9x only */ - uint8_t a1voltRatio; //FrSky - uint8_t a2voltRatio; //FrSky - uint8_t res3; - SafetySwData safetySw[16]; - FrSkyData frsky; -} __attribute__((packed)) ModelData; - -} - -#endif diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 591f5947d..3e27d4d74 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -236,12 +236,12 @@ void menuProcSetup(uint8_t event) }subN++; if(s_pgOfs7*FH) return; lcd_putcAtt( 3*FW, y, '1'+g_eeGeneral.stickMode,sub==subN?INVERS:0); - for(uint8_t i=0; i<4; i++) putsChnRaw( (6+4*i)*FW, y,i+1,0);//sub==3?INVERS:0); + for(uint8_t i=0; i<4; i++) putsChnRaw( (6+4*i)*FW, y, CONVERT_MODE(i+1),0); if(sub==subN) CHECK_INCDEC_GENVAR(event,g_eeGeneral.stickMode,0,3); if((y+=FH)>7*FH) return; diff --git a/src/gruvin9x.cpp b/src/gruvin9x.cpp index 0a1af8fde..cf7d97f4c 100644 --- a/src/gruvin9x.cpp +++ b/src/gruvin9x.cpp @@ -56,6 +56,7 @@ bool warble = false; uint8_t heartbeat; +// TODO reduce this tab const prog_char APM modi12x3[]= "RUD ELE THR AIL " "RUD THR ELE AIL " @@ -307,6 +308,9 @@ FORCEINLINE int16_t getValue(uint8_t i) #if defined(FRSKY_HUB) || defined(WS_HOW_HIGH) else if(i CHOUT_BASE+NUM_CHNOUT+MAX_TIMERS+3) + y = (128+cs.v2) * 25; + else +#endif #if defined(FRSKY_HUB) || defined(WS_HOW_HIGH) + // ALT if (cs.v1 > CHOUT_BASE+NUM_CHNOUT+MAX_TIMERS+2) y = (128+cs.v2) * 4; else #endif + // Volts if (cs.v1 > CHOUT_BASE+NUM_CHNOUT+MAX_TIMERS) y = 128+cs.v2; else #endif + // Timers if (cs.v1 > CHOUT_BASE+NUM_CHNOUT) y = 98+cs.v2; else @@ -497,7 +510,7 @@ FORCEINLINE uint8_t keyDown() void clearKeyEvents() { #ifdef SIMU - while (keyDown() && main_thread_running); + while (keyDown() && main_thread_running) sleep(1/*ms*/); #else while (keyDown()); // loop until all keys are up #endif @@ -534,6 +547,7 @@ void doSplash() { #ifdef SIMU if (!main_thread_running) return; + sleep(1/*ms*/); #else getADC_filt(); #endif @@ -595,6 +609,7 @@ void checkTHR() { #ifdef SIMU if (!main_thread_running) return; + sleep(1/*ms*/); #else getADC_single(); #endif @@ -632,6 +647,7 @@ void checkSwitches() { #ifdef SIMU if (!main_thread_running) return; + sleep(1/*ms*/); #endif uint8_t i; @@ -675,6 +691,7 @@ void alert(const prog_char * s, bool defaults) { #ifdef SIMU if (!main_thread_running) return; + sleep(1/*ms*/); #endif if(keyDown()) return; //wait for key release @@ -925,7 +942,7 @@ void resetTimer(uint8_t idx) s_timerVal_10ms[idx] = 0 ; } -FORCEINLINE void incTimers() +FORCEINLINE void incTimers(int16_t val) { static uint8_t lastSwPos[2] = {0, 0}; static uint16_t s_cnt[2] = {0, 0}; @@ -948,14 +965,11 @@ FORCEINLINE void incTimers() s_time_cum_16[i] = 0; } - uint8_t atm = abs(tm); + uint8_t atm = (tm >= 0 ? tm : TMR_VAROFS-tm-1); // value for time described in timer->mode - // OFFABSRUsRU%ELsEL%THsTH%ALsAL%P1P1%P2P2%P3P3% - int16_t val = 0; - if (atm>1 && atm= 16) { - s_timerVal[i] ++; - s_time_cum_16[i] -= 16; - } + else if (atm==TMRMODE_THR) { + if (val) s_timerVal[i]++; + } + else if (atm==TMRMODE_THR_REL) { + if (s_cnt[i]) { + val = s_sum[i]/s_cnt[i]; + s_sum[i] -= val*s_cnt[i]; //rest + s_cnt[i] = 0; + s_time_cum_16[i] += val/2; + if (s_time_cum_16[i] >= 16) { + s_timerVal[i] ++; + s_time_cum_16[i] -= 16; } } - else if (val) { - s_timerVal[i]++; - } } - else if (atm<(TMR_VAROFS+MAX_SWITCH-1)) { - sw_toggled[i] = getSwitch((tm>0 ? tm-(TMR_VAROFS-1) : tm+(TMR_VAROFS-1)), 0); // normal switch + else if (atm==TMRMODE_THR_TRG) { + if (val || s_timerVal[i] > 0) + s_timerVal[i]++; + } + else { + if (atm<(TMR_VAROFS+MAX_SWITCH-1)) + sw_toggled[i] = getSwitch((tm>0 ? tm-(TMR_VAROFS-1) : tm+(TMR_VAROFS-1)), 0); // normal switch + if (sw_toggled[i]) + s_timerVal[i]++; } switch(s_timerState[i]) @@ -1040,12 +1059,8 @@ FORCEINLINE void incTimers() uint8_t s_traceBuf[MAXTRACE]; uint16_t s_traceWr; int8_t s_traceCnt; -FORCEINLINE void thrTrace() // called in perOut - once envery 0.01sec +FORCEINLINE void thrTrace(int16_t val) // called in perOut - once envery 0.01sec { - int16_t val = calibratedStick[CONVERT_MODE(3)-1]; // get throttle channel value - val = (g_eeGeneral.throttleReversed ? RESX-val : val+RESX); - val /= (RESX/16); // calibrate it - static uint16_t s_time_tot; static uint16_t s_time_trace; static uint8_t s_cnt_1s; @@ -1154,7 +1169,7 @@ uint8_t evalSticks(uint8_t phase) for(uint8_t i=0; i [-1024..1024] - + uint8_t ch = (i < NUM_STICKS ? CONVERT_MODE(i+1) - 1 : i); int16_t v = anaIn(i); #ifndef SIMU @@ -1167,17 +1182,17 @@ uint8_t evalSticks(uint8_t phase) if(v <= -RESX) v = -RESX; if(v >= RESX) v = RESX; - if (g_eeGeneral.throttleReversed && i==THR_STICK) + if (g_eeGeneral.throttleReversed && ch==2/*TODO THR_STICK*/) v = -v; - calibratedStick[i] = v; //for show in expo - if(!(v/16)) anaCenter |= 1<<(CONVERT_MODE((i+1))-1); + calibratedStick[ch] = v; //for show in expo + if(!(v/16)) anaCenter |= 1<mode) { uint8_t chStud = td->srcChn; int32_t vStud = (g_ppmIns[chStud]- g_eeGeneral.trainer.calib[chStud]); @@ -1191,12 +1206,12 @@ uint8_t evalSticks(uint8_t phase) } #ifdef HELI - if(d && (i==ELE_STICK || i==AIL_STICK)) + if(d && (ch==1/*TODO ELE_STICK*/ || ch==3/*TODO AIL_STICK*/)) v = int32_t(v)*g_model.swashR.value*RESX/(int32_t(d)*100); #endif } - anas[i] = v; //set values for mixer + anas[ch] = v; //set values for mixer } /* EXPOs */ @@ -1319,11 +1334,27 @@ void perOut(int16_t *chanOut, uint8_t phase) for (uint8_t i=CHOUT_BASE; i NUM_POTS) { + val = RESX + g_chans512[g_model.thrTraceSrc-NUM_POTS-1]; + } + else { + val = calibratedStick[g_model.thrTraceSrc+NUM_STICKS-1]; + } + + val /= (RESX/16); // calibrate it + + incTimers(val); + + thrTrace(val); // trace thr 0..32 (/32) } - memset(chans,0,sizeof(chans)); // All outputs to 0 + memset(chans, 0, sizeof(chans)); // All outputs to 0 //========== MIXER LOOP =============== mixWarning = 0; diff --git a/src/gruvin9x.h b/src/gruvin9x.h index 90466f612..c7125fee8 100644 --- a/src/gruvin9x.h +++ b/src/gruvin9x.h @@ -357,7 +357,10 @@ enum EnumKeys { #define CHOUT_BASE (PPM_BASE+NUM_PPM) #if defined(FRSKY) -#if defined(FRSKY_HUB) || defined(WS_HOW_HIGH) +#if defined(FRSKY_HUB) +#define NUM_TELEMETRY 4 +#define TELEMETRY_CHANNELS "AD1AD2ALTRPM" +#elif defined(WS_HOW_HIGH) #define NUM_TELEMETRY 3 #define TELEMETRY_CHANNELS "AD1AD2ALT" #else @@ -409,10 +412,6 @@ enum EnumKeys { #define HEART_TIMER2Mhz 1 #define HEART_TIMER10ms 2 -#define TMRMODE_NONE 0 -#define TMRMODE_ABS 1 -#define TMRMODE_THR 2 -#define TMRMODE_THR_REL 3 #define MAX_ALERT_TIME 60 #define PROTO_PPM 0 @@ -611,7 +610,7 @@ extern inline uint16_t get_tmr10ms() return time ; } -#define TMR_VAROFS 16 +#define TMR_VAROFS 5 void setupPulses(); diff --git a/src/lcd.cpp b/src/lcd.cpp index eab147215..0a99a09a0 100644 --- a/src/lcd.cpp +++ b/src/lcd.cpp @@ -407,7 +407,7 @@ void putsChnRaw(uint8_t x, uint8_t y, uint8_t idx, uint8_t att) if (idx==0) lcd_putsnAtt(x, y, PSTR("----"), 4, att); else if (idx<=NUM_STICKS) - lcd_putsnAtt(x, y, modi12x3+g_eeGeneral.stickMode*16+4*(idx-1), 4, att); + lcd_putsnAtt(x, y, modi12x3+4*(idx-1), 4, att); else if (idx<=NUM_STICKS+NUM_POTS+2+3) lcd_putsnAtt(x,y,PSTR("P1 P2 P3 MAX FULLCYC1CYC2CYC3")+4*(idx-5), 4, att); else if (idx<=NUM_STICKS+NUM_POTS+2+3+NUM_PPM) @@ -476,22 +476,21 @@ void putsCurve(uint8_t x, uint8_t y, uint8_t idx, uint8_t att) void putsTmrMode(uint8_t x, uint8_t y, int8_t mode, uint8_t att) { if (mode < 0) { - mode = -mode; + mode = TMR_VAROFS - mode - 1; lcd_putcAtt(x-1*FW, y, '!', att); } - - if (mode < TMR_VAROFS) { - lcd_putsnAtt(x, y, PSTR("OFFABSRUsRU%ELsEL%THsTH%ALsAL%P1 P1%P2 P2%P3 P3%")+3*mode, 3, att); + else if (mode < TMR_VAROFS) { + lcd_putsnAtt(x, y, PSTR("OFFABSTHsTH%THt")+3*mode, 3, att); return; } if (mode < TMR_VAROFS+MAX_SWITCH-1) { // normal on-off putsSwitches(x, y, mode-(TMR_VAROFS-1), att); - return; } - - putsSwitches(x, y, mode-(TMR_VAROFS+MAX_SWITCH-1-1), att); // momentary on-off - if (~att & SHRT_TM_MODE) lcd_putcAtt(x+3*FW, y, 'm', att); + else { + putsSwitches(x, y, mode-(TMR_VAROFS+MAX_SWITCH-2), att); // momentary on-off + if (~att & SHRT_TM_MODE) lcd_putcAtt(x+3*FW, y, 'm', att); + } } #ifdef FRSKY diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 851eaaed0..ea0ef0ac3 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -404,14 +404,14 @@ void menuProcModel(uint8_t event) if (s_pgOfsmode, sub==subN && m_posHorz==0 ? ((s_editMode>0) ? BLINK : INVERS) : 0); - putsTime(14*FW-3, y, timer->val, + putsTime(14*FW, y, timer->val, (sub==subN && m_posHorz==1 ? ((s_editMode>0) ? BLINK : INVERS):0), (sub==subN && m_posHorz==2 ? ((s_editMode>0) ? BLINK : INVERS):0) ); if (sub==subN && (s_editMode>0 || p1valdiff)) { uint16_t timer_val = timer->val; switch (m_posHorz) { case 0: - CHECK_INCDEC_MODELVAR(event, timer->mode, -(13+2*MAX_SWITCH),(13+2*MAX_SWITCH)); + CHECK_INCDEC_MODELVAR(event, timer->mode, -2*(MAX_PSWITCH+NUM_CSW), TMR_VAROFS-1+2*(MAX_PSWITCH+NUM_CSW)); break; case 1: { @@ -456,6 +456,16 @@ void menuProcModel(uint8_t event) if((y+=FH)>7*FH) return; }subN++; + if(s_pgOfs NUM_POTS) idx = NUM_STICKS+2+3+NUM_PPM+g_model.thrTraceSrc; + else if (g_model.thrTraceSrc > 0) idx = NUM_STICKS+g_model.thrTraceSrc; + putsChnRaw(PARAM_OFS, y, idx, (sub==subN ? INVERS:0)); + if (sub==subN) CHECK_INCDEC_MODELVAR(event, g_model.thrTraceSrc, 0, NUM_POTS+NUM_CHNOUT); + if((y+=FH)>7*FH) return; + }subN++; + if(s_pgOfs NUM_XCHNRAW-NUM_TELEMETRY+3) { + lcd_outdezAtt(20*FW, y, (128+cs.v2) * 50, m_posHorz==2 ? attr : 0); + v2_min = -128; v2_max = 127; + } + else +#endif #if defined(FRSKY_HUB) || defined(WS_HOW_HIGH) - if (cs.v1 > NUM_XCHNRAW-1) { + if (cs.v1 > NUM_XCHNRAW-NUM_TELEMETRY+2) { lcd_outdezAtt(20*FW, y, (128+cs.v2) * 4, m_posHorz==2 ? attr : 0); v2_min = -128; v2_max = 127; } @@ -1633,8 +1650,19 @@ void menuProcCustomSwitches(uint8_t event) } break; case 1: + { + int8_t v1 = cs.v1; CHECK_INCDEC_MODELVAR(event, cs.v1, v1_min, v1_max); + if (cs.v1 == CHOUT_BASE+NUM_CHNOUT+1 && v1 < cs.v1) cs.v2 = -98; +#ifdef FRSKY + if (cs.v1 == CHOUT_BASE+NUM_CHNOUT+3 && v1 < cs.v1) cs.v2 = -128; +#endif + if (cs.v1 == CHOUT_BASE+NUM_CHNOUT && v1 > cs.v1) cs.v2 = 0; +#ifdef FRSKY + if (cs.v1 == CHOUT_BASE+NUM_CHNOUT+2 && v1 > cs.v1) cs.v2 = -98; +#endif break; + } case 2: CHECK_INCDEC_MODELVAR(event, cs.v2, v2_min, v2_max); break; diff --git a/src/myeeprom.h b/src/myeeprom.h index 2c24a030a..01bd9a8e7 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -41,7 +41,7 @@ #define EEPROM_VER_r584 3 #define EEPROM_VER_r751 5 -#define EEPROM_VER 201 +#define EEPROM_VER 202 #ifndef PACK #define PACK( __Declaration__ ) __Declaration__ __attribute__((__packed__)) @@ -238,6 +238,11 @@ PACK(typedef struct t_PhaseData { #define NUM_CSW 12 // number of custom switches #define NUM_FSW 12 // number of functions assigned to switches +#define TMRMODE_NONE 0 +#define TMRMODE_ABS 1 +#define TMRMODE_THR 2 +#define TMRMODE_THR_REL 3 +#define TMRMODE_THR_TRG 4 PACK(typedef struct t_TimerData { int8_t mode; // timer trigger source -> off, abs, stk, stk%, sw/!sw, !m_sw/!m_sw uint16_t val; @@ -270,6 +275,7 @@ PACK(typedef struct t_ModelData { PhaseData phaseData[MAX_PHASES]; FrSkyData frsky; int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments + uint8_t thrTraceSrc; }) ModelData; extern EEGeneral g_eeGeneral; diff --git a/src/pers.cpp b/src/pers.cpp index 2ccd2727b..09c7a79e1 100644 --- a/src/pers.cpp +++ b/src/pers.cpp @@ -19,11 +19,6 @@ * */ -#ifdef TRANSLATIONS -#include "eeprom_v4.h" -#include "eeprom_v3.h" -#endif - #include "gruvin9x.h" #include "templates.h" @@ -49,166 +44,6 @@ void generalDefault() g_eeGeneral.chkSum = (0x200 * 7) + (0x180 * 5); } -#ifdef TRANSLATIONS -uint8_t Translate() -{ - if (g_eeGeneral.myVers == 0) { - if (theFile.readRlc1((uint8_t*)&g_eeGeneral, 1) != 1) - return 0; - theFile.openRlc(FILE_GENERAL); - } - - if (g_eeGeneral.myVers == EEPROM_VER_r584 || (g_eeGeneral.myVers >= EEPROM_ER9X_MIN && g_eeGeneral.myVers <= EEPROM_ER9X_MAX)) { - alert(g_eeGeneral.myVers == EEPROM_VER_r584 ? PSTR("EEprom Data v3") : PSTR("EEprom Data Er9x"), true); - message(PSTR("EEPROM Converting")); - theFile.readRlc1((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)); - memset(&g_eeGeneral.frskyRssiAlarms, 0, sizeof(g_eeGeneral.frskyRssiAlarms)); - if (g_eeGeneral.myVers == EEPROM_VER_r584) { - // previous version had only 6 custom switches, OFF and ON values have to be shifted 6 - if (g_eeGeneral.lightSw == MAX_SWITCH-6) - g_eeGeneral.lightSw += 6; - if (g_eeGeneral.lightSw == -MAX_SWITCH+6) - g_eeGeneral.lightSw -= 6; - } - else { - g_eeGeneral.inactivityTimer += 10; - } - g_eeGeneral.view = 0; // will not translate the view index - EEPROM_V3::EEGeneral *old = (EEPROM_V3::EEGeneral *)&g_eeGeneral; - g_eeGeneral.disableMemoryWarning = old->disableMemoryWarning; - g_eeGeneral.switchWarning = old->disableSwitchWarning ? 0 : -1; - for (uint8_t i=0; i<4; i++) { - g_eeGeneral.trainer.mix[i].srcChn = old->trainer.mix[i].srcChn; - g_eeGeneral.trainer.mix[i].mode = old->trainer.mix[i].mode; - g_eeGeneral.trainer.mix[i].studWeight = old->trainer.mix[i].studWeight * 13 / 4; - } - for (uint8_t id=0; id 0) { - EEPROM_V4::ModelData *v4 = (EEPROM_V4::ModelData *)&g_model; - EEPROM_V3::ModelData *v3 = (EEPROM_V3::ModelData *)&g_model; - SwashRingData swashR; - swashR.invertELE = v4->swashInvertELE; - swashR.invertAIL = v4->swashInvertAIL; - swashR.invertCOL = v4->swashInvertCOL; - swashR.type = v4->swashType; - swashR.collectiveSource = v4->swashCollectiveSource; - swashR.value = v4->swashRingValue; - int8_t trims[4]; - memcpy(&trims[0], &v3->trim[0], 4); - int8_t trimSw = v3->trimSw; - for (uint8_t i=0; i<10; i++) - g_model.name[i] = char2idx(g_model.name[i]); - g_model.timer1.mode = v3->tmrMode; - g_model.timer1.val = v3->tmrVal; - g_model.protocol = v3->protocol; - g_model.ppmNCH = v3->ppmNCH; - g_model.thrTrim = v3->thrTrim; - g_model.trimInc = v3->trimInc; - g_model.pulsePol = v3->pulsePol; - if (g_eeGeneral.myVers == EEPROM_VER_r584) - g_model.extendedLimits = 0; - else - g_model.extendedLimits = v4->extendedLimits; - g_model.extendedTrims = 0; - g_model.spare2 = 0; - g_model.ppmDelay = v3->ppmDelay; - g_model.beepANACenter = v3->beepANACenter; - g_model.timer2.mode = 0; - g_model.timer2.val = 0; - for (uint8_t i=0; imixData[i], sizeof(MixData)); // MixData size changed! - g_model.mixData[i].mixWarn = g_model.mixData[i].phase; - g_model.mixData[i].phase = 0; - if (g_eeGeneral.myVers == EEPROM_VER_r584 && g_model.mixData[i].srcRaw > MIX_FULL) { - g_model.mixData[i].srcRaw += 3; /* because of [CYC1:CYC3] inserted after MIX_FULL */ - } - } - assert((char *)&g_model.limitData[0] < (char *)&v3->limitData[0]); - memmove(&g_model.limitData[0], &v3->limitData[0], sizeof(LimitData)*NUM_CHNOUT); - assert((char *)&g_model.expoData[0] < (char *)v3->expoData); - EEPROM_V4::ExpoData expo4[4]; - memcpy(&expo4[0], &v4->expoData[0], sizeof(expo4)); - memset(&g_model.expoData[0], 0, sizeof(expo4)); - // expos conversion - uint8_t e = 0; - for (uint8_t ch = 0; ch < 4 && e < MAX_EXPOS; ch++) { - for (uint8_t dr = 0, pos = 0; dr < 3 && e < MAX_EXPOS; dr++, pos++) { - if ((dr == 0 && !expo4[ch].drSw1) || (dr == 1 && !expo4[ch].drSw2)) - dr = 2; - if (dr == 2 && !expo4[ch].expo[0][0][0] && !expo4[ch].expo[0][0][1] && !expo4[ch].expo[0][1][0] && !expo4[ch].expo[0][1][1]) - break; - g_model.expoData[e].swtch = (dr == 0 ? -expo4[ch].drSw1 : (dr == 1 ? -expo4[ch].drSw2 : 0)); - g_model.expoData[e].chn = ch; - g_model.expoData[e].expo = expo4[ch].expo[pos][0][0]; - g_model.expoData[e].weight = 100 + expo4[ch].expo[pos][1][0]; - if (expo4[ch].expo[pos][0][0] == expo4[ch].expo[pos][0][1] && expo4[ch].expo[pos][1][0] == expo4[ch].expo[pos][1][1]) { - g_model.expoData[e++].mode = 3; - } - else { - g_model.expoData[e].mode = 2; - if (e < MAX_EXPOS - 1) { - g_model.expoData[e + 1].swtch = g_model.expoData[e].swtch; - g_model.expoData[++e].chn = ch; - g_model.expoData[e].mode = 1; - g_model.expoData[e].expo = expo4[ch].expo[pos][0][1]; - g_model.expoData[e++].weight = 100 + expo4[ch].expo[pos][1][1]; - } - } - } - } - assert((char *)&g_model.curves5[0][0] < (char *)&v3->curves5[0][0]); - memmove(&g_model.curves5[0][0], &v3->curves5[0][0], 5*MAX_CURVE5); - assert((char *)&g_model.curves9[0][0] < (char *)&v3->curves9[0][0]); - memmove(&g_model.curves9[0][0], &v3->curves9[0][0], 9*MAX_CURVE9); - if (g_eeGeneral.myVers == EEPROM_VER_r584) { - memmove(&g_model.customSw[0], &v3->customSw[0], sizeof(CustomSwData)*6); - memset(&g_model.customSw[6], 0, sizeof(CustomSwData)*6); - memset(&g_model.safetySw[0], 0, sizeof(SafetySwData)*NUM_CHNOUT + sizeof(SwashRingData) + sizeof(FrSkyData)); - } - else { - assert((char *)&g_model.customSw[0] < (char *)&v4->customSw[0]); - memmove(&g_model.customSw[0], &v4->customSw[0], sizeof(CustomSwData)*12); - assert((char *)&g_model.safetySw[0] < (char *)&v4->safetySw[0]); - memmove(&g_model.safetySw[0], &v4->safetySw[0], sizeof(SafetySwData)*NUM_CHNOUT); - memcpy(&g_model.swashR, &swashR, sizeof(SwashRingData)); - for (uint8_t i=0; i<2; i++) { - // TODO this conversion is bad - // assert(&g_model.frsky.channels[i].ratio < &v4->frsky.channels[i].ratio); - g_model.frsky.channels[i].ratio = v4->frsky.channels[i].ratio; - g_model.frsky.channels[i].type = v4->frsky.channels[i].type; - g_model.frsky.channels[i].offset = 0; - g_model.frsky.channels[i].alarms_value[0] = v4->frsky.channels[i].alarms_value[0]; - g_model.frsky.channels[i].alarms_value[1] = v4->frsky.channels[i].alarms_value[1]; - g_model.frsky.channels[i].alarms_level = v4->frsky.channels[i].alarms_level; - g_model.frsky.channels[i].alarms_greater = v4->frsky.channels[i].alarms_greater; - g_model.frsky.channels[i].barMin = 0; - g_model.frsky.channels[i].barMax = 0; - } - } - memset(&g_model.phaseData[0], 0, sizeof(g_model.phaseData)); - memset(&g_model.funcSw[0], 0, sizeof(g_model.funcSw)); - if (trimSw) { - g_model.funcSw[0].swtch = trimSw; - g_model.funcSw[0].func = FUNC_INSTANT_TRIM; - } - for (uint8_t i=0; i -#define sleep(x) Sleep(x) -#else -#include -#define sleep(x) usleep(1000*x) -#endif - #include #include "simpgmspace.h" #include "lcd.h" diff --git a/src/simpgmspace.h b/src/simpgmspace.h index 786fdb670..4434fa470 100644 --- a/src/simpgmspace.h +++ b/src/simpgmspace.h @@ -22,6 +22,14 @@ #ifndef simpgmspace_h #define simpgmspace_h +#ifndef __GNUC__ +#include +#define sleep(x) Sleep(x) +#else +#include +#define sleep(x) usleep(1000*x) +#endif + #ifdef SIMU_EXCEPTIONS extern char * main_thread_error; #include