diff --git a/src/devices/ambient_weather.c b/src/devices/ambient_weather.c index ad4301116..34361a1cf 100644 --- a/src/devices/ambient_weather.c +++ b/src/devices/ambient_weather.c @@ -41,7 +41,7 @@ static int ambient_weather_decode(r_device *decoder, bitbuffer_t *bitbuffer, uns isBatteryLow = (b[2] & 0x80) != 0; // if not zero, battery is low channel = ((b[2] & 0x70) >> 4) + 1; int temp_f = ((b[2] & 0x0f) << 8) | b[3]; - temperature = (temp_f - 400) / 10.0f; + temperature = (temp_f - 400) * 0.1f; humidity = b[4]; data = data_make( diff --git a/src/devices/bresser_3ch.c b/src/devices/bresser_3ch.c index 897405c44..99f8c0f72 100644 --- a/src/devices/bresser_3ch.c +++ b/src/devices/bresser_3ch.c @@ -58,7 +58,7 @@ static int bresser_3ch_callback(r_device *decoder, bitbuffer_t *bitbuffer) { temp_raw = ((b[1] & 0x0F) << 8) + b[2]; // 12 bits allows for values -90.0 F - 319.6 F (-67 C - 159 C) - temp_f = (temp_raw - 900) / 10.0; + temp_f = (temp_raw - 900) * 0.1f; humidity = b[3]; diff --git a/src/devices/digitech_xc0324.c b/src/devices/digitech_xc0324.c index eddd7e4d1..96d871a14 100644 --- a/src/devices/digitech_xc0324.c +++ b/src/devices/digitech_xc0324.c @@ -106,8 +106,8 @@ static int decode_xc0324_message(r_device *decoder, bitbuffer_t *bitbuffer, // Decode temperature (b[2]), plus 1st 4 bits b[3], LSB first order! // Tenths of degrees C, offset from the minimum possible (-40.0 degrees) - uint16_t temp = ((uint16_t)(reverse8(b[3]) & 0x0f) << 8) | reverse8(b[2]); - temperature = (temp / 10.0) - 40.0; + int temp = ((uint16_t)(reverse8(b[3]) & 0x0f) << 8) | reverse8(b[2]); + temperature = (temp - 400) * 0.1f; //Unknown byte, constant as 0x80 in all my data // ??maybe battery status?? diff --git a/src/devices/ecowitt.c b/src/devices/ecowitt.c index 46f4ca3b1..85430970d 100644 --- a/src/devices/ecowitt.c +++ b/src/devices/ecowitt.c @@ -73,9 +73,8 @@ static int ecowitt_decode(r_device *decoder, bitbuffer_t *bitbuffer) } // Temperature is next 10 bits - float temp_c = -40.0; // Bias - temp_c += (float)b[3] / 10.0; - temp_c += (float)((b[2] & 0x3) << 8) / 10.0; + int temp_raw = ((b[2] & 0x3) << 8) | b[3]; + float temp_c = (temp_raw - 400) * 0.1f; // All Ecowitt observed packets have bits 39-48 set. if (b[4] != 0xFF) { diff --git a/src/devices/emontx.c b/src/devices/emontx.c index aa8a032cb..9b16f7c27 100644 --- a/src/devices/emontx.c +++ b/src/devices/emontx.c @@ -119,12 +119,12 @@ static int emontx_callback(r_device *decoder, bitbuffer_t *bitbuffer) { _X("batt_Vrms","Vrms/batt"), "", DATA_FORMAT, "%.2f", DATA_DOUBLE, vrms, "pulse", "", DATA_FORMAT, "%u", DATA_INT, words[11] | ((uint32_t)words[12] << 16), // Slightly horrid... a value of 300.0°C means 'no reading'. So omit them completely. - words[5] == 3000 ? NULL : "temp1_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, (double)words[5] / 10.0, - words[6] == 3000 ? NULL : "temp2_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, (double)words[6] / 10.0, - words[7] == 3000 ? NULL : "temp3_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, (double)words[7] / 10.0, - words[8] == 3000 ? NULL : "temp4_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, (double)words[8] / 10.0, - words[9] == 3000 ? NULL : "temp5_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, (double)words[9] / 10.0, - words[10] == 3000 ? NULL : "temp6_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, (double)words[10] / 10.0, + words[5] == 3000 ? NULL : "temp1_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, words[5] * 0.1f, + words[6] == 3000 ? NULL : "temp2_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, words[6] * 0.1f, + words[7] == 3000 ? NULL : "temp3_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, words[7] * 0.1f, + words[8] == 3000 ? NULL : "temp4_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, words[8] * 0.1f, + words[9] == 3000 ? NULL : "temp5_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, words[9] * 0.1f, + words[10] == 3000 ? NULL : "temp6_C", "", DATA_FORMAT, "%.1f", DATA_DOUBLE, words[10] * 0.1f, "mic", "Integrity", DATA_STRING, "CRC", NULL); decoder_output_data(decoder, data); diff --git a/src/devices/lacrossews.c b/src/devices/lacrossews.c index 53a9017a8..2462827e4 100644 --- a/src/devices/lacrossews.c +++ b/src/devices/lacrossews.c @@ -168,7 +168,7 @@ static int lacrossews_callback(r_device *decoder, bitbuffer_t *bitbuffer) case 7: // Gust wind_dir = msg_nybbles[9] * 22.5; - wind_spd = (msg_nybbles[7] * 16 + msg_nybbles[8]) / 10.0; + wind_spd = (msg_nybbles[7] * 16 + msg_nybbles[8]) * 0.1f; if (msg_nybbles[7] == 0xF && msg_nybbles[8] == 0xE) { if (decoder->verbose) { fprintf(stderr, "LaCrosse WS %02X-%02X: %s Not Connected\n", diff --git a/src/devices/mebus.c b/src/devices/mebus.c index 0e88d1650..5f344abe3 100644 --- a/src/devices/mebus.c +++ b/src/devices/mebus.c @@ -40,7 +40,7 @@ static int mebus433_callback(r_device *decoder, bitbuffer_t *bitbuffer) { "battery", "Battery", DATA_STRING, battery ? "OK" : "LOW", "unknown1", "Unknown 1", DATA_INT, unknown1, "unknown2", "Unknown 2", DATA_INT, unknown2, - "temperature_C", "Temperature", DATA_FORMAT, "%.02f C", DATA_DOUBLE, temp / 10.0, + "temperature_C", "Temperature", DATA_FORMAT, "%.02f C", DATA_DOUBLE, temp * 0.1f, "humidity", "Humidity", DATA_FORMAT, "%u %%", DATA_INT, hum, NULL); decoder_output_data(decoder, data); diff --git a/src/devices/thermopro_tp11.c b/src/devices/thermopro_tp11.c index 075864b63..a98d4fa32 100644 --- a/src/devices/thermopro_tp11.c +++ b/src/devices/thermopro_tp11.c @@ -44,7 +44,7 @@ static int thermopro_tp11_sensor_callback(r_device *decoder, bitbuffer_t *bitbuf device = value >> 12; temp_raw = value & 0xfff; - temp_c = (temp_raw - 200) / 10.; + temp_c = (temp_raw - 200) * 0.1f; data = data_make( "model", "", DATA_STRING, _X("Thermopro-TP11","Thermopro TP11 Thermometer"), diff --git a/src/devices/wt0124.c b/src/devices/wt0124.c index 567c4c462..8206373b9 100644 --- a/src/devices/wt0124.c +++ b/src/devices/wt0124.c @@ -60,7 +60,7 @@ static int wt1024_callback(r_device *decoder, bitbuffer_t *bitbuffer) sensor_rid = (b[0]&0x0F)<<4 | (b[1]&0x0F); /* Get temperature */ - temp_c = (float) ((((b[1]&0xF)<<8) | b[2])-0x990) / 10.0; + temp_c = ((((b[1] & 0xF) << 8) | b[2]) - 0x990) * 0.1f; /* Get channel */ channel = ((b[3]>>4) & 0x3); diff --git a/src/r_util.c b/src/r_util.c index 0fa225bba..85eb32201 100644 --- a/src/r_util.c +++ b/src/r_util.c @@ -90,57 +90,57 @@ char *sample_pos_str(float sample_file_pos, char *buf) float celsius2fahrenheit(float celsius) { - return celsius * 9 / 5 + 32; + return celsius * (9.0f / 5.0f) + 32; } float fahrenheit2celsius(float fahrenheit) { - return (fahrenheit - 32) / 1.8; + return (fahrenheit - 32) * (5.0f / 9.0f); } float kmph2mph(float kmph) { - return kmph / 1.609344; + return kmph * (1.0f / 1.609344f); } float mph2kmph(float mph) { - return mph * 1.609344; + return mph * 1.609344f; } float mm2inch(float mm) { - return mm * 0.039370; + return mm * 0.039370f; } float inch2mm(float inch) { - return inch / 0.039370; + return inch * 25.4f; } float kpa2psi(float kpa) { - return kpa / 6.89475729; + return kpa * (1.0f / 6.89475729f); } float psi2kpa(float psi) { - return psi * 6.89475729; + return psi * 6.89475729f; } float hpa2inhg(float hpa) { - return hpa / 33.8639; + return hpa * (1.0f / 33.8639f); } float inhg2hpa(float inhg) { - return inhg * 33.8639; + return inhg * 33.8639f; }