Hi,
I've used the ADXL362 sensor sample code in the zephyr folder to get the low power accelerometer sensor working on the the thingy91. It triggers on motion and I can print out the xyz values. but I cant figure out how to shut it down so I can turn it back on later. This would serve 2 purposes, to save power if needed, and eliminate motion triggers from the accelerameter when they shouldn't be acknowledged. For example the trigger fires off 2 motion events on all motions. I assume this is 1 high and 1 low. I would like to shut the accelerometer down after the first motion for a few minutes to eliminate the double read.
Here is some code example. disable_motion_sensor() doesn't seem to do anything
static void trigger_handler(struct device *dev, struct sensor_trigger *trig)
{
switch (trig->type) {
case SENSOR_TRIG_DATA_READY:
// printf("trig data ready\n");
if (sensor_sample_fetch(dev) < 0) {
printf("Sample fetch error\n");
return;
}
k_sem_give(&sem);
break;
case SENSOR_TRIG_THRESHOLD:
printf("Motion event\n");
blink_led();
// disable_motion_sensor();
// set_timer(checkinFrequency);
break;
default:
printf("Unknown trigger\n");
}
}
void set_motion_trig(){
if (IS_ENABLED(CONFIG_ADXL362_TRIGGER)) {
struct sensor_trigger trig = { .chan = SENSOR_CHAN_ACCEL_XYZ };
trig.type = SENSOR_TRIG_THRESHOLD;
if (sensor_trigger_set(devMotion, &trig, trigger_handler)) {
printf("Trigger set error\n");
return;
}
trig.type = SENSOR_TRIG_DATA_READY;
if (sensor_trigger_set(devMotion, &trig, trigger_handler)) {
printf("Trigger set error\n");
}
}
else{
printf("CONFIG_ADXL362_TRIGGER not enabled\n");
motionTriggerOn = 0;
}
}
void enable_motion_sensor(){
devMotion = device_get_binding(DT_INST_0_ADI_ADXL362_LABEL);
motionTriggerOn = 1;
if (devMotion == NULL) {
motionTriggerOn = 0;
printf("Device get binding device is null\n");
return;
}
}
void disable_motion_sensor(){
devMotion = NULL;
if (devMotion == NULL) {
if (IS_ENABLED(CONFIG_ADXL362_TRIGGER)) {
printf("Tried to shut down but motion sensor is still running\n");
}
else{
motionTriggerOn = 0;
printf("Motion sensor is shut down\n");
return;
}
}
}
Any thoughts would be appreciated