I am trying to a interrupt on when the sensor has noticed 1G movement for 150MS
Is this the correct way to configure it?
const struct device *const sensor = DEVICE_DT_GET_ANY(st_lis2dh);
void configure_freefall()
{
int rc;
struct sensor_value threshold, duration;
threshold.val1 = 0;
threshold.val2 = (int32_t)(SENSOR_G * 1);
rc = sensor_attr_set(sensor, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SLOPE_TH, &threshold);
if (rc) {
printk("Failed to set free-fall threshold\n");
}
threshold.val1 = 150;
threshold.val2 = 0;
rc = sensor_attr_set(sensor, SENSOR_CHAN_ACCEL_XYZ, SENSOR_ATTR_SLOPE_DUR, &threshold);
if (rc) {
printk("Failed to set free-fall duration\n");
}
}
For setting up the trigger:
static struct sensor_trigger lis2dh12_trigger;
struct sensor_trigger trig = {
.type = 2,
.chan = SENSOR_CHAN_ACCEL_XYZ, // Use SENSOR_CHAN_ACCEL_ANY for any axis
};
int test = sensor_trigger_set(sensor, &trig, freefall_handler);
if (test < 0) {
printk("Could not set trigger %i", test);
return;
}