changeset 190:cca59de24fe0

Merged in janlmulder/ostc4/avg-temp (pull request #6) Bugfix: average temperature on arrival from RTE instead of display time
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Fri, 15 Mar 2019 15:48:53 +0000
parents ddc21166d25b (current diff) 8b8074080d7b (diff)
children cdbdb4458520 05df3b395615 d328abe2e44e
files
diffstat 4 files changed, 19 insertions(+), 430 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/data_exchange_main.c	Fri Mar 15 12:55:58 2019 +0000
+++ b/Discovery/Src/data_exchange_main.c	Fri Mar 15 15:48:53 2019 +0000
@@ -771,6 +771,20 @@
 	return (depth[0] + depth[1] + depth[2] + depth[3])/4.0f;
 }
 
+#define TEMP_AVERAGE_COUNT	3
+static float getTemperature(SDataExchangeSlaveToMaster *d)
+{
+	static uint8_t c = 0;
+	static float temp[TEMP_AVERAGE_COUNT] = {0};
+
+	temp[c] = d->data[d->boolPressureData].temperature;
+
+	c++;
+	if (c == TEMP_AVERAGE_COUNT) c = 0;
+
+	return (temp[0] + temp[1] + temp[2])/3.0f;
+}
+
 void DataEX_copy_to_LifeData(_Bool *modeChangeFlag)
 {
 	SDiveState *pStateReal = stateRealGetPointerWrite();
@@ -937,7 +951,7 @@
 			pStateReal->lifeData.depth_meter = meter;
 		}
 
-		pStateReal->lifeData.temperature_celsius = dataIn.data[dataIn.boolPressureData].temperature;
+		pStateReal->lifeData.temperature_celsius = getTemperature(&dataIn);
 		pStateReal->lifeData.ascent_rate_meter_per_min = dataIn.data[dataIn.boolPressureData].ascent_rate_meter_per_min;
 		if(pStateReal->mode != MODE_DIVE)
 			pStateReal->lifeData.max_depth_meter = 0;
--- a/Discovery/Src/t3.c	Fri Mar 15 12:55:58 2019 +0000
+++ b/Discovery/Src/t3.c	Fri Mar 15 15:48:53 2019 +0000
@@ -52,9 +52,6 @@
 GFX_DrawCfgWindow	t3c1;
 GFX_DrawCfgWindow	t3c2;
 
-extern float temperatureLastCall[3];
-extern uint8_t idTemperatureLastCall;
-
 uint8_t t3_selection_customview = 0;
 
 /* TEM HAS TO MOVE TO GLOBAL--------------------------------------------------*/
@@ -507,7 +504,6 @@
     uint16_t textpointer = 0;
 
     // CVIEW_T3_Temperature
-    float temperatureThisCall;
     float temperature;
 
     SDivetime TotalDivetime = {0,0,0,0};
@@ -527,13 +523,7 @@
         snprintf(text,TEXTSIZE,"\032\f%c",TXT_Temperature);
         GFX_write_string(&FontT42,tXc1,text,0);
 
-        // mean value
-        temperatureThisCall = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
-        temperature = (temperatureThisCall + temperatureLastCall[0] + temperatureLastCall[1] + temperatureLastCall[2]) / 4.0f;
-        idTemperatureLastCall++;
-        if(idTemperatureLastCall >= 3)
-            idTemperatureLastCall = 0;
-        temperatureLastCall[idTemperatureLastCall] = temperatureThisCall;
+        temperature = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
         textpointer = snprintf(text,TEXTSIZE,"\020\003\016%01.0f\016\016\140",temperature); // "\016\016%01.1f `" + C or F
         if(settingsGetPointer()->nonMetricalSystem == 0)
             text[textpointer++] = 'C';
@@ -606,7 +596,6 @@
     uint8_t oxygen_percentage = 0;
 
     // CVIEW_T3_Temperature
-    float temperatureThisCall;
     float temperature;
 
     // CVIEW_T3_GasList
@@ -619,7 +608,6 @@
     SDivetime Stopwatch = {0,0,0,0};
     float fAverageDepth, fAverageDepthAbsolute;
 
-
     uint16_t tempWinX0;
     uint16_t tempWinX1;
     uint16_t tempWinY0;
@@ -749,13 +737,8 @@
     case CVIEW_T3_Temperature:
         snprintf(text,TEXTSIZE,"\032\f%c",TXT_Temperature);
         GFX_write_string(&FontT42,tXc1,text,0);
-        // mean value
-        temperatureThisCall = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
-        temperature = (temperatureThisCall + temperatureLastCall[0] + temperatureLastCall[1] + temperatureLastCall[2]) / 4.0f;
-        idTemperatureLastCall++;
-        if(idTemperatureLastCall >= 3)
-            idTemperatureLastCall = 0;
-        temperatureLastCall[idTemperatureLastCall] = temperatureThisCall;
+
+        temperature = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
         textpointer = snprintf(text,TEXTSIZE,"\030\003\016%01.1f \140",temperature); // "\016\016%01.1f `" + C or F
         if(settingsGetPointer()->nonMetricalSystem == 0)
             text[textpointer++] = 'C';
--- a/Discovery/Src/t6_apnea.c	Fri Mar 15 12:55:58 2019 +0000
+++ b/Discovery/Src/t6_apnea.c	Fri Mar 15 15:48:53 2019 +0000
@@ -74,8 +74,6 @@
 void t6_refresh_customview(float depth);
 
 uint8_t t6_test_customview_warnings(void);
-void t6_show_customview_warnings(void);
-void t6_compass(uint16_t ActualHeading, uint16_t UserSetHeading);
 
 /* Exported functions --------------------------------------------------------*/
 
@@ -331,398 +329,3 @@
     count = 0;
     return count;
 }
-
-/*
-
-    char text[512];
-    uint16_t textpointer = 0;
-
-
-    // CVIEW_T3_Temperature
-    float temperatureThisCall;
-    float temperature;
-
-
-    // CVIEW_T3_StopWatch
-    SDivetime Stopwatch = {0,0,0,0};
-    float fAverageDepth, fAverageDepthAbsolute;
-    uint16_t tempWinX0;
-    uint16_t tempWinY0;
-
-    switch(t6_selection_customview)
-    {
-        case CVIEW_T3_ApnoeTimes:
-        break;
-
-        case CVIEW_T3_StopWatch:
-            Stopwatch.Total = timer_Stopwatch_GetTime();
-            Stopwatch.Minutes = Stopwatch.Total / 60;
-            Stopwatch.Seconds = Stopwatch.Total - ( Stopwatch.Minutes * 60 );
-            fAverageDepth = timer_Stopwatch_GetAvarageDepth_Meter();
-            fAverageDepthAbsolute = stateUsed->lifeData.average_depth_meter;
-
-            snprintf(text,TEXTSIZE,"\032\f%c",TXT_AvgDepth);
-            GFX_write_string(&FontT42,&t6c1,text,0);
-            snprintf(text,TEXTSIZE,"\030\003\016%01.1f",fAverageDepthAbsolute);
-            GFX_write_string(&FontT105,&t6c1,text,0);
-
-            tempWinX0 = t6c1.WindowX0;
-            tempWinY0 = t6c1.WindowY0;
-            t6c1.WindowX0 = 480;
-//			snprintf(text,TEXTSIZE,"\032\f%c%c - %c",TXT_2BYTE, TXT2BYTE_Clock, TXT_AvgDepth);
-            snprintf(text,TEXTSIZE,"\032\f%c", TXT_Stopwatch);
-            GFX_write_string(&FontT42,&t6c1,text,0);
-            snprintf(text,TEXTSIZE,"\030\016%01.1f",fAverageDepth);
-            GFX_write_string(&FontT105,&t6c1,text,0);
-            t6c1.WindowY0 = 100;
-            snprintf(text,TEXTSIZE,"\030%u:\016\016%02u",Stopwatch.Minutes, Stopwatch.Seconds);
-            GFX_write_string(&FontT105,&t6c1,text,0);
-            t6c1.WindowX0 = tempWinX0;
-            t6c1.WindowY0 = tempWinY0;
-        break;
-
-        case CVIEW_T3_Temperature:
-            snprintf(text,TEXTSIZE,"\032\f%c",TXT_Temperature);
-            GFX_write_string(&FontT42,&t6c1,text,0);
-            // mean value
-            temperatureThisCall = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
-            temperature = (temperatureThisCall + temperatureLastCall[0] + temperatureLastCall[1] + temperatureLastCall[2]) / 4.0f;
-            idTemperatureLastCall++;
-            if(idTemperatureLastCall >= 3)
-                idTemperatureLastCall = 0;
-            temperatureLastCall[idTemperatureLastCall] = temperatureThisCall;
-            textpointer = snprintf(text,TEXTSIZE,"\030\003\016%01.1f \140",temperature); // "\016\016%01.1f `" + C or F
-            if(settingsGetPointer()->nonMetricalSystem == 0)
-                text[textpointer++] = 'C';
-            else
-                text[textpointer++] = 'F';
-            text[textpointer++] = 0;
-            GFX_write_string(&FontT105,&t6c1,text,0);
-        break;
-
-        case CVIEW_Compass:
-            snprintf(text,TEXTSIZE,"\032\f%c%c",TXT_2BYTE, TXT2BYTE_Compass);
-            GFX_write_string(&FontT42,&t6c1,text,0);
-            snprintf(text,100,"\030\003%03i`",(uint16_t)stateUsed->lifeData.compass_heading);
-            GFX_write_string(&FontT105,&t6c1,text,0);
-            t6_compass((uint16_t)stateUsed->lifeData.compass_heading, stateUsed->diveSettings.compassHeading);
-        break;
-
-        case CVIEW_T3_MaxDepth:
-        default:
-            snprintf(text,TEXTSIZE,"\032\f%c",TXT_MaxDepth);
-            GFX_write_string(&FontT42,&t6c1,text,0);
-            snprintf(text,TEXTSIZE,"\020\003\016%01.1f",unit_depth_float(stateUsed->lifeData.max_depth_meter));
-            t3_basics_colorscheme_mod(text);
-            GFX_write_string(&FontT105,&t6c1,text,1);
-            break;
-    }
-}
-
-
-void t6_show_customview_warnings(void)
-{
-    char text[256], textMain[256];
-    uint8_t textpointer, textpointerMain, lineFree, more;
-
-    snprintf(text,TEXTSIZE,"\025\f%c",TXT_Warning);
-    GFX_write_string(&FontT42,&t6c1,text,0);
-
-    lineFree = 1;
-    more = 0;
-
-    textpointerMain = 0;
-    textMain[textpointerMain++] = '\025';
-    textMain[textpointerMain++] = '\003';
-
-    textpointer = 0;
-
-    text[textpointer++] = '\021';
-    text[textpointer++] = TXT_2BYTE;
-    text[textpointer++] = TXT2BYTE_WarnDecoMissed;
-    if(stateUsed->warnings.decoMissed)
-    {
-        text[textpointer - 3] =  '\025';
-        if(lineFree)
-        {
-            textMain[textpointerMain++] = TXT_2BYTE;
-            textMain[textpointerMain++] = text[textpointer - 1];
-            textMain[textpointerMain] = 0;
-            lineFree--;
-        }
-        else
-        {
-            more++;
-        }
-    }
-
-    text[textpointer++] = '\t';
-    text[textpointer++] = '\021';
-    text[textpointer++] = TXT_2BYTE;
-    text[textpointer++] = TXT2BYTE_WarnPPO2Low;
-    if(stateUsed->warnings.ppO2Low)
-    {
-        text[textpointer - 3] =  '\025';
-        if(lineFree)
-        {
-            textMain[textpointerMain++] = TXT_2BYTE;
-            textMain[textpointerMain++] = text[textpointer - 1];
-            textMain[textpointerMain] = 0;
-            lineFree--;
-        }
-        else
-        {
-            more++;
-        }
-    }
-
-    text[textpointer++] = '\n';
-    text[textpointer++] = '\r';
-    text[textpointer++] = '\021';
-    text[textpointer++] = TXT_2BYTE;
-    text[textpointer++] = TXT2BYTE_WarnPPO2High;
-    if(stateUsed->warnings.ppO2High)
-    {
-        text[textpointer - 3] =  '\025';
-        if(lineFree)
-        {
-            textMain[textpointerMain++] = TXT_2BYTE;
-            textMain[textpointerMain++] = text[textpointer - 1];
-            textMain[textpointerMain] = 0;
-            lineFree--;
-        }
-        else
-        {
-            more++;
-        }
-    }
-
-    text[textpointer++] = '\t';
-    text[textpointer++] = '\021';
-    text[textpointer++] = TXT_2BYTE;
-    text[textpointer++] = TXT2BYTE_WarnFallback;
-    if(stateUsed->warnings.fallback)
-    {
-        text[textpointer - 3] =  '\025';
-        if(lineFree)
-        {
-            textMain[textpointerMain++] = TXT_2BYTE;
-            textMain[textpointerMain++] = text[textpointer - 1];
-            textMain[textpointerMain] = 0;
-            lineFree--;
-        }
-        else
-        {
-            more++;
-        }
-    }
-
-    text[textpointer++] = '\n';
-    text[textpointer++] = '\r';
-    text[textpointer++] = '\021';
-    text[textpointer++] = TXT_2BYTE;
-    text[textpointer++] = TXT2BYTE_WarnSensorLinkLost;
-    if(stateUsed->warnings.sensorLinkLost)
-    {
-        text[textpointer - 3] =  '\025';
-        if(lineFree)
-        {
-            textMain[textpointerMain++] = TXT_2BYTE;
-            textMain[textpointerMain++] = text[textpointer - 1];
-            textMain[textpointerMain] = 0;
-            lineFree--;
-        }
-        else
-        {
-            more++;
-        }
-    }
-
-    text[textpointer] = 0;
-    GFX_write_string(&FontT48,&t6c1,textMain,1);
-    if(more)
-    {
-        GFX_write_string(&FontT48,&t6c2,text,1);
-    }
-}
-
-
-void t6_change_customview(void)
-{
-    const uint8_t *pViews;
-    pViews = t6_customviews;
-
-    while((*pViews != CVIEW_T3_END) && (*pViews != t6_selection_customview))
-        {pViews++;}
-
-    if(*pViews < CVIEW_T3_END)
-        pViews++;
-
-    if(*pViews == CVIEW_T3_END)
-    {
-        t6_selection_customview = t6_customviews[0];
-    }
-    else
-        t6_selection_customview = *pViews;
-}
-
-
-void t3_basics_colorscheme_mod(char *text)
-{
-    if((text[0] == '\020') && !GFX_is_colorschemeDiveStandard())
-    {
-        text[0] = '\027';
-    }
-}
-
-point_t t6_compass_circle(uint8_t id, uint16_t degree)
-{
-    float fCos, fSin;
-    const float piMult =  ((2 * 3.14159) / 360);
-//	const int radius[4] = {95,105,115,60};
-    const int radius[4] = {85,95,105,90};
-    const point_t offset = {.x = 600, .y = 116};
-
-    static point_t r[4][360] = { 0 };
-
-    if(r[0][0].y == 0)
-    {
-        for(int i=0;i<360;i++)
-        {
-            fCos = cos(i * piMult);
-            fSin = sin(i * piMult);
-            for(int j=0;j<4;j++)
-            {
-                r[j][i].x = offset.x + (int)(fSin * radius[j]);
-                r[j][i].y = offset.y + (int)(fCos * radius[j]);
-            }
-        }
-    }
-    if(id > 3) id = 0;
-    if(degree > 359) degree = 0;
-    return r[id][degree];
-}
-
-
-void t6_compass(uint16_t ActualHeading, uint16_t UserSetHeading)
-{
-    uint16_t LineHeading;
-    point_t center;
-    static int32_t LastHeading = 0;
-    int32_t newHeading = 0;
-    int32_t diff = 0;
-    int32_t diff2 = 0;
-
-    int32_t diffAbs = 0;
-    int32_t diffAbs2 = 0;
-
-    newHeading = ActualHeading;
-
-    diff = newHeading - LastHeading;
-
-    if(newHeading < LastHeading)
-        diff2 = newHeading + 360 - LastHeading;
-    else
-        diff2 = newHeading - 360 - LastHeading;
-
-    diffAbs = diff;
-    if(diffAbs < 0)
-        diffAbs *= -1;
-
-    diffAbs2 = diff2;
-    if(diffAbs2 < 0)
-        diffAbs2 *= -1;
-
-
-    if(diffAbs <= diffAbs2)
-        newHeading = LastHeading + (diff / 2);
-    else
-        newHeading = LastHeading + (diff2 / 2);
-
-    if(newHeading < 0)
-        newHeading += 360;
-    else
-    if(newHeading >= 360)
-        newHeading -= 360;
-
-    LastHeading = newHeading;
-    ActualHeading = newHeading;
-
-    if (ActualHeading < 90)
-        ActualHeading += 360;
-
-    while(ActualHeading > 359) ActualHeading -= 360;
-
-    LineHeading = 360 - ActualHeading;
-    GFX_draw_thick_line(9,&t6screen, t6_compass_circle(0,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font030); // North
-    LineHeading += 90;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031); // Maintick
-    LineHeading += 90;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 90;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(9,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-
-    LineHeading = 360 - ActualHeading;
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
-    LineHeading += 90;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 90;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 90;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(5,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-
-    LineHeading = 360 - ActualHeading;
-    LineHeading += 22;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031); // Subtick
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-    LineHeading += 45;
-    if(LineHeading > 359) LineHeading -= 360;
-    GFX_draw_thick_line(3,&t6screen, t6_compass_circle(1,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_Font031);
-
-    if(UserSetHeading)
-    {
-        LineHeading = UserSetHeading + 360 - ActualHeading;
-        if(LineHeading > 359) LineHeading -= 360;
-        GFX_draw_thick_line(9,&t6screen, t6_compass_circle(3,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_CompassUserHeadingTick);
-
-        // R�ckpeilung, User Back Heading
-        LineHeading = UserSetHeading + 360 + 180 - ActualHeading;
-        if(LineHeading > 359) LineHeading -= 360;
-        if(LineHeading > 359) LineHeading -= 360;
-        GFX_draw_thick_line(9,&t6screen, t6_compass_circle(3,LineHeading),  t6_compass_circle(2,LineHeading), CLUT_CompassUserBackHeadingTick);
-    }
-
-    center.x = 600;
-    center.y = 116;
-    GFX_draw_circle(&t6screen, center, 106, CLUT_Font030);
-    GFX_draw_circle(&t6screen, center, 107, CLUT_Font030);
-    GFX_draw_circle(&t6screen, center, 108, CLUT_Font030);
-}
-*/
-
--- a/Discovery/Src/t7.c	Fri Mar 15 12:55:58 2019 +0000
+++ b/Discovery/Src/t7.c	Fri Mar 15 15:48:53 2019 +0000
@@ -74,8 +74,6 @@
 /* Exported variables --------------------------------------------------------*/
 
 /* Private variables ---------------------------------------------------------*/
-float temperatureLastCall[3] = { 0,0,0};
-uint8_t idTemperatureLastCall = 0;
 
 GFX_DrawCfgScreen	t7screen;
 GFX_DrawCfgScreen	t7screenCompass;
@@ -2472,8 +2470,6 @@
     const SDecoinfo * pDecoinfoStandard;
     const SDecoinfo * pDecoinfoFuture;
     float fCNS;
-
-    float temperatureThisCall;
     float temperature;
 
     if(stateUsed->diveSettings.deco_type.ub.standard == GF_MODE)
@@ -2501,14 +2497,7 @@
     /* Temperature */
     case 1:
     default:
-        // mean value
-        temperatureThisCall = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
-        temperature = (temperatureThisCall + temperatureLastCall[0] + temperatureLastCall[1] + temperatureLastCall[2]) / 4.0f;
-        idTemperatureLastCall++;
-        if(idTemperatureLastCall >= 3)
-            idTemperatureLastCall = 0;
-        temperatureLastCall[idTemperatureLastCall] = temperatureThisCall;
-        // output
+    	temperature = unit_temperature_float(stateUsed->lifeData.temperature_celsius);
         headerText[2] = TXT_Temperature;
         textpointer = snprintf(text,TEXTSIZE,"\020\016%01.1f \140",temperature); // "\016\016%01.1f `" + C or F
         if(settingsGetPointer()->nonMetricalSystem == 0)