ADXL362: Add separate activity/inactivity triggers
This patch modifies the ADXL362 driver to use the new SENSOR_TRIG_MOTION trigger for activity detection and SENSOR_TRIG_STATIONARY for inactivity detection. Signed-off-by: Maximilian Deubel <maximilian.deubel@nordicsemi.no>
This commit is contained in:
parent
ba59262425
commit
1c1c72ea08
3 changed files with 38 additions and 14 deletions
|
@ -197,8 +197,10 @@ struct adxl362_data {
|
|||
struct gpio_callback gpio_cb;
|
||||
struct k_mutex trigger_mutex;
|
||||
|
||||
sensor_trigger_handler_t th_handler;
|
||||
struct sensor_trigger th_trigger;
|
||||
sensor_trigger_handler_t inact_handler;
|
||||
struct sensor_trigger inact_trigger;
|
||||
sensor_trigger_handler_t act_handler;
|
||||
struct sensor_trigger act_trigger;
|
||||
sensor_trigger_handler_t drdy_handler;
|
||||
struct sensor_trigger drdy_trigger;
|
||||
|
||||
|
|
|
@ -29,10 +29,15 @@ static void adxl362_thread_cb(const struct device *dev)
|
|||
}
|
||||
|
||||
k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER);
|
||||
if (drv_data->th_handler != NULL) {
|
||||
if (ADXL362_STATUS_CHECK_INACT(status_buf) ||
|
||||
ADXL362_STATUS_CHECK_ACTIVITY(status_buf)) {
|
||||
drv_data->th_handler(dev, &drv_data->th_trigger);
|
||||
if (drv_data->inact_handler != NULL) {
|
||||
if (ADXL362_STATUS_CHECK_INACT(status_buf)) {
|
||||
drv_data->inact_handler(dev, &drv_data->inact_trigger);
|
||||
}
|
||||
}
|
||||
|
||||
if (drv_data->act_handler != NULL) {
|
||||
if (ADXL362_STATUS_CHECK_ACTIVITY(status_buf)) {
|
||||
drv_data->act_handler(dev, &drv_data->act_trigger);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,13 +87,21 @@ int adxl362_trigger_set(const struct device *dev,
|
|||
uint8_t int_mask, int_en, status_buf;
|
||||
|
||||
switch (trig->type) {
|
||||
case SENSOR_TRIG_THRESHOLD:
|
||||
case SENSOR_TRIG_MOTION:
|
||||
k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER);
|
||||
drv_data->th_handler = handler;
|
||||
drv_data->th_trigger = *trig;
|
||||
drv_data->act_handler = handler;
|
||||
drv_data->act_trigger = *trig;
|
||||
k_mutex_unlock(&drv_data->trigger_mutex);
|
||||
int_mask = ADXL362_INTMAP1_ACT |
|
||||
ADXL362_INTMAP1_INACT;
|
||||
int_mask = ADXL362_INTMAP1_ACT;
|
||||
/* Clear activity and inactivity interrupts */
|
||||
adxl362_get_status(dev, &status_buf);
|
||||
break;
|
||||
case SENSOR_TRIG_STATIONARY:
|
||||
k_mutex_lock(&drv_data->trigger_mutex, K_FOREVER);
|
||||
drv_data->inact_handler = handler;
|
||||
drv_data->inact_trigger = *trig;
|
||||
k_mutex_unlock(&drv_data->trigger_mutex);
|
||||
int_mask = ADXL362_INTMAP1_INACT;
|
||||
/* Clear activity and inactivity interrupts */
|
||||
adxl362_get_status(dev, &status_buf);
|
||||
break;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue