diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 19:27:37 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-07-26 19:27:37 +0200 |
commit | 22b3bbc0855aa50864f33305e818626fbd3b7725 (patch) | |
tree | 0e73288ee38441367ae094325650325561a858d6 | |
parent | afd694f05178c22b4f71f65143c4647ce912d980 (diff) | |
download | trygvisio_soil_moisture-22b3bbc0855aa50864f33305e818626fbd3b7725.tar.gz trygvisio_soil_moisture-22b3bbc0855aa50864f33305e818626fbd3b7725.tar.bz2 trygvisio_soil_moisture-22b3bbc0855aa50864f33305e818626fbd3b7725.tar.xz trygvisio_soil_moisture-22b3bbc0855aa50864f33305e818626fbd3b7725.zip |
o Fixing wrong calculations when creating FLOATs.
-rw-r--r-- | trygvisio_soil_moisture.ino | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/trygvisio_soil_moisture.ino b/trygvisio_soil_moisture.ino index 8ecc907..4c9e0d7 100644 --- a/trygvisio_soil_moisture.ino +++ b/trygvisio_soil_moisture.ino @@ -208,15 +208,15 @@ static void aci_loop() { int32_t t = aci_evt->params.cmd_rsp.params.get_temperature.temperature_value; - // t is in 1/4 degrees celcius parts. + // t is number of 1/4 degrees celcius. // Multiply t by 25 without having to include float support t = t * 16 + t * 8 + t; - uint32_t exponent = ((uint32_t) 2) << 24; + uint8_t exponent = -2; // example. reading=111. real temperature = 111 / 4 = 27.75 dec C - // Calculation: t = 2775, exp = 2. formula: 10^exp * 0.t => 10^2 * 0.2775 = 27.75 + // Calculation: t = 111, formula: t*25 * 10^exp => 2775 * 10^-2 = 27.75 // The value of flags // bit 0: 0=Celcius, 1=Farenheight @@ -231,7 +231,7 @@ static void aci_loop() { // temperature type } temperature_measurement = { 0, - exponent | (t & 0x00FFFFFF) + ((uint32_t)exponent) << 24 | (t & 0x00FFFFFF) }; lib_aci_set_local_data(&aci_state, PIPE_SOIL_MOISTURE_INTERMEDIATE_TEMPERATURE_SET, |