|
15 | 15 | #define FREEFALL_EVENT 0x02U |
16 | 16 | #define DATAREADY_EVENT 0x01U |
17 | 17 |
|
18 | | -#define ABS(x) (((x) < 0) ? -(x) : (x)) |
19 | | - |
20 | | -uint8_t reg_value; |
21 | | -struct sensor_value temperature; |
22 | 18 | bool sample_init_complete = false; |
23 | 19 |
|
24 | | -uint8_t status; |
25 | 20 |
|
| 21 | +uint8_t reg_value; |
| 22 | +struct sensor_value temperature; |
26 | 23 | struct sensor_value sensor_attr_val; |
27 | 24 | struct sensor_trigger trig; |
28 | 25 |
|
@@ -64,7 +61,7 @@ static void trigger_and_display(const struct device *sensor) |
64 | 61 | if (rc < 0) { |
65 | 62 | printf("\n\tERROR: Unable to read register 0X27 :%d\n", rc); |
66 | 63 | } else { |
67 | | - uint8_t reg_value = (uint8_t)sensor_attr_val.val1; |
| 64 | + reg_value = (uint8_t)sensor_attr_val.val1; |
68 | 65 | if ((reg_value & SINGLE_TAP_EVENT) == SINGLE_TAP_EVENT) { |
69 | 66 | printf("\n\tSINGLE TAP was detected (%xh)\n", (reg_value)); |
70 | 67 | } else if ((reg_value & DOUBLE_TAP_EVENT) == DOUBLE_TAP_EVENT) { |
@@ -122,15 +119,12 @@ static void trigger_and_display(const struct device *sensor) |
122 | 119 | } |
123 | 120 | } |
124 | 121 |
|
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); |
127 | 123 | if (rc < 0) { |
128 | 124 | printf("\n\tERROR: Unable to read ambient temperature :%d\n", rc); |
129 | 125 | } else { |
130 | 126 |
|
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)); |
134 | 128 | } |
135 | 129 | } |
136 | 130 |
|
|
0 commit comments