From 6ed367834b2b42130e118e598341bc04f3dd6fec Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 26 Jul 2012 10:31:33 +0000 Subject: [PATCH] Possibility to remove completely the CURVES Menu and calculations (CURVES=NO Makefile option) --- src/Makefile | 8 ++++++++ src/model_menus.cpp | 29 +++++++++++++++++++++++------ src/myeeprom.h | 6 ++++-- src/open9x.cpp | 12 ++++++++++++ src/open9x.h | 6 ++++++ util/tts.py | 9 +++++++-- 6 files changed, 60 insertions(+), 10 deletions(-) diff --git a/src/Makefile b/src/Makefile index c120ce9eb..e9c19d195 100644 --- a/src/Makefile +++ b/src/Makefile @@ -144,6 +144,10 @@ DEBUG = NO # Values = YES, NO FLIGHT_PHASES = YES +# Curves +# Values = YES, NO +CURVES = YES + # Customizable Curves # Values = YES, NO XCURVES = YES @@ -285,6 +289,10 @@ ifeq ($(FLIGHT_PHASES), YES) CPPDEFS += -DFLIGHT_PHASES endif +ifeq ($(CURVES), YES) + CPPDEFS += -DCURVES +endif + ifeq ($(XCURVES), YES) CPPDEFS += -DXCURVES endif diff --git a/src/model_menus.cpp b/src/model_menus.cpp index c82770798..85219c441 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -49,7 +49,9 @@ enum EnumTabModel { e_ExposAll, e_MixAll, e_Limits, +#ifdef CURVES e_CurvesAll, +#endif e_CustomSwitches, e_FunctionSwitches, #ifdef FRSKY @@ -94,7 +96,9 @@ const MenuFuncP_PROGMEM menuTabModel[] PROGMEM = { menuProcExposAll, menuProcMixAll, menuProcLimits, +#ifdef CURVES menuProcCurvesAll, +#endif menuProcCustomSwitches, menuProcFunctionSwitches, #ifdef FRSKY @@ -1062,8 +1066,6 @@ void menuProcHeli(uint8_t event) } #endif -static uint8_t s_curveChan; - typedef int16_t (*FnFuncP) (int16_t x); int16_t expoFn(int16_t x) @@ -1075,10 +1077,13 @@ int16_t expoFn(int16_t x) return anas[ed->chn]; } +#if defined(CURVES) +static uint8_t s_curveChan; int16_t curveFn(int16_t x) { return intpol(x, s_curveChan); } +#endif void DrawCurve(FnFuncP fn) { @@ -1092,9 +1097,10 @@ void DrawCurve(FnFuncP fn) } } +#if defined(CURVES) bool moveCurve(uint8_t index, int8_t shift, int8_t custom=0) { - if (g_model.curves[MAX_CURVES-1] + shift > NUM_POINTS-5*MAX_CURVES) { + if (g_model.curves[MAX_CURVES-1] + shift > NUM_POINTS-CURVES_OFFSET_SHIFT(MAX_CURVES)) { AUDIO_WARNING2(); return false; } @@ -1106,7 +1112,7 @@ bool moveCurve(uint8_t index, int8_t shift, int8_t custom=0) } int8_t *nextCrv = curveaddress(index+1); - memmove(nextCrv+shift, nextCrv, 5*(MAX_CURVES-index-1)+g_model.curves[MAX_CURVES-1]); + memmove(nextCrv+shift, nextCrv, CURVES_OFFSET_SHIFT(MAX_CURVES-index-1)+g_model.curves[MAX_CURVES-1]); if (shift < 0) memclear(&g_model.points[NUM_POINTS-1] + shift, -shift); while (indexexpo, attr|INFLIGHT(ed->expo)); if (attr) CHECK_INFLIGHT_INCDEC_MODELVAR(event, ed->expo, -100, 100, 0, STR_DREXPO); break; +#ifdef CURVES case EXPO_FIELD_CURVE: putsCurve(6*FW+5, y, ed->curve, attr); if (attr) { @@ -1493,6 +1503,7 @@ void menuProcExpoOne(uint8_t event) } } break; +#endif #ifdef FLIGHT_PHASES case EXPO_FIELD_FLIGHT_PHASE: { @@ -1543,9 +1554,11 @@ enum MixFields { MIX_FIELD_DIFFERENTIAL, MIX_FIELD_OFFSET, MIX_FIELD_TRIM, +#if defined(CURVES) MIX_FIELD_CURVE, +#endif MIX_FIELD_SWITCH, -#ifdef FLIGHT_PHASES +#if defined(FLIGHT_PHASES) MIX_FIELD_FLIGHT_PHASE, #endif MIX_FIELD_WARNING, @@ -1614,6 +1627,7 @@ void menuProcMixOne(uint8_t event) if (attr) md2->carryTrim = -checkIncDecModel(event, carryTrim, not_stick ? TRIM_ON : -TRIM_OFF, -TRIM_AIL); break; } +#if defined(CURVES) case MIX_FIELD_CURVE: lcd_putsLeft(y, STR_CURVES); putsCurve(MIXES_2ND_COLUMN, y, md2->curve, attr); @@ -1623,12 +1637,13 @@ void menuProcMixOne(uint8_t event) pushMenu(menuProcCurveOne); } break; +#endif case MIX_FIELD_SWITCH: lcd_putsLeft(y, STR_SWITCH); putsSwitches(MIXES_2ND_COLUMN, y,md2->swtch,attr); if(attr) CHECK_INCDEC_MODELSWITCH( event, md2->swtch, -MAX_SWITCH, MAX_SWITCH); break; -#ifdef FLIGHT_PHASES +#if defined(FLIGHT_PHASES) case MIX_FIELD_FLIGHT_PHASE: lcd_putsLeft(y, STR_FPHASE); putsFlightPhase(MIXES_2ND_COLUMN, y, md2->phase, attr); @@ -2140,6 +2155,7 @@ void menuProcLimits(uint8_t _event) } } +#if defined(CURVES) void menuProcCurvesAll(uint8_t event) { SIMPLE_MENU(STR_MENUCURVES, menuTabModel, e_CurvesAll, 1+MAX_CURVES); @@ -2173,6 +2189,7 @@ void menuProcCurvesAll(uint8_t event) s_curveChan = sub; DrawCurve(curveFn); } +#endif #if defined(PCBARM) enum CustomSwitchFields { diff --git a/src/myeeprom.h b/src/myeeprom.h index 5d94f51ef..59d29f55a 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -592,10 +592,12 @@ PACK(typedef struct t_PhaseData { #if defined(PCBARM) #define MAX_CURVES 16 -#define NUM_POINTS 256 +#define NUM_POINTS 512 +#define CURVTYPE uint16_t #else #define MAX_CURVES 8 #define NUM_POINTS (112-MAX_CURVES) +#define CURVTYPE int8_t #endif #define MIN_POINTS 3 @@ -676,7 +678,7 @@ PACK(typedef struct t_ModelData { LimitData limitData[NUM_CHNOUT]; ExpoData expoData[MAX_EXPOS]; - int8_t curves[MAX_CURVES]; + CURVTYPE curves[MAX_CURVES]; int8_t points[NUM_POINTS]; CustomSwData customSw[NUM_CSW]; diff --git a/src/open9x.cpp b/src/open9x.cpp index 5b592ee43..8a1e3f4be 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -162,10 +162,18 @@ LimitData *limitaddress(uint8_t idx) return &g_model.limitData[idx]; } +#if defined(PCBARM) +int8_t *curveaddress(uint8_t idx) +{ + return &g_model.points[idx==0 ? 0 : g_model.curves[idx-1]]; +} +#else int8_t *curveaddress(uint8_t idx) { return &g_model.points[idx==0 ? 0 : 5*idx+g_model.curves[idx-1]]; } +#endif + CurveInfo curveinfo(uint8_t idx) { CurveInfo result; @@ -299,6 +307,7 @@ int16_t intpol(int16_t x, uint8_t idx) // -100, -75, -50, -25, 0 ,25 ,50, 75, 10 return erg / 25; // 100*D5/RESX; } +#if defined(CURVES) int16_t applyCurve(int16_t x, int8_t idx) { /* already tried to have only one return at the end */ @@ -326,6 +335,9 @@ int16_t applyCurve(int16_t x, int8_t idx) } return intpol(x, idx - 7); } +#else +#define applyCurve(x, idx) (x) +#endif // expo-funktion: // --------------- diff --git a/src/open9x.h b/src/open9x.h index 94781cb82..1d59ac8d1 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -819,6 +819,12 @@ struct CurveInfo { }; extern CurveInfo curveinfo(uint8_t idx); +#if defined(PCBARM) +#define CURVES_OFFSET_SHIFT(x) (0) +#else +#define CURVES_OFFSET_SHIFT(x) (5*(x)) +#endif + extern void deleteExpoMix(uint8_t expo, uint8_t idx); extern void incSubtrim(uint8_t idx, int16_t inc); diff --git a/util/tts.py b/util/tts.py index 73d0d4351..3d93c81b3 100644 --- a/util/tts.py +++ b/util/tts.py @@ -27,8 +27,10 @@ def generate(str, idx, alternate=0): if "speak" in sys.argv: if "sapi" in sys.argv: tts.Speak(str) - else: + elif "espeak" in sys.argv: subprocess.Popen(["espeak", "-v", espeakVoice, "-s", espeakspeed, "-z", str.encode("latin-1")], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait() + else: + print "which speach engine?" else: if isinstance(idx, int): result = "%04d.wav" % idx @@ -54,8 +56,11 @@ def generate(str, idx, alternate=0): o.writeframes(f[6400:-6400]) o.close() os.remove(temp) - else: + elif "espeak" in sys.argv: subprocess.Popen(["espeak", "-v", espeakVoice, "-s", espeakspeed, "-z", "-w", result, str.encode("latin-1")], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait() + else: + print "which speach engine?" + return [] if 'ad4' in sys.argv: subprocess.Popen(["AD4CONVERTER", "-E4", result], stdout=subprocess.PIPE, stderr=subprocess.PIPE).wait()