changeset 653:269e57ac4e56

Bugfix temperature display Logpage2: Temperature was shown in Centidegrees (Fahrenheit as well as Celsius). Root cause was that conversion was done via character cutting (string: removal of last digit). This has been replaced by a factor 10 devision.
author Ideenmodellierer
date Sun, 25 Apr 2021 20:36:18 +0200
parents f6212495f34f
children 890440ab993a
files Discovery/Inc/unit.h Discovery/Src/show_logbook.c Discovery/Src/unit.c
diffstat 3 files changed, 11 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Inc/unit.h	Mon Apr 19 20:34:53 2021 +0200
+++ b/Discovery/Inc/unit.h	Sun Apr 25 20:36:18 2021 +0200
@@ -46,7 +46,7 @@
 float unit_depth_float(float input_meter);
 uint16_t unit_depth_integer(uint16_t input_meter);
 float unit_temperature_float(float input_celsius);
-uint16_t unit_temperature_integer(uint16_t input_celsius);
+int16_t unit_temperature_integer(int16_t input_celsius);
 uint16_t unit_speed_integer(uint16_t input_meterPerMinute);
 int unit_SeaLevelRelation_integer(int input_atmospheric_mbar);
 char unit_depth_char1(void);
--- a/Discovery/Src/show_logbook.c	Mon Apr 19 20:34:53 2021 +0200
+++ b/Discovery/Src/show_logbook.c	Sun Apr 25 20:36:18 2021 +0200
@@ -774,6 +774,7 @@
     int newBottom = 0;
     uint16_t step = 0;
     int16_t maxValTop = 0;
+    int16_t tmp = 0;
 
     scaleHelper(dataLength, tempdata, wintemp.top, wintemp.bottom,
                             &minVal, &maxVal, &newTop, &newBottom,
@@ -786,25 +787,18 @@
     // temperature in 1/10 �C
     int deltaline = (1 + wintemp.bottom - wintemp.top)/5;
     char msg[15];
-    int tmp = maxValTop;
-    int converted;
+
+    /* temperature is provided in centi scaling => convert */
+    maxValTop /= 10;
+    step /= 10;
+
+    tmp = maxValTop;
     for(int i = 1; i<=5; i++)
     {
         tmp -= 	step;
-        if(settingsGetPointer()->nonMetricalSystem) {
-        	converted = unit_temperature_integer(tmp);
-        }
-        else{
-        	converted = tmp;
-        }
-        //if(tmp < 0)
-            //break;
         winsmal.top	= wintemp.top + deltaline * i - 14;
         winsmal.bottom = winsmal.top + 16;
-        if((converted >= 0) && (converted < 100))
-            snprintf(msg,15,"%1i",converted);
-        else
-            snprintf(msg,15,"%2i",converted);
+        snprintf(msg,15,"%2i",unit_temperature_integer(tmp));
         Gfx_write_label_var(hgfx, winsmal.left, winsmal.right,winsmal.top, &FontT24,CLUT_LogbookTemperature,msg);
     }
 
--- a/Discovery/Src/unit.c	Mon Apr 19 20:34:53 2021 +0200
+++ b/Discovery/Src/unit.c	Sun Apr 25 20:36:18 2021 +0200
@@ -107,13 +107,13 @@
     }
 }
 
-uint16_t unit_temperature_integer(uint16_t input_celsius)
+int16_t unit_temperature_integer(int16_t input_celsius)
 {
     if(settingsGetPointer()->nonMetricalSystem == 0)
         return input_celsius;
     else
     {
-        return ((input_celsius * 9 / 5) + 320);
+        return ((input_celsius * 9 / 5) + 32);
     }
 }