# HG changeset patch # User heinrichsweikamp # Date 1552403059 0 # Node ID 458f16cda15ca695dcda366ee24eea8e2bca1735 # Parent c659fda83e44e08245f63de52ef4865c2473c5f5# Parent 1719b9d1094b0a180986e26e07cb3c8b8a70fe22 Merged in janlmulder/ostc4/max-depth (pull request #3) Bugfix: make max depth move with current depth Approved-by: heinrichsweikamp diff -r c659fda83e44 -r 458f16cda15c Discovery/Src/data_exchange_main.c --- a/Discovery/Src/data_exchange_main.c Sun Mar 10 20:30:42 2019 +0100 +++ b/Discovery/Src/data_exchange_main.c Tue Mar 12 15:04:19 2019 +0000 @@ -73,7 +73,7 @@ #include "externLogbookFlash.h" -/* Expoted variables --------------------------------------------------------*/ +/* Exported variables --------------------------------------------------------*/ uint8_t wasPowerOn = 0; confirmbit8_Type requestNecessary = { .uw = 0 }; uint8_t wasUpdateNotPowerOn = 0; @@ -749,10 +749,31 @@ } } +#define AVERAGE_COUNT 4 +static float getSampleDepth(SDataExchangeSlaveToMaster *d, SDiveState *ds) +{ + static uint8_t c = 0; + static float ambient[AVERAGE_COUNT] = {0}; + static float surface[AVERAGE_COUNT]= {0}; + static float depth[AVERAGE_COUNT]= {0}; + + ambient[c] = d->data[d->boolPressureData].pressure_mbar / 1000.0f; + surface[c] = d->data[d->boolPressureData].surface_mbar / 1000.0f; + float density = ((float)( 100 + settingsGetPointer()->salinity)) / 100.0f; + + ds->lifeData.pressure_ambient_bar = (ambient[0] + ambient[1] + ambient[2] + ambient[3])/4.0f; + ds->lifeData.pressure_surface_bar = (surface[0] + surface[1] + surface[2] + surface[3])/4.0f; + depth[c] = (ambient[c] - surface[c]) / (0.09807f * density); + + c++; + if (c == AVERAGE_COUNT) c = 0; + + return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f; +} void DataEX_copy_to_LifeData(_Bool *modeChangeFlag) { - SDiveState * pStateReal = stateRealGetPointerWrite(); + SDiveState *pStateReal = stateRealGetPointerWrite(); static uint16_t getDeviceDataAfterStartOfMainCPU = 20; /* internal sensor: HUD data @@ -780,12 +801,6 @@ } } -/* Why? hw 8.6.2015 - if(DataEX_check_header_and_footer_ok() && dataIn.power_on_reset) - { - return; - } -*/ if(!DataEX_check_header_and_footer_ok()) { if(DataEX_check_header_and_footer_devicedata()) @@ -838,22 +853,11 @@ { setButtonResponsiveness(settingsGetPointer()->ButtonResponsiveness); } -/* - } - if((dataIn.confirmRequest.ub.clearDeco != 1) && (requestNecessary.ub.clearDeco == 1)) - { - clearDeco(); // is dataOut.clearDecoNow = 1; - } -*/ } requestNecessary.uw = 0; // clear all - float ambient, surface, density, meter; + float meter = 0; SSettings *pSettings; - - ambient = 0; - surface = 0; - meter = 0; /* uint8_t IAmStolenPleaseKillMe; */ @@ -869,20 +873,11 @@ if(pStateReal->data_old__lost_connection_to_slave == 0) { - ambient = dataIn.data[dataIn.boolPressureData].pressure_mbar / 1000.0f; - surface = dataIn.data[dataIn.boolPressureData].surface_mbar / 1000.0f; - - density = ((float)( 100 + pSettings->salinity)) / 100.0f; - meter = (ambient - surface); - meter /= (0.09807f * density); - + meter = getSampleDepth(&dataIn, pStateReal); pStateReal->pressure_uTick_old = pStateReal->pressure_uTick_new; pStateReal->pressure_uTick_new = dataIn.data[dataIn.boolPressureData].pressure_uTick; pStateReal->pressure_uTick_local_new = HAL_GetTick(); - - /* what was the code behind this if statement ? */ - /* if(ambient < (surface + 0.04f)) */ pStateReal->lifeData.dateBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_dr; pStateReal->lifeData.timeBinaryFormat = dataIn.data[dataIn.boolTimeData].localtime_rtc_tr; @@ -933,8 +928,6 @@ pStateReal->mode = dataIn.mode; pStateReal->chargeStatus = dataIn.chargeStatus; - pStateReal->lifeData.pressure_ambient_bar = ambient; - pStateReal->lifeData.pressure_surface_bar = surface; if(is_ambient_pressure_close_to_surface(&pStateReal->lifeData)) { pStateReal->lifeData.depth_meter = 0; @@ -972,7 +965,6 @@ if (pStateReal->lifeData.compass_heading < 0) pStateReal->lifeData.compass_heading +=360.0; } - pStateReal->lifeData.compass_roll = dataIn.data[dataIn.boolCompassData].compass_roll; pStateReal->lifeData.compass_pitch = dataIn.data[dataIn.boolCompassData].compass_pitch; @@ -1056,7 +1048,7 @@ { pStateReal->lifeData.apnea_last_max_depth_meter = pStateReal->lifeData.max_depth_meter; } - // eset max_depth_meter, average_depth_meter and internal values + // reset max_depth_meter, average_depth_meter and internal values pStateReal->lifeData.max_depth_meter = 0; pStateReal->lifeData.boolResetAverageDepth = 1; pStateReal->lifeData.boolResetStopwatch = 1; diff -r c659fda83e44 -r 458f16cda15c Discovery/Src/simulation.c --- a/Discovery/Src/simulation.c Sun Mar 10 20:30:42 2019 +0100 +++ b/Discovery/Src/simulation.c Tue Mar 12 15:04:19 2019 +0000 @@ -616,7 +616,6 @@ { // ascent time timeThis = ((float)(actualDepthPoint - nextDepthPoint)) / sim_ascent_rate_meter_per_min_local; - actualDepthPoint = actualDepthPoint; // that is where we are // deco stop time for(ptrDecoInfo=0;ptrDecoInfo < DECOINFO_STRUCT_MAX_STOPS; ptrDecoInfo++) diff -r c659fda83e44 -r 458f16cda15c Discovery/Src/t3.c --- a/Discovery/Src/t3.c Sun Mar 10 20:30:42 2019 +0100 +++ b/Discovery/Src/t3.c Tue Mar 12 15:04:19 2019 +0000 @@ -52,8 +52,6 @@ GFX_DrawCfgWindow t3c1; GFX_DrawCfgWindow t3c2; -extern float depthLastCall[9]; -extern uint8_t idDepthLastCall; extern float temperatureLastCall[3]; extern uint8_t idTemperatureLastCall; @@ -210,28 +208,8 @@ stop.x = start.x = BigFontSeperationLeftRight; GFX_draw_line(tXscreen, start, stop, CLUT_Font020); - /* depth */ - float depth = 0; - float depthThisCall = unit_depth_float(stateUsed->lifeData.depth_meter); - if(is_stateUsedSetToSim()) - { - depth = (depthThisCall + depthLastCall[0] + depthLastCall[1] + depthLastCall[2] + depthLastCall[3] + depthLastCall[4] + depthLastCall[5] + depthLastCall[6] + depthLastCall[7] + depthLastCall[8]) / 10.0f; - - idDepthLastCall++; - if(idDepthLastCall >= 9) - idDepthLastCall = 0; - depthLastCall[idDepthLastCall] = depthThisCall; - } - else - { - depth = (depthThisCall + depthLastCall[0] + depthLastCall[1] + depthLastCall[2]) / 4.0f; - - idDepthLastCall++; - if(idDepthLastCall >= 3) - idDepthLastCall = 0; - depthLastCall[idDepthLastCall] = depthThisCall; - } + float depth = unit_depth_float(stateUsed->lifeData.depth_meter); if(depth <= 0.3f) depth = 0; diff -r c659fda83e44 -r 458f16cda15c Discovery/Src/t4_tetris.c --- a/Discovery/Src/t4_tetris.c Sun Mar 10 20:30:42 2019 +0100 +++ b/Discovery/Src/t4_tetris.c Tue Mar 12 15:04:19 2019 +0000 @@ -45,12 +45,6 @@ GFX_DrawCfgWindow t4l2; GFX_DrawCfgWindow t4l3; -extern float depthLastCall[9]; -extern uint8_t idDepthLastCall; -extern float temperatureLastCall[3]; -extern uint8_t idTemperatureLastCall; - - /* Private types -------------------------------------------------------------*/ #define TEXTSIZE 16 @@ -60,11 +54,6 @@ /* Private function prototypes -----------------------------------------------*/ void t4_refresh_divemode(void); -void t4_refresh_customview(float depth); - -uint8_t t4_test_customview_warnings(void); -void t4_show_customview_warnings(void); -void t4_battery_low_customview_extra(void); /* Exported functions --------------------------------------------------------*/ @@ -150,26 +139,7 @@ // depth - float depth = 0; - float depthThisCall = unit_depth_float(stateUsed->lifeData.depth_meter); - if(is_stateUsedSetToSim()) - { - depth = (depthThisCall + depthLastCall[0] + depthLastCall[1] + depthLastCall[2] + depthLastCall[3] + depthLastCall[4] + depthLastCall[5] + depthLastCall[6] + depthLastCall[7] + depthLastCall[8]) / 10.0f; - - idDepthLastCall++; - if(idDepthLastCall >= 9) - idDepthLastCall = 0; - depthLastCall[idDepthLastCall] = depthThisCall; - } - else - { - depth = (depthThisCall + depthLastCall[0] + depthLastCall[1] + depthLastCall[2]) / 4.0f; - - idDepthLastCall++; - if(idDepthLastCall >= 3) - idDepthLastCall = 0; - depthLastCall[idDepthLastCall] = depthThisCall; - } + float depth = unit_depth_float(stateUsed->lifeData.depth_meter); if(depth <= 0.3f) depth = 0; diff -r c659fda83e44 -r 458f16cda15c Discovery/Src/t5_gauge.c --- a/Discovery/Src/t5_gauge.c Sun Mar 10 20:30:42 2019 +0100 +++ b/Discovery/Src/t5_gauge.c Tue Mar 12 15:04:19 2019 +0000 @@ -47,11 +47,6 @@ GFX_DrawCfgWindow t5c2; GFX_DrawCfgWindow t5c3; // for menu text -extern float depthLastCall[9]; -extern uint8_t idDepthLastCall; -extern float temperatureLastCall[3]; -extern uint8_t idTemperatureLastCall; - uint8_t t5_selection_customview = 0; /* Importend function prototypes ---------------------------------------------*/ diff -r c659fda83e44 -r 458f16cda15c Discovery/Src/t6_apnea.c --- a/Discovery/Src/t6_apnea.c Sun Mar 10 20:30:42 2019 +0100 +++ b/Discovery/Src/t6_apnea.c Tue Mar 12 15:04:19 2019 +0000 @@ -46,15 +46,9 @@ GFX_DrawCfgWindow t6c2; GFX_DrawCfgWindow t6c3; // for menu text -extern float depthLastCall[9]; -extern uint8_t idDepthLastCall; -extern float temperatureLastCall[3]; -extern uint8_t idTemperatureLastCall; - uint8_t t6_selection_customview = 0; /* Importend function prototypes ---------------------------------------------*/ -extern uint8_t write_gas(char *text, uint8_t oxygen, uint8_t helium); /* Private types -------------------------------------------------------------*/ diff -r c659fda83e44 -r 458f16cda15c Discovery/Src/t7.c --- a/Discovery/Src/t7.c Sun Mar 10 20:30:42 2019 +0100 +++ b/Discovery/Src/t7.c Tue Mar 12 15:04:19 2019 +0000 @@ -2012,26 +2012,7 @@ } /* depth */ - float depth = 0; - float depthThisCall = unit_depth_float(stateUsed->lifeData.depth_meter); - if(is_stateUsedSetToSim()) - { - depth = (depthThisCall + depthLastCall[0] + depthLastCall[1] + depthLastCall[2] + depthLastCall[3] + depthLastCall[4] + depthLastCall[5] + depthLastCall[6] + depthLastCall[7] + depthLastCall[8]) / 10.0f; - - idDepthLastCall++; - if(idDepthLastCall >= 9) - idDepthLastCall = 0; - depthLastCall[idDepthLastCall] = depthThisCall; - } - else - { - depth = (depthThisCall + depthLastCall[0] + depthLastCall[1] + depthLastCall[2]) / 4.0f; - - idDepthLastCall++; - if(idDepthLastCall >= 3) - idDepthLastCall = 0; - depthLastCall[idDepthLastCall] = depthThisCall; - } + float depth = unit_depth_float(stateUsed->lifeData.depth_meter); if(depth <= 0.3f) depth = 0;