Skip to content

Commit

Permalink
Enhance arexx-ml to address pull request feedback
Browse files Browse the repository at this point in the history
Declare variables one per line.
Replace nested switch/if structure with if/else sequence.
  • Loading branch information
leighbb committed Oct 24, 2024
1 parent 946952a commit 9df6d61
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions src/devices/arexx_ml.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,41 +105,37 @@ static int arexx_ml_decode(r_device *decoder, bitbuffer_t *bitbuffer)
int sens_val = (b[3] << 8) | (b[4]); // big-endian?

// Decode readings
float temp_c = 0.0, humidity = 0.0;
int is_humi = 0, is_temp = 0, is_alert = 0, temp_alert = 0;

switch (msg_len) {
case 5:
if ((id & 0xF000) == 0x2000) {
// temperature reading from TL-3TSN, TSN-33MN, etc.
is_temp = 1;
temp_c = (int16_t)sens_val * 0.0078125f;
}
else if ((id & 0xF001) == 0x4000) {
// temperature reading from TSN-TH70E, IP-TH70EXT, etc.
is_temp = 1;
// SHT10 Temperature
temp_c = sens_val * 0.01f - 40.0f; // offset actually varies by Vdd
}
else if ((id & 0xF001) == 0x4001) {
// humidity reading from TSN-TH70E, IP-TH70EXT, etc.
is_humi = 1;
sens_val = (int16_t)sens_val;
// SHT10 Humidity
humidity = -2.0468 + 0.0367 * sens_val - 1.5955E-6 * sens_val * sens_val;
}
break;

case 6:
float temp_c = 0.0;
float humidity = 0.0;
int is_humi = 0;
int is_temp = 0;
int is_alert = 0;
int temp_alert = 0;

if (msg_len == 5 && (id & 0xF000) == 0x2000) {
// temperature reading from TL-3TSN, TSN-33MN, etc.
is_temp = 1;
temp_c = (int16_t)sens_val * 0.0078125f;
}
else if (msg_len == 5 && (id & 0xF001) == 0x4000) {
// temperature reading from TSN-TH70E, IP-TH70EXT, etc.
is_temp = 1;
// SHT10 Temperature
temp_c = sens_val * 0.01f - 40.0f; // offset actually varies by Vdd
}
else if (msg_len == 5 && (id & 0xF001) == 0x4001) {
// humidity reading from TSN-TH70E, IP-TH70EXT, etc.
is_humi = 1;
sens_val = (int16_t)sens_val;
// SHT10 Humidity
humidity = -2.0468 + 0.0367 * sens_val - 1.5955E-6 * sens_val * sens_val;
}
else if (msg_len == 6) {
is_temp = is_alert = 1;
// MCP9808 Ambient Temperature Register "5-4":
temp_alert = (sens_val >> 13) & 7;
int temp_raw = (int16_t)(sens_val << 3); // uses sign-extend
temp_c = temp_raw / 128;
break;

default:
break; // Will report raw result only
}

/* clang-format off */
Expand Down

0 comments on commit 9df6d61

Please sign in to comment.