Configure lis2dh sensor

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;
}
Parents
  • Hi,

    This is the kind of question that you ask if you tried it and it did not work.

    Could you let me know the error you face when you tried this?

    Also, please include some more info:

    For us to help you with this in the best possible way, please list the following information:

    • SDK Version
    • Which sample do you use, if any?
    • Do you use custom hardware or code?

     

    Regards,
    Sigurd Hellesvik

Reply
  • Hi,

    This is the kind of question that you ask if you tried it and it did not work.

    Could you let me know the error you face when you tried this?

    Also, please include some more info:

    For us to help you with this in the best possible way, please list the following information:

    • SDK Version
    • Which sample do you use, if any?
    • Do you use custom hardware or code?

     

    Regards,
    Sigurd Hellesvik

Children
No Data
Related