Browse Source

Fix Pressure calculation.

Vladimir N. Shilov 3 years ago
parent
commit
a15c5e4cc3
1 changed files with 5 additions and 5 deletions
  1. 5 5
      Src/main.c

+ 5 - 5
Src/main.c

@@ -219,7 +219,7 @@ COLOR_RGB(255, 0, 0);
   /* bme280_get_sensor_data(...) returns:
    *  - temperature in DegC, resolution is 0.01 DegC. Output value of "5123" equals 51.23 DegC.
    *  - pressure in Pa as unsigned 32 bit integer in Q24.8 format (24 integer bits and 8 fractional bits).
-   *    Output value "24674867" represents 24674867/256 = 96386.2 Pa = 963.862 hPa.
+   *    Output value "24674867" represents 24674867/256 = 96386.2 Pa = 963.862 hPa. -- for 64bit
    *  - humidity in %RH as unsigned 32 bit integer in Q22.10 format.
    *    Output value of "47445" represents 47445/1024 = 46.333 %RH
    */
@@ -286,10 +286,10 @@ COLOR_RGB(255, 0, 0);
       hum_h = (uint8_t)(tmp / 1024);
       hum_l = (uint8_t)((tmp % 1024) / 10);
 
-      tmp = (SensorData.pressure + 128) / 256; // pressure in Pa
-      //tmp *= 1000;
-      //tmp += 66661;
-      //tmp /= 133322; // pressure in mmHg
+      /* in 32-bit ariphmetics pressure in Pa */
+      tmp = SensorData.pressure * 1000;
+      tmp += 66661;
+      tmp /= 133322; // pressure in mmHg
       pres_h = (uint8_t)(tmp / 100);
       pres_l = (uint8_t)(tmp % 100);