Skip to content

Commit 574a38f

Browse files
authored
Merge pull request #83 from tmobile/ambient_temp_fix
fixed ambient temperature in the lis2dw12 sensor sample.
2 parents d30ed7f + 630c3ff commit 574a38f

File tree

1 file changed

+5
-11
lines changed
  • samples/lis2dw12_sample/src

1 file changed

+5
-11
lines changed

samples/lis2dw12_sample/src/main.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,11 @@
1515
#define FREEFALL_EVENT 0x02U
1616
#define DATAREADY_EVENT 0x01U
1717

18-
#define ABS(x) (((x) < 0) ? -(x) : (x))
19-
20-
uint8_t reg_value;
21-
struct sensor_value temperature;
2218
bool sample_init_complete = false;
2319

24-
uint8_t status;
2520

21+
uint8_t reg_value;
22+
struct sensor_value temperature;
2623
struct sensor_value sensor_attr_val;
2724
struct sensor_trigger trig;
2825

@@ -64,7 +61,7 @@ static void trigger_and_display(const struct device *sensor)
6461
if (rc < 0) {
6562
printf("\n\tERROR: Unable to read register 0X27 :%d\n", rc);
6663
} else {
67-
uint8_t reg_value = (uint8_t)sensor_attr_val.val1;
64+
reg_value = (uint8_t)sensor_attr_val.val1;
6865
if ((reg_value & SINGLE_TAP_EVENT) == SINGLE_TAP_EVENT) {
6966
printf("\n\tSINGLE TAP was detected (%xh)\n", (reg_value));
7067
} else if ((reg_value & DOUBLE_TAP_EVENT) == DOUBLE_TAP_EVENT) {
@@ -122,15 +119,12 @@ static void trigger_and_display(const struct device *sensor)
122119
}
123120
}
124121

125-
struct sensor_value temp12bit;
126-
rc = sensor_channel_get(sensor, SENSOR_CHAN_AMBIENT_TEMP, &temp12bit);
122+
rc = sensor_channel_get(sensor, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
127123
if (rc < 0) {
128124
printf("\n\tERROR: Unable to read ambient temperature :%d\n", rc);
129125
} else {
130126

131-
float deltaT = (((int16_t)temp12bit.val1 >> 4) * 0.0625);
132-
float temperature16 = (25.0 + deltaT);
133-
printf("\tAmbient Temperature %.1f deg C\n", ABS(temperature16));
127+
printf("\t\tAmbient Temperature: %.2f C\n", sensor_value_to_double(&temperature));
134128
}
135129
}
136130

0 commit comments

Comments
 (0)