From 4200c203b6f35b73f027c181fa38be3fb52194e2 Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 23 Feb 2012 18:09:27 +0000 Subject: [PATCH] PXX updates + optimizations pulled from er9x FrSky TELEMETRY menu is now moved to [DOWN long] Function added to reach the TELEMETRY screen when a switch is enabled Main view optimizations --- changelog.txt | 20 +++ src/file.cpp | 8 +- src/file.h | 4 + src/frsky.cpp | 256 ++++++++++++++++++++++++++++++++++- src/general_menus.cpp | 21 ++- src/main_views.cpp | 301 +++--------------------------------------- src/menus.h | 3 + src/model_menus.cpp | 10 +- src/myeeprom.h | 8 +- src/open9x.cpp | 12 ++ src/open9x.h | 19 ++- src/pers.cpp | 61 ++++----- src/pulses.cpp | 28 +--- src/simpgmspace.cpp | 2 + src/translations/en.h | 2 +- src/translations/fr.h | 2 +- 16 files changed, 387 insertions(+), 370 deletions(-) diff --git a/changelog.txt b/changelog.txt index 410d5f015..2c380de61 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,7 +1,27 @@ +****************************************** +CHANGELOG: 23-02-2012 BSS +PXX updates + optimizations pulled from er9x +FrSky TELEMETRY menu is now moved to [DOWN long] +Function added to reach the TELEMETRY screen when a switch is enabled +Optimizations + +****************************************** +CHANGELOG: 22-02-2012 BSS +Blades count may now be 4 +V4: New mixers/expos fields inflight modifiable through RE1 + +****************************************** +CHANGELOG: 21-02-2012 BSS +V4: Logs format ported from gruvin9x + ****************************************** CHANGELOG: 20-02-2012 BSS Last GPS coords displayed even when streaming stops (model lost) +****************************************** +CHANGELOG: 19-02-2012 BSS +V4: Inflight fields modification through RE1 feature added + ****************************************** CHANGELOG: 17-02-2012 BSS RSSI thresholds on a per model basis diff --git a/src/file.cpp b/src/file.cpp index 5420eca1a..2042211b1 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -40,10 +40,6 @@ uint8_t s_write_err = 0; // error reasons uint8_t s_sync_write = false; -#define RESV 64 //reserv for eeprom header with directory (eeFs) -#define FIRSTBLK (RESV/BS) -#define BLOCKS (EESIZE/BS) - #define EEFS_VERS 4 PACK(struct DirEnt{ uint8_t startBlk; @@ -127,9 +123,7 @@ int8_t EeFsck() { s_sync_write = true; - uint8_t *bufp; - static uint8_t buffer[BLOCKS]; - bufp = buffer; + uint8_t *bufp = reusableBuffer.eefs_buffer; memset(bufp,0,BLOCKS); uint8_t blk ; int8_t ret=0; diff --git a/src/file.h b/src/file.h index 42750c976..17abc0c56 100644 --- a/src/file.h +++ b/src/file.h @@ -56,6 +56,10 @@ #define FILE_MODEL(n) (1+(n)) #define FILE_TMP (1+16) +#define RESV 64 //reserv for eeprom header with directory (eeFs) +#define FIRSTBLK (RESV/BS) +#define BLOCKS (EESIZE/BS) + bool EeFsOpen(); int8_t EeFsck(); void EeFsFormat(); diff --git a/src/frsky.cpp b/src/frsky.cpp index b87b43bd3..13cc4f073 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -31,6 +31,7 @@ */ #include "open9x.h" +#include "menus.h" // Enumerate FrSky packet codes #define LINKPKT 0xfe @@ -224,7 +225,7 @@ void parseTelemHubByte(uint8_t byte) // First received GPS position => Pilot GPS position getGpsPilotPosition(); } - else if (frskyHubData.gpsDistNeeded || g_eeGeneral.view == e_telemetry+4*ALTERNATE_VIEW) { + else if (frskyHubData.gpsDistNeeded || g_menuStack[0] != menuProcFrsky) { getGpsDistance(); } } @@ -636,3 +637,256 @@ void resetTelemetry() #endif } +#if defined(FRSKY) +void displayRssiLine() +{ + lcd_hline(0, 54, 128, 0); // separator + lcd_putsLeft(7*FH+1, STR_TX); lcd_outdezNAtt(4*FW, 7*FH+1, frskyRSSI[1].value, LEADING0, 2); + lcd_rect(25, 57, 38, 7); + lcd_filled_rect(26, 58, 9*frskyRSSI[1].value/25, 5); + lcd_puts(105, 7*FH+1, STR_RX); lcd_outdezNAtt(105+4*FW-1, 7*FH+1, frskyRSSI[0].value, LEADING0, 2); + lcd_rect(65, 57, 38, 7); + uint8_t v = 9*frskyRSSI[0].value/25; + lcd_filled_rect(66+36-v, 58, v, 5); +} +#endif + +#if defined(FRSKY_HUB) || defined(WS_HOW_HIGH) +void displayAltitudeLine(uint8_t x, uint8_t y, uint8_t flags) +{ + lcd_putsn(x, y, STR_ALTnDST, 4); + int16_t value = frskyHubData.baroAltitude_bp + frskyHubData.baroAltitudeOffset; + putsTelemetryValue(lcd_lastPos, y, value, UNIT_METERS, flags|LEFT); +} +#endif + +enum FrskyViews { + e_frsky_bars, + e_frsky_a1a2, +#ifdef WS_HOW_HIGH + e_frsky_ws_how_high, +#endif +#ifdef FRSKY_HUB + e_frsky_hub = e_frsky_a1a2+1, + e_frsky_gps +#endif +}; + +#if defined(FRSKY_HUB) && defined(WS_HOW_HIGH) +#define FRSKY_VIEW_MAX (g_model.frsky.usrProto == 0 ? 1 : ((g_model.frsky.usrProto == 1 && frskyHubData.gpsFix >= 0) ? 3 : 2)) +#elif defined(FRSKY_HUB) +#define FRSKY_VIEW_MAX (g_model.frsky.usrProto == 0 ? 1 : (frskyHubData.gpsFix >= 0 ? 3 : 2)) +#elif defined(WS_HOW_HIGH) +#define FRSKY_VIEW_MAX (g_model.frsky.usrProto == 0 ? 1 : 2) +#endif + +void menuProcFrsky(uint8_t event) +{ + static uint8_t s_frsky_view = e_frsky_bars; + + switch (event) { + case EVT_KEY_BREAK(KEY_UP): + if (s_frsky_view-- == 0) + s_frsky_view = FRSKY_VIEW_MAX; + break; + + case EVT_KEY_BREAK(KEY_DOWN): + if (s_frsky_view++ == FRSKY_VIEW_MAX) + s_frsky_view = 0; + break; + + case EVT_KEY_FIRST(KEY_EXIT): + chainMenu(menuMainView); + break; + } + + // The top black bar + putsModelName(0, 0, g_model.name, g_eeGeneral.currModel, 0); + uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK : 0); + putsVBat(14*FW,0,att); + if (g_model.timer1.mode) { + att = (s_timerState[0]==TMR_BEEPING ? BLINK : 0); + putsTime(17*FW, 0, s_timerVal[0], att, att); + } + lcd_filled_rect(0, 0, DISPLAY_W, 8); + + if (frskyStreaming >= 0) { + if (s_frsky_view == e_frsky_bars) { + // The bars + uint8_t bars_height = 5; + for (int8_t i=3; i>=0; i--) { + if (g_model.frsky.bars[i].source && (51-g_model.frsky.bars[i].barMax) > g_model.frsky.bars[i].barMin) { + lcd_putsnAtt(0, bars_height+bars_height+1+i*(bars_height+6), STR_VTELEMBARS+LEN_VTELEMBARS*g_model.frsky.bars[i].source, LEN_VTELEMBARS, 0); + lcd_rect(25, bars_height+6+i*(bars_height+6), 101, bars_height+2); + int16_t value = getValue(CHOUT_BASE+NUM_CHNOUT+MAX_TIMERS+g_model.frsky.bars[i].source-1); + uint8_t threshold = 0, thresholdX = 0; + if (g_model.frsky.bars[i].source <= 2) + threshold = g_model.frsky.channels[g_model.frsky.bars[i].source-1].alarms_value[0]; + else + threshold = barsThresholds[g_model.frsky.bars[i].source-3]; + if (threshold) { + thresholdX = (uint8_t)(int16_t)((int16_t)100 * (threshold - g_model.frsky.bars[i].barMin * 4) / ((51 - g_model.frsky.bars[i].barMax) * 5 - g_model.frsky.bars[i].barMin * 4)); + if (thresholdX > 100) + thresholdX = 0; + } + uint8_t width = (uint8_t)limit((int16_t)0, (int16_t)((int16_t)100 * (value - g_model.frsky.bars[i].barMin * 5) / ((51 - g_model.frsky.bars[i].barMax) * 4 - g_model.frsky.bars[i].barMin * 4)), (int16_t)100); + lcd_filled_rect(26, bars_height+6+1+i*(bars_height+6), width, bars_height, (threshold > value) ? DOTTED : SOLID); + for (uint8_t j=50; j<125; j+=25) + if (j>26+thresholdX) lcd_vline(j, bars_height+6+1+i*(bars_height+6), bars_height); + if (thresholdX) { + lcd_vlineStip(26+thresholdX, bars_height+4+i*(bars_height+6), bars_height+3, DOTTED); + lcd_hline(25+thresholdX, bars_height+4+i*(bars_height+6), 3); + } + } + else { + bars_height += 2; + } + } + displayRssiLine(); + } + else if (s_frsky_view == e_frsky_a1a2) { + // Big A1 / A2 with min and max + uint8_t x0, blink; + if (g_model.frsky.channels[0].ratio || g_model.frsky.channels[1].ratio) { + x0 = 0; + for (uint8_t i=0; i<2; i++) { + if (g_model.frsky.channels[i].ratio) { + blink = (FRSKY_alarmRaised(i) ? INVERS : 0); + putsStrIdx(x0, 2*FH, STR_A, i+1, TWO_DOTS); + x0 += 3*FW; + putsTelemetryChannel(x0, 2*FH, i, frskyTelemetry[i].value, blink|DBLSIZE|LEFT); + putsTelemetryChannel(x0+FW, 3*FH, i, frskyTelemetry[i].min, 0); + putsTelemetryChannel(x0+3*FW, 3*FH, i, frskyTelemetry[i].max, LEFT); + x0 = 11*FW-2; + } + } + } + +#ifdef FRSKY_HUB + // Cells voltage + { + uint8_t x, y; + x = 3*FW; + y = 5*FH-3; + for (uint8_t k=0; k=4) midVals[i] = (loVals[i] + hiVals[i])/2; } @@ -611,9 +608,9 @@ void menuProcDiagCalib(uint8_t event) lcd_puts(3*FW, 3*FH, STR_MENUWHENDONE); for (uint8_t i=0; i<7; i++) { - loVals[i] = 15000; - hiVals[i] = -15000; - midVals[i] = anaIn(i); + reusableBuffer.calib.loVals[i] = 15000; + reusableBuffer.calib.hiVals[i] = -15000; + reusableBuffer.calib.midVals[i] = anaIn(i); } break; @@ -623,11 +620,11 @@ void menuProcDiagCalib(uint8_t event) lcd_puts(3*FW, 3*FH, STR_MENUWHENDONE); for (uint8_t i=0; i<7; i++) { - if (abs(loVals[i]-hiVals[i])>50) { - g_eeGeneral.calibMid[i] = midVals[i]; - int16_t v = midVals[i] - loVals[i]; + if (abs(reusableBuffer.calib.loVals[i]-reusableBuffer.calib.hiVals[i])>50) { + g_eeGeneral.calibMid[i] = reusableBuffer.calib.midVals[i]; + int16_t v = reusableBuffer.calib.midVals[i] - reusableBuffer.calib.loVals[i]; g_eeGeneral.calibSpanNeg[i] = v - v/64; - v = hiVals[i] - midVals[i]; + v = reusableBuffer.calib.hiVals[i] - reusableBuffer.calib.midVals[i]; g_eeGeneral.calibSpanPos[i] = v - v/64; } } diff --git a/src/main_views.cpp b/src/main_views.cpp index 7722591d7..332cde9b0 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -32,20 +32,6 @@ #include "menus.h" -uint8_t tabViews[] = { - 1, /*e_outputValues*/ - 1, /*e_outputBars*/ - 2, /*e_inputs*/ - 1, /*e_timer2*/ -#if defined(FRSKY_HUB) - 5, /*e_telemetry*/ -#elif defined(WS_HOW_HIGH) - 4, /*e_telemetry*/ -#elif defined(FRSKY) - 3, /*e_telemetry*/ -#endif -}; - #define BOX_WIDTH 23 #define BAR_HEIGHT (BOX_WIDTH-1l) #define MARKER_WIDTH 5 @@ -79,29 +65,6 @@ void doMainScreenGrphics() } } -#if defined(FRSKY) -void displayRssiLine() -{ - lcd_hline(0, 54, 128, 0); // separator - lcd_putsLeft(7*FH+1, STR_TX); lcd_outdezNAtt(4*FW, 7*FH+1, frskyRSSI[1].value, LEADING0, 2); - lcd_rect(25, 57, 38, 7); - lcd_filled_rect(26, 58, 9*frskyRSSI[1].value/25, 5); - lcd_puts(105, 7*FH+1, STR_RX); lcd_outdezNAtt(105+4*FW-1, 7*FH+1, frskyRSSI[0].value, LEADING0, 2); - lcd_rect(65, 57, 38, 7); - uint8_t v = 9*frskyRSSI[0].value/25; - lcd_filled_rect(66+36-v, 58, v, 5); -} -#endif - -#if defined(FRSKY_HUB) || defined(WS_HOW_HIGH) -void displayAltitudeLine(uint8_t x, uint8_t y, uint8_t flags) -{ - lcd_putsn(x, y, STR_ALTnDST, 4); - int16_t value = frskyHubData.baroAltitude_bp + frskyHubData.baroAltitudeOffset; - putsTelemetryValue(lcd_lastPos, y, value, UNIT_METERS, flags|LEFT); -} -#endif - void menuMainView(uint8_t event) { static bool instantTrimSwLock; @@ -110,6 +73,12 @@ void menuMainView(uint8_t event) uint8_t view = g_eeGeneral.view; uint8_t view_base = view & 0x0f; +#if defined(FRSKY) || defined(JETI) || defined(ARDUPILOT) || defined(NMEA) + if (isFunctionActive(FUNC_TELEMETRY_SCREEN)) { + event = EVT_KEY_LONG(KEY_DOWN); + } +#endif + switch(event) { /* TODO if timer2 is OFF, it's possible to use this timer2 as in er9x... @@ -126,18 +95,11 @@ void menuMainView(uint8_t event) break; case EVT_KEY_BREAK(KEY_RIGHT): case EVT_KEY_BREAK(KEY_LEFT): -#if defined(FRSKY) -#if defined(FRSKY_HUB) && defined(WS_HOW_HIGH) - tabViews[e_telemetry] = (g_model.frsky.usrProto == 0 ? 3 : ((g_model.frsky.usrProto == 1 && frskyHubData.gpsFix >= 0) ? 5 : 4)); -#elif defined(FRSKY_HUB) - tabViews[e_telemetry] = (g_model.frsky.usrProto == 1 ? 5 : 3); -#elif defined(WS_HOW_HIGH) - tabViews[e_telemetry] = (g_model.frsky.usrProto == 2 ? 4 : 3); -#endif -#endif - g_eeGeneral.view = (view + (event == EVT_KEY_BREAK(KEY_RIGHT) ? ALTERNATE_VIEW : tabViews[view_base]*ALTERNATE_VIEW-ALTERNATE_VIEW)) % (tabViews[view_base]*ALTERNATE_VIEW); - eeDirty(EE_GENERAL); - AUDIO_KEYPAD_UP(); + if (view_base == e_inputs) { + g_eeGeneral.view ^= ALTERNATE_VIEW; + eeDirty(EE_GENERAL); + AUDIO_KEYPAD_UP(); + } break; case EVT_KEY_LONG(KEY_RIGHT): pushMenu(menuProcModelSelect); @@ -148,16 +110,8 @@ void menuMainView(uint8_t event) killEvents(event); break; case EVT_KEY_BREAK(KEY_UP): - g_eeGeneral.view = view+1; - if(g_eeGeneral.view>=MAX_VIEWS) g_eeGeneral.view=0; - eeDirty(EE_GENERAL); - AUDIO_KEYPAD_UP(); - break; case EVT_KEY_BREAK(KEY_DOWN): - if(view>0) - g_eeGeneral.view = view - 1; - else - g_eeGeneral.view = MAX_VIEWS-1; + g_eeGeneral.view = (event == EVT_KEY_BREAK(KEY_UP) ? (view_base == MAIN_VIEW_MAX ? 0 : view_base + 1) : (view_base == 0 ? MAIN_VIEW_MAX : view_base - 1)); eeDirty(EE_GENERAL); AUDIO_KEYPAD_UP(); break; @@ -166,7 +120,9 @@ void menuMainView(uint8_t event) killEvents(event); break; case EVT_KEY_LONG(KEY_DOWN): -#if defined(JETI) +#if defined(FRSKY) + chainMenu(menuProcFrsky); +#elif defined(JETI) JETI_EnableRXD(); // enable JETI-Telemetry reception chainMenu(menuProcJeti); #elif defined(ARDUPILOT) @@ -190,24 +146,15 @@ void menuMainView(uint8_t event) } #endif else if (view == e_timer2) { - resetTimer(1); + resetTimer(1); } -#ifdef FRSKY - else if (view_base == e_telemetry) { - resetTelemetry(); - } -#endif else { resetTimer(0); } AUDIO_KEYPAD_UP(); break; case EVT_KEY_LONG(KEY_EXIT): - resetTimer(0); - resetTimer(1); -#ifdef FRSKY - resetTelemetry(); -#endif + resetAll(); AUDIO_KEYPAD_UP(); break; case EVT_ENTRY: @@ -240,19 +187,6 @@ void menuMainView(uint8_t event) if (!trim2OfsSwLock && trimSw) moveTrimsToOffsets(); trim2OfsSwLock = trimSw; -#ifdef FRSKY - if (view_base == e_telemetry && frskyStreaming >= 0 && view > ALTERNATE_VIEW) { - putsModelName(0, 0, g_model.name, g_eeGeneral.currModel, 0); - uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK : 0); - putsVBat(14*FW,0,att); - if (g_model.timer1.mode) { - att = (s_timerState[0]==TMR_BEEPING ? BLINK : 0); - putsTime(17*FW, 0, s_timerVal[0], att, att); - } - lcd_filled_rect(0, 0, DISPLAY_W, 8); - } - else -#endif { uint8_t phase = getFlightPhase(); lcd_putsnAtt(6*FW+2, 2*FH, g_model.phaseData[phase].name, sizeof(g_model.phaseData[phase].name), ZCHAR); @@ -373,207 +307,6 @@ void menuMainView(uint8_t event) } } } -#if defined(FRSKY) - else if (view_base == e_telemetry) { - if (frskyStreaming >= 0) { - uint8_t y0, x0, blink; - - if (view == e_telemetry+ALTERNATE_VIEW) { - // The bars - uint8_t bars_height = 5; - for (int8_t i=3; i>=0; i--) { - if (g_model.frsky.bars[i].source && (51-g_model.frsky.bars[i].barMax) > g_model.frsky.bars[i].barMin) { - lcd_putsnAtt(0, bars_height+bars_height+1+i*(bars_height+6), STR_VTELEMBARS+LEN_VTELEMBARS*g_model.frsky.bars[i].source, LEN_VTELEMBARS, 0); - lcd_rect(25, bars_height+6+i*(bars_height+6), 101, bars_height+2); - int16_t value = getValue(CHOUT_BASE+NUM_CHNOUT+MAX_TIMERS+g_model.frsky.bars[i].source-1); - uint8_t threshold = 0, thresholdX = 0; - if (g_model.frsky.bars[i].source <= 2) - threshold = g_model.frsky.channels[g_model.frsky.bars[i].source-1].alarms_value[0]; - else - threshold = barsThresholds[g_model.frsky.bars[i].source-3]; - if (threshold) { - thresholdX = (uint8_t)(int16_t)((int16_t)100 * (threshold - g_model.frsky.bars[i].barMin * 4) / ((51 - g_model.frsky.bars[i].barMax) * 5 - g_model.frsky.bars[i].barMin * 4)); - if (thresholdX > 100) - thresholdX = 0; - } - uint8_t width = (uint8_t)limit((int16_t)0, (int16_t)((int16_t)100 * (value - g_model.frsky.bars[i].barMin * 5) / ((51 - g_model.frsky.bars[i].barMax) * 4 - g_model.frsky.bars[i].barMin * 4)), (int16_t)100); - lcd_filled_rect(26, bars_height+6+1+i*(bars_height+6), width, bars_height, (threshold > value) ? DOTTED : SOLID); - for (uint8_t j=50; j<125; j+=25) - if (j>26+thresholdX) lcd_vline(j, bars_height+6+1+i*(bars_height+6), bars_height); - if (thresholdX) { - lcd_vlineStip(26+thresholdX, bars_height+4+i*(bars_height+6), bars_height+3, DOTTED); - lcd_hline(25+thresholdX, bars_height+4+i*(bars_height+6), 3); - } - } - else { - bars_height += 2; - } - } - - displayRssiLine(); - } - else if (view == e_telemetry+2*ALTERNATE_VIEW) { - // Big A1 / A2 with min and max - if (g_model.frsky.channels[0].ratio || g_model.frsky.channels[1].ratio) { - x0 = 0; - for (uint8_t i=0; i<2; i++) { - if (g_model.frsky.channels[i].ratio) { - blink = (FRSKY_alarmRaised(i) ? INVERS : 0); - putsStrIdx(x0, 2*FH, STR_A, i+1, TWO_DOTS); - x0 += 3*FW; - putsTelemetryChannel(x0, 2*FH, i, frskyTelemetry[i].value, blink|DBLSIZE|LEFT); - putsTelemetryChannel(x0+FW, 3*FH, i, frskyTelemetry[i].min, 0); - putsTelemetryChannel(x0+3*FW, 3*FH, i, frskyTelemetry[i].max, LEFT); - x0 = 11*FW-2; - } - } - } - -#ifdef FRSKY_HUB - // Cells voltage - { - uint8_t x, y; - x = 3*FW; - y = 5*FH-3; - for (uint8_t k=0; k= 0 ? 20-FW/2+5 : 20-FW/2-2, FH*6, g_model.timer2.mode, SHRT_TM_MODE); diff --git a/src/menus.h b/src/menus.h index 738894fc9..8c457a1ba 100644 --- a/src/menus.h +++ b/src/menus.h @@ -72,6 +72,9 @@ inline MenuFuncP lastPopMenu() void doMainScreenGrphics(); void menuMainView(uint8_t event); +#ifdef FRSKY +void menuProcFrsky(uint8_t event); +#endif void menuProcSetup(uint8_t event); void menuProcModelSelect(uint8_t event); void menuProcStatistic(uint8_t event); diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 35e5c081f..f45b87362 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -154,8 +154,6 @@ static int8_t s_copyTgtOfs; void menuProcModelSelect(uint8_t event) { - char name[sizeof(g_model.name)]; - TITLE(STR_MENUMODELSEL); // flush eeprom write @@ -343,8 +341,8 @@ void menuProcModelSelect(uint8_t event) k %= 16; if (EFile::exists(FILE_MODEL(k))) { - uint16_t size = eeLoadModelName(k, name); - putsModelName(4*FW, y, name, k, 0); + uint16_t size = eeLoadModelName(k, reusableBuffer.model_name); + putsModelName(4*FW, y, reusableBuffer.model_name, k, 0); lcd_outdezAtt(20*FW, y, size, 0); if (k==g_eeGeneral.currModel && (s_copySrcRow<0 || i+s_pgOfs!=sub)) lcd_putc(1, y, '*'); } @@ -356,8 +354,8 @@ void menuProcModelSelect(uint8_t event) } if (s_warning) { - eeLoadModelName(sub, name); - s_warning_info = name; + eeLoadModelName(sub, reusableBuffer.model_name); + s_warning_info = reusableBuffer.model_name; s_warning_info_len = sizeof(g_model.name); displayConfirmation(event); } diff --git a/src/myeeprom.h b/src/myeeprom.h index fc070a063..f4524a0a1 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -74,10 +74,7 @@ enum MainViews { e_outputBars, e_inputs, e_timer2, -#ifdef FRSKY - e_telemetry, -#endif - MAX_VIEWS + MAIN_VIEW_MAX = e_timer2 }; #define ALTERNATE_VIEW 0x10 @@ -191,7 +188,10 @@ enum Functions { FUNC_INSTANT_TRIM, FUNC_TRIMS_2_OFS, FUNC_PLAY_SOUND, + FUNC_TELEMETRY_SCREEN, +#ifdef SOMO FUNC_PLAY_SOMO, +#endif #ifdef LOGS FUNC_LOGS, #endif diff --git a/src/open9x.cpp b/src/open9x.cpp index 960b0cf77..58ccb79fd 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -65,6 +65,8 @@ uint8_t heartbeat; int8_t safetyCh[NUM_CHNOUT]; +union ReusableBuffer reusableBuffer; + const pm_char s_charTab[] PROGMEM = "_-.,"; const pm_uint8_t bchout_ar[] PROGMEM = { @@ -928,6 +930,16 @@ void resetTimer(uint8_t idx) s_timerVal_10ms[idx] = 0 ; } +void resetAll() +{ + // TODO s_traceCnt to be reset? + resetTimer(0); + resetTimer(1); +#ifdef FRSKY + resetTelemetry(); +#endif +} + static uint8_t lastSwPos[2] = {0, 0}; static uint16_t s_cnt[2] = {0, 0}; static uint16_t s_sum[2] = {0, 0}; diff --git a/src/open9x.h b/src/open9x.h index 623036ecd..3e4095e4b 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -464,6 +464,7 @@ extern uint8_t trimsCheckTimer; #define TMR_BEEPING 2 #define TMR_STOPPED 3 void resetTimer(uint8_t idx); +void resetAll(); extern uint8_t g_tmr1Latency_max; extern uint8_t g_tmr1Latency_min; @@ -608,7 +609,6 @@ void startPulses(); void setupPulses(); void DSM2_Init(); void DSM2_Done(); -void resetProto(); extern uint8_t *pulses2MHzRPtr; extern uint8_t *pulses2MHzWPtr; @@ -703,5 +703,22 @@ extern volatile uint8_t g_rotenc[2]; #include "somo14d.h" #endif +// Re-useable byte array to save having multiple buffers +union ReusableBuffer +{ + uint8_t eefs_buffer[BLOCKS]; // used by EeFsck + + char model_name[sizeof(g_model.name)]; // used by menuProcModelSelect + + struct + { + int16_t midVals[7]; + int16_t loVals[7]; + int16_t hiVals[7]; + } calib; // used by menuProcDiagCalib +}; + +extern union ReusableBuffer reusableBuffer; + #endif // gruvin9x_h /*eof*/ diff --git a/src/pers.cpp b/src/pers.cpp index 886b8f61f..24c74c52c 100644 --- a/src/pers.cpp +++ b/src/pers.cpp @@ -108,37 +108,7 @@ bool eeModelExists(uint8_t id) return EFile::exists(FILE_MODEL(id)); } -void eeLoadModel(uint8_t id) -{ - if(id 0 && sz != sizeof(g_model)) { - printf("Model data read=%d bytes vs %d bytes\n", sz, (int)sizeof(ModelData)); - } -#endif - - if (sz == 0) { - // alert("Error Loading Model"); - modelDefault(id); - eeCheck(true); - } - - // TODO optim: resetAll() - // TODO s_traceCnt to be reset? - resetTimer(0); - resetTimer(1); - resetProto(); -#ifdef LOGS - initLogs(); -#endif - } -} - -void resetProto() // TODO inline this if !DSM2_SERIAL +void resetProto() { #if defined(DSM2_SERIAL) if (g_model.protocol == PROTO_DSM2) { @@ -161,11 +131,38 @@ void resetProto() // TODO inline this if !DSM2_SERIAL #endif } #elif defined(FRSKY) - resetTelemetry(); FRSKY_setModelAlarms(); #endif } +void eeLoadModel(uint8_t id) +{ + if(id 0 && sz != sizeof(g_model)) { + printf("Model data read=%d bytes vs %d bytes\n", sz, (int)sizeof(ModelData)); + } +#endif + + if (sz == 0) { + // alert("Error Loading Model"); + modelDefault(id); + eeCheck(true); + } + + resetProto(); + resetAll(); + +#ifdef LOGS + initLogs(); +#endif + } +} + int8_t eeFindEmptyModel(uint8_t id, bool down) { int8_t i = id; diff --git a/src/pulses.cpp b/src/pulses.cpp index ae85ff5c4..3f70cbdf8 100644 --- a/src/pulses.cpp +++ b/src/pulses.cpp @@ -61,11 +61,7 @@ void startPulses() setupPulses(); #ifdef DSM2_SERIAL - if (g_model.protocol == PROTO_DSM2) { - DSM2_EnableTXD(); - OCR1A = 40000; - } - else + if (g_model.protocol != PROTO_DSM2) #endif { @@ -319,10 +315,10 @@ void putPcmByte( uint8_t byte ) crc( byte ) ; - for ( i = 0 ; i < 8 ; i += 1 ) + for (i=0; i<8; i++) { - putPcmBit( byte & 0x01 ) ; - byte >>= 1 ; + putPcmBit( byte & 0x80 ) ; + byte <<= 1 ; } } @@ -359,17 +355,9 @@ void setupPulsesPXX() putPcmByte( 0 ) ; // Second byte of flags pxxFlag = 0; // reset flag after send for ( i = 0 ; i < 8 ; i += 2 ) // First 8 channels only - { // Next 8 channels would have 2048 added - chan = g_chans512[i] * 3 / 4 + 1024 ; - chan_1 = g_chans512[i+1] * 3 / 4 + 1024 ; - if ( chan > 2047 ) - { - chan = 2047 ; - } - if ( chan_1 > 2047 ) - { - chan_1 = 2047 ; - } + { + chan = g_chans512[i] * 3 / 4 + 2250 ; + chan_1 = g_chans512[i+1] * 3 / 4 + 2250 ; putPcmByte( chan ) ; // Low byte of channel putPcmByte( ( ( chan >> 8 ) & 0x0F ) | ( chan_1 << 4) ) ; // 4 bits each from 2 channels putPcmByte( chan_1 >> 4 ) ; // High byte of channel @@ -465,8 +453,6 @@ void DSM2_Init(void) while (UCSR0A & (1 << RXC0)) UDR0; // flush receive buffer - setupPulsesDsm2(); - // These should be running right from power up on a FrSky enabled '9X. DSM2_EnableTXD(); // enable DSM2 UART transmitter diff --git a/src/simpgmspace.cpp b/src/simpgmspace.cpp index 6cda4df09..a7d7a5b77 100644 --- a/src/simpgmspace.cpp +++ b/src/simpgmspace.cpp @@ -74,6 +74,8 @@ void *eeprom_write_function(void *) if (eepromFile) { fp = fopen(eepromFile, "r+"); + if (!fp) + fp = fopen(eepromFile, "w+"); assert(fp); } diff --git a/src/translations/en.h b/src/translations/en.h index 52245dd98..4e76fd0a1 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -73,7 +73,7 @@ #else #define TR_SOMO #endif -#define TR_VFSWFUNC "Security \0 ""Trainer \0 ""Instant Trim ""Trims2Offsets""Play sound\0 " TR_SOMO TR_SDCLOGGS +#define TR_VFSWFUNC "Security \0 ""Trainer \0 ""Instant Trim ""Trims2Offsets""Play Sound\0 ""Telem. View\0 " TR_SOMO TR_SDCLOGGS #define LEN_FUNCSOUNDS 6 #define TR_FUNCSOUNDS "Warn1 ""Warn2 ""Cheep ""Ring ""SciFi ""Robot ""Chirp ""Tada ""Crickt""Siren ""AlmClk""Ratata""Tick ""Haptc1""Haptc2""Haptc3" diff --git a/src/translations/fr.h b/src/translations/fr.h index d0bed7df0..da6538bdd 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -73,7 +73,7 @@ #else #define TR_SOMO #endif -#define TR_VFSWFUNC "Securite \0 ""Ecolage \0 ""Trim instant ""Trims2Offsets""Jouer son " TR_SOMO TR_SDCLOGGS +#define TR_VFSWFUNC "Securite \0 ""Ecolage \0 ""Trim instant ""Trims2Offsets""Jouer son\0 ""Telem. View\0 " TR_SOMO TR_SDCLOGGS #define LEN_FUNCSOUNDS 6 #define TR_FUNCSOUNDS "Warn1 ""Warn2 ""Cheep ""Ring ""SciFi ""Robot ""Chirp ""Tada ""Crickt""Siren ""AlmClk""Ratata""Tick ""Haptc1""Haptc2""Haptc3"