Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions samples/lis2dw12_sample/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@
#define FREEFALL_EVENT 0x02U
#define DATAREADY_EVENT 0x01U

#define ABS(x) (((x) < 0) ? -(x) : (x))

uint8_t reg_value;
struct sensor_value temperature;
bool sample_init_complete = false;

uint8_t status;

uint8_t reg_value;
struct sensor_value temperature;
struct sensor_value sensor_attr_val;
struct sensor_trigger trig;

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

struct sensor_value temp12bit;
rc = sensor_channel_get(sensor, SENSOR_CHAN_AMBIENT_TEMP, &temp12bit);
rc = sensor_channel_get(sensor, SENSOR_CHAN_AMBIENT_TEMP, &temperature);
if (rc < 0) {
printf("\n\tERROR: Unable to read ambient temperature :%d\n", rc);
} else {

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

Expand Down