diff --git a/src/drivers.cpp b/src/drivers.cpp index 50dd2c126..d1df6e7f3 100644 --- a/src/drivers.cpp +++ b/src/drivers.cpp @@ -473,7 +473,7 @@ void per10ms() #if defined(AUDIO) uint8_t warble = 0; #endif - int8_t verticalSpeed = frskyHubData.baroAltitude_bp; // TODO to be modified of course!! + int8_t verticalSpeed = limit((int16_t)-100, frskyHubData.varioSpeed, (int16_t)+100); uint16_t interval; if (verticalSpeed == 0) { @@ -484,8 +484,7 @@ void per10ms() verticalSpeed = -verticalSpeed; warble = 1; } - if (verticalSpeed > 100) verticalSpeed = 100; - interval = (uint16_t)200 / verticalSpeed; + interval = (uint8_t)200 / verticalSpeed; } if (g_tmr10ms - s_varioTmr > interval) { s_varioTmr = g_tmr10ms; diff --git a/src/file.cpp b/src/file.cpp index d9ab57caf..d19cec614 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -31,8 +31,6 @@ * */ -#define PROGRESS_VERTICAL_BAR - #include "open9x.h" #include "stdio.h" #include "inttypes.h" @@ -470,9 +468,7 @@ void RlcFile::writeRlc(uint8_t i_fileId, uint8_t typ, uint8_t*buf, uint16_t i_le m_rlc_buf = buf; m_rlc_len = i_len; m_cur_rlc_len = 0; -#if defined (PROGRESS_CIRCLE) - m_ratio = (typ == FILE_TYP_MODEL ? 60 : 6); -#elif defined (PROGRESS_VERTICAL_BAR) +#if defined (EEPROM_PROGRESS_BAR) m_ratio = (typ == FILE_TYP_MODEL ? 100 : 10); #endif @@ -590,32 +586,13 @@ void RlcFile::flush() s_sync_write = false; } +#if defined (EEPROM_PROGRESS_BAR) void RlcFile::DisplayProgressBar(uint8_t x) { if (s_eeDirtyMsk || isWriting() || eeprom_buffer_size) { -#if defined (PROGRESS_BAR) - uint8_t len = (s_eeDirtyMsk ? 123 : min((uint8_t)123, (uint8_t)((m_rlc_len) / 5 + eeprom_buffer_size))); - lcd_filled_rect(2, 1, 125, 5, SOLID, WHITE); - lcd_filled_rect(3, 2, 123-len, 3); -#elif defined (PROGRESS_CIRCLE) - lcd_filled_rect(x-1, 0, 7, 7, SOLID, WHITE); - uint8_t len = s_eeDirtyMsk ? 1 : limit(1, 12 - (uint8_t)(m_rlc_len/m_ratio), 12); - lcd_hline(x+1, 1, min((uint8_t)3, len)); - if (len >= 3) { - lcd_vline(x+4, 2, min(3, len-3)); - if (len >= 6) { - lcd_hline(x+4, 1+4, -min(3, len-6)); - if (len >= 9) { - lcd_vline(x, 5, -min(3, len-9)); - } - } - } -#elif defined (PROGRESS_VERTICAL_BAR) uint8_t len = s_eeDirtyMsk ? 1 : limit((uint8_t)1, (uint8_t)(7 - (m_rlc_len/m_ratio)), (uint8_t)7); lcd_filled_rect(x+1, 0, 5, FH, SOLID, WHITE); lcd_filled_rect(x+2, 7-len, 3, len); -#elif defined (PROGRESS_FIXED_CIRCLE) - lcd_square(x, 1, 5); -#endif } } +#endif diff --git a/src/file.h b/src/file.h index 22fc77909..b61852059 100644 --- a/src/file.h +++ b/src/file.h @@ -126,7 +126,9 @@ class RlcFile: public EFile uint8_t m_write1_byte; uint8_t m_write_len; uint8_t * m_write_buf; +#if defined (EEPROM_PROGRESS_BAR) uint8_t m_ratio; +#endif public: @@ -160,8 +162,18 @@ public: uint16_t readRlc(uint8_t*buf, uint16_t i_len); // TODO should be like writeRlc? #endif +#if defined (EEPROM_PROGRESS_BAR) void DisplayProgressBar(uint8_t x); +#endif }; +#if defined (EEPROM_PROGRESS_BAR) +#define DISPLAY_PROGRESS_BAR(x) theFile.DisplayProgressBar(x) +#else +#define DISPLAY_PROGRESS_BAR(x) +#endif + +uint16_t evalChkSum(); + #endif /*eof*/ diff --git a/src/frsky.cpp b/src/frsky.cpp index b94c65a68..317165a46 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -152,16 +152,6 @@ inline void getGpsDistance() frskyHubData.maxGpsDistance = frskyHubData.gpsDistance; } -inline int8_t parseTelemHubIndex(uint8_t index) -{ - if (index > 0x39) { - if (index > 0x3b) - return -1; // invalid index - index -= 17; - } - return index*2; -} - typedef enum { TS_IDLE = 0, // waiting for 0x5e frame marker TS_DATA_ID, // waiting for dataID @@ -192,10 +182,13 @@ void parseTelemHubByte(uint8_t byte) return; } if (state == TS_DATA_ID) { - structPos = parseTelemHubIndex(byte); - state = TS_DATA_LOW; - if (structPos < 0) + if (byte > 0x3b) { state = TS_IDLE; + } + else { + structPos = byte*2; + state = TS_DATA_LOW; + } return; } if (state == TS_DATA_LOW) { @@ -258,6 +251,20 @@ void parseTelemHubByte(uint8_t byte) frskyHubData.minAltitude = frskyHubData.baroAltitude_bp; break; + case offsetof(FrskyHubData, baroAltitude_ap): + { + uint16_t actVario = frskyHubData.baroAltitude_bp - frskyHubData.lastBaroAltitude_bp; + actVario *= 100; + actVario += frskyHubData.baroAltitude_ap - frskyHubData.lastBaroAltitude_ap; + frskyHubData.varioSpeed = frskyHubData.varioSpeed - frskyHubData.varioQueue[frskyHubData.queuePointer] + actVario; + frskyHubData.varioQueue[frskyHubData.queuePointer] = actVario; + if (++frskyHubData.queuePointer > 4) + frskyHubData.queuePointer=0; + frskyHubData.lastBaroAltitude_bp = frskyHubData.baroAltitude_bp; + frskyHubData.lastBaroAltitude_ap = frskyHubData.baroAltitude_ap; + break; + } + case offsetof(FrskyHubData, gpsAltitude_ap): if (!frskyHubData.gpsAltitudeOffset) frskyHubData.gpsAltitudeOffset = -frskyHubData.gpsAltitude_bp; diff --git a/src/frsky.h b/src/frsky.h index b855d6ca3..c17dff0fd 100644 --- a/src/frsky.h +++ b/src/frsky.h @@ -109,14 +109,11 @@ PACK(struct FrskyHubData { uint8_t cellsCount:4; // 4bits out of 16bits spare reused uint8_t minCellVolts; // 8bits out of 16bits spare reused uint16_t current; // 0x28 Current - // 17 spares - uint16_t volts_bp; // 0x3A - uint16_t volts_ap; // 0x3B - // end of FrSky Hub data - uint16_t gpsDistance; - int16_t gpsAltitudeOffset; - uint8_t minCellMinVolts; - /* order is important starting from here */ + int16_t varioQueue[5]; // circular-buffer + uint8_t queuePointer; // circular-buffer pointer + int8_t lastBaroAltitude_ap; + int16_t lastBaroAltitude_bp; + int16_t varioSpeed; int16_t minAltitude; int16_t maxAltitude; uint16_t maxRpm; @@ -124,6 +121,12 @@ PACK(struct FrskyHubData { int16_t maxTemperature2; uint16_t maxGpsSpeed; uint16_t maxGpsDistance; + uint16_t gpsDistance; + int16_t gpsAltitudeOffset; + uint16_t volts_bp; // 0x3A + uint16_t volts_ap; // 0x3B + // end of FrSky Hub data + uint8_t minCellMinVolts; }); #elif defined(WS_HOW_HIGH) diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 88dc9635a..a0bccabb0 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -118,7 +118,7 @@ void menuProcSetup(uint8_t event) MENU(STR_MENURADIOSETUP, menuTabDiag, e_Setup, ITEM_SETUP_MAX+1, {0, 0, 0, AUDIO_ZEROS HAPTIC_ZEROS 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, SPLASH_ZEROS 0, 0, 0, 0, FRSKY_ZEROS 0, (uint8_t)-1, 1}); - int8_t sub = m_posVert; + int8_t sub = m_posVert; uint8_t y = 1*FH; uint8_t subN = 1; @@ -663,10 +663,7 @@ void menuProcDiagCalib(uint8_t event) } } - int16_t sum = 0; - for (uint8_t i=0; i<12; i++) - sum += g_eeGeneral.calibMid[i]; - g_eeGeneral.chkSum = sum; + g_eeGeneral.chkSum = evalChkSum(); break; } diff --git a/src/main_views.cpp b/src/main_views.cpp index 9d0cd9a4d..14edac1fd 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -323,5 +323,5 @@ void menuMainView(uint8_t event) } #endif - theFile.DisplayProgressBar(20*FW+1); + DISPLAY_PROGRESS_BAR(20*FW+1); } diff --git a/src/menus.cpp b/src/menus.cpp index 2ab32dda3..3a7bf7cd2 100644 --- a/src/menus.cpp +++ b/src/menus.cpp @@ -276,7 +276,7 @@ bool check(uint8_t event, uint8_t curr, const MenuFuncP *menuTab, uint8_t menuTa } #endif - theFile.DisplayProgressBar(menuTab ? lcd_lastPos-2*FW-((curr+1)/10*FWNUM)-2 : 20*FW+1); + DISPLAY_PROGRESS_BAR(menuTab ? lcd_lastPos-2*FW-((curr+1)/10*FWNUM)-2 : 20*FW+1); if (s_editMode<=0) { if (scrollUD) { diff --git a/src/model_menus.cpp b/src/model_menus.cpp index e1be7a7ef..d0659b352 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -378,7 +378,7 @@ void EditName(uint8_t x, uint8_t y, char *name, uint8_t size, uint8_t event, boo STORE_MODELVARS; } - switch(event) { + switch (event) { case EVT_KEY_BREAK(KEY_LEFT): if (next>0) next--; break; @@ -395,12 +395,13 @@ void EditName(uint8_t x, uint8_t y, char *name, uint8_t size, uint8_t event, boo #endif case EVT_KEY_LONG(KEY_LEFT): case EVT_KEY_LONG(KEY_RIGHT): - if (v>=-26 && v<=26) { - v = -v; // toggle case - STORE_MODELVARS; // TODO optim if (c!=v) at the end - if (event==EVT_KEY_LONG(KEY_LEFT)) - killEvents(KEY_LEFT); - } + if (v>=-26 && v<=26) { + v = -v; // toggle case + STORE_MODELVARS; // TODO optim if (c!=v) at the end + if (event==EVT_KEY_LONG(KEY_LEFT)) + killEvents(KEY_LEFT); + } + break; } name[cur] = v; @@ -418,7 +419,9 @@ void EditName(uint8_t x, uint8_t y, char *name, uint8_t size, uint8_t event, boo void menuProcModel(uint8_t event) { lcd_outdezNAtt(7*FW,0,g_eeGeneral.currModel+1,INVERS+LEADING0,2); - MENU(STR_MENUSETUP, menuTabModel, e_Model, (g_model.protocol==PROTO_PPM||g_model.protocol==PROTO_FAAST||g_model.protocol==PROTO_DSM2||g_model.protocol==PROTO_PXX ? 12 : 11), {0,ZCHAR|(sizeof(g_model.name)-1),2,2,0,0,0,0,0,6,2,1}); + + uint8_t protocol = g_model.protocol; + MENU(STR_MENUSETUP, menuTabModel, e_Model, (protocol==PROTO_PPM||protocol==PROTO_FAAST||protocol==PROTO_DSM2||protocol==PROTO_PXX ? 12 : 11), {0,ZCHAR|(sizeof(g_model.name)-1),2,2,0,0,0,0,0,6,2,1}); uint8_t sub = m_posVert; uint8_t y = 1*FH; @@ -428,7 +431,7 @@ void menuProcModel(uint8_t event) lcd_puts(0*FW, y, STR_NAME); EditName(PARAM_OFS, y, g_model.name, sizeof(g_model.name), event, sub==subN, m_posHorz); if((y+=FH)>7*FH) return; - }subN++; + } subN++; for (uint8_t i=0; i<2; i++) { TimerData *timer = &g_model.timers[i]; @@ -521,21 +524,17 @@ void menuProcModel(uint8_t event) if(s_pgOfs0 ? BLINK|INVERS : INVERS):0)); - if (g_model.protocol == PROTO_PPM || g_model.protocol == PROTO_FAAST) { + if (protocol == PROTO_PPM || protocol == PROTO_FAAST) { lcd_putsiAtt(PARAM_OFS+4*FW, y, STR_NCHANNELS, g_model.ppmNCH+2, (sub==subN && m_posHorz==1) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0); lcd_puts(PARAM_OFS+11*FW, y, PSTR("u")); lcd_outdezAtt(PARAM_OFS+11*FW, y, (g_model.ppmDelay*50)+300, ((sub==subN && m_posHorz==2) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0)); } #ifdef DSM2 - // TODO optimize that? - else if (g_model.protocol == PROTO_DSM2) { + else if (protocol == PROTO_DSM2) { if (m_posHorz > 1) m_posHorz = 1; - int8_t x; - x = g_model.ppmNCH; - if ( x < 0 ) x = 0; - if ( x > 2 ) x = 2; + int8_t x = limit((int8_t)0, (int8_t)g_model.ppmNCH, (int8_t)2); g_model.ppmNCH = x; lcd_putsiAtt(PARAM_OFS+5*FW, y, STR_DSM2MODE, x, (sub==subN && m_posHorz==1) ? ((s_editMode>0) ? BLINK|INVERS : INVERS) : 0); } @@ -543,14 +542,14 @@ void menuProcModel(uint8_t event) else if (sub==subN) { m_posHorz = 0; } - if (sub==subN && (s_editMode>0 || p1valdiff || (g_model.protocol!=PROTO_PPM && g_model.protocol!=PROTO_FAAST && g_model.protocol!=PROTO_DSM2))) { // TODO avoid DSM2 when not defined + if (sub==subN && (s_editMode>0 || p1valdiff || (protocol!=PROTO_PPM && protocol!=PROTO_FAAST && protocol!=PROTO_DSM2))) { // TODO avoid DSM2 when not defined switch (m_posHorz) { case 0: - CHECK_INCDEC_MODELVAR(event,g_model.protocol,0,PROTO_MAX-1); + CHECK_INCDEC_MODELVAR(event, g_model.protocol,0, PROTO_MAX-1); break; case 1: #ifdef DSM2 - if (g_model.protocol == PROTO_DSM2) + if (protocol == PROTO_DSM2) CHECK_INCDEC_MODELVAR(event, g_model.ppmNCH, 0, 2); else #endif @@ -565,7 +564,7 @@ void menuProcModel(uint8_t event) }subN++; if(s_pgOfs0 ? BLINK|INVERS : INVERS) : 0) | PREC1|LEFT); @@ -576,16 +575,16 @@ void menuProcModel(uint8_t event) CHECK_INCDEC_MODELVAR(event, g_model.ppmFrameLength, -20, 20); break; case 1: - CHECK_INCDEC_MODELVAR(event,g_model.pulsePol,0,1); + CHECK_INCDEC_MODELVAR(event, g_model.pulsePol, 0, 1); break; } } } // TODO port PPM16 ppmDelay from er9x #if defined(DSM2) || defined(PXX) - else if (g_model.protocol == PROTO_DSM2 || g_model.protocol == PROTO_PXX) { + else if (protocol == PROTO_DSM2 || protocol == PROTO_PXX) { lcd_putsLeft( y, STR_RXNUM); - lcd_outdezNAtt(PARAM_OFS-(g_model.protocol==PROTO_DSM2 ? 0 : 3*FW), y, g_model.modelId, ((sub==subN && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | LEADING0|LEFT, 2); + lcd_outdezNAtt(PARAM_OFS-(protocol==PROTO_DSM2 ? 0 : 3*FW), y, g_model.modelId, ((sub==subN && m_posHorz==0) ? (s_editMode>0 ? BLINK|INVERS : INVERS) : 0) | LEADING0|LEFT, 2); if (sub==subN && (s_editMode>0 || p1valdiff)) { switch (m_posHorz) { @@ -596,7 +595,7 @@ void menuProcModel(uint8_t event) } #if defined(PXX) - if (g_model.protocol == PROTO_PXX) { + if (protocol == PROTO_PXX) { lcd_putsAtt(PARAM_OFS, y, STR_SYNCMENU, ((sub==subN && m_posHorz==1) ? INVERS : 0)); if (sub==subN && m_posHorz==1) { s_editMode = false; @@ -829,7 +828,7 @@ void menuProcCurveOne(uint8_t event) TITLE(STR_MENUCURVE); lcd_outdezAtt(5*FW+1, 0, s_curveChan+1, INVERS|LEFT); - theFile.DisplayProgressBar(20*FW+1); + DISPLAY_PROGRESS_BAR(20*FW+1); if (s_curveChan >= MAX_CURVE5) { points = 9; diff --git a/src/open9x.cpp b/src/open9x.cpp index a74d0b3ca..8f98a07fb 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -525,16 +525,29 @@ void clearKeyEvents() putEvent(0); } +#define INAC_DEVISOR 256 // Bypass splash screen with stick movement +uint16_t stickMoveValue() +{ + uint16_t sum = 0; + for (uint8_t i=0; i<4; i++) + sum += anaIn(i)/INAC_DEVISOR; + return sum; +} + +void checkBacklight() +{ + if (getSwitch(g_eeGeneral.lightSw, 0) || g_eeGeneral.lightAutoOff) + BACKLIGHT_ON; + else + BACKLIGHT_OFF; +} + #ifdef SPLASH void doSplash() { if(!g_eeGeneral.disableSplashScreen) { - if(getSwitch(g_eeGeneral.lightSw,0) || g_eeGeneral.lightAutoOff) - BACKLIGHT_ON; - else - BACKLIGHT_OFF; - + checkBacklight() ; lcd_clear(); lcd_img(0, 0, s9xsplash,0,0); refreshDisplay(); @@ -546,14 +559,10 @@ void doSplash() getADC_filt(); // init ADC array #endif -#define INAC_DEVISOR 256 // Bypass splash screen with stick movement - uint16_t inacSum = 0; - // TODO uint16_t inacSum = stickMoveValue(); - for(uint8_t i=0; i<4; i++) - inacSum += anaIn(i)/INAC_DEVISOR; + uint16_t inacSum = stickMoveValue(); uint16_t tgtime = get_tmr10ms() + SPLASH_TIMEOUT; //2sec splash screen - while(tgtime != get_tmr10ms()) + while (tgtime != get_tmr10ms()) { #ifdef SIMU if (!main_thread_running) return; @@ -561,17 +570,11 @@ void doSplash() #else getADC_filt(); #endif - uint16_t tsum = 0; - for(uint8_t i=0; i<4; i++) - tsum += anaIn(i)/INAC_DEVISOR; + uint16_t tsum = stickMoveValue(); if(keyDown() || (tsum!=inacSum)) return; //wait for key release - // TODO check_backlight() ; - if(getSwitch(g_eeGeneral.lightSw,0) || g_eeGeneral.lightAutoOff) - BACKLIGHT_ON; - else - BACKLIGHT_OFF; + checkBacklight(); } } } @@ -635,10 +638,7 @@ void checkTHR() return; } - if(getSwitch(g_eeGeneral.lightSw,0) || g_eeGeneral.lightAutoOff) - BACKLIGHT_ON; - else - BACKLIGHT_OFF; + checkBacklight(); } } @@ -673,10 +673,7 @@ void checkSwitches() } if(i==SW_Trainer || keyDown()) return; - if(getSwitch(g_eeGeneral.lightSw,0) || g_eeGeneral.lightAutoOff) - BACKLIGHT_ON; - else - BACKLIGHT_OFF; + checkBacklight(); } } @@ -707,10 +704,10 @@ void alert(const pm_char * s, bool defaults) #endif if(keyDown()) return; //wait for key release - if(getSwitch(g_eeGeneral.lightSw,0) || g_eeGeneral.lightAutoOff || defaults) - BACKLIGHT_ON; - else - BACKLIGHT_OFF; + if (getSwitch(g_eeGeneral.lightSw,0) || g_eeGeneral.lightAutoOff || defaults) + BACKLIGHT_ON; + else + BACKLIGHT_OFF; wdt_reset(); } @@ -1269,10 +1266,12 @@ void perOut(uint8_t phase) v = getValue(k <= MIXSRC_3POS ? k : k-MAX_SWITCH); //========== DELAYS =============== + uint8_t swTog; if (sw) { // switch on? (if no switch selected => on) + swTog = !swOn[i]; + swOn[i] = true; if (md->delayUp) { - if (!swOn[i]) { - swOn[i] = true; + if (swTog) { sDelay[i] = md->delayUp * 100; } if (sDelay[i]) { // perform delay @@ -1285,15 +1284,15 @@ void perOut(uint8_t phase) } } } - swOn[i] = true; // TODO optim if (md->mixWarn) mixWarning |= 1<<(md->mixWarn-1); // Mix warning } else { bool has_delay = false; + swTog = swOn[i]; + swOn[i] = false; if (md->delayDown) { - if (swOn[i]) { + if (swTog) { sDelay[i] = md->delayDown * 100; - swOn[i] = false; } if (sDelay[i]) { // perform delay if(tick10ms) sDelay[i]--; @@ -1304,7 +1303,6 @@ void perOut(uint8_t phase) v = -1024; } } - swOn[i] = false; if (!has_delay) { if (md->speedDown) { if (md->mltpx==MLTPX_REP) continue; @@ -1721,10 +1719,7 @@ void perMain() if(g_LightOffCounter) g_LightOffCounter--; if(evt) g_LightOffCounter = g_eeGeneral.lightAutoOff*500; // on keypress turn the light on 5*100 - if( getSwitch(g_eeGeneral.lightSw,0) || g_LightOffCounter) - BACKLIGHT_ON; - else - BACKLIGHT_OFF; + checkBacklight(); g_menuStack[g_menuStackPtr](evt); refreshDisplay(); diff --git a/src/pers.cpp b/src/pers.cpp index 99ccf64d6..19bd80fe5 100644 --- a/src/pers.cpp +++ b/src/pers.cpp @@ -50,14 +50,21 @@ void generalDefault() g_eeGeneral.chkSum = (0x200 * 7) + (0x180 * 5); } +uint16_t evalChkSum() +{ + uint16_t sum=0; + for (int i=0; i<12;i++) + sum += g_eeGeneral.calibMid[i]; + return sum; +} + bool eeLoadGeneral() { theFile.openRlc(FILE_GENERAL); if (theFile.readRlc((uint8_t*)&g_eeGeneral, 1) == 1 && g_eeGeneral.myVers == EEPROM_VER) { theFile.openRlc(FILE_GENERAL); // TODO include this openRlc inside readRlc if (theFile.readRlc((uint8_t*)&g_eeGeneral, sizeof(g_eeGeneral)) <= sizeof(EEGeneral)) { - uint16_t sum=0; - for (int i=0; i<12;i++) sum += g_eeGeneral.calibMid[i]; + uint16_t sum = evalChkSum(); if (g_eeGeneral.chkSum == sum) { return true; }