Skip to content

Commit

Permalink
Change div 10 to mul 0.1 in all decoders
Browse files Browse the repository at this point in the history
  • Loading branch information
zuckschwerdt committed May 16, 2020
1 parent e5bdd68 commit c1d1f9f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/devices/ambient_weather.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/devices/bresser_3ch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down
4 changes: 2 additions & 2 deletions src/devices/digitech_xc0324.c
Original file line number Diff line number Diff line change
Expand Up @@ -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??
Expand Down
5 changes: 2 additions & 3 deletions src/devices/ecowitt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
12 changes: 6 additions & 6 deletions src/devices/emontx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/lacrossews.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/devices/mebus.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/devices/thermopro_tp11.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion src/devices/wt0124.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
20 changes: 10 additions & 10 deletions src/r_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down

0 comments on commit c1d1f9f

Please sign in to comment.