/*
- * Copyright (C) 2014 Intel Corporation.
- */
+// Copyright (c) 2015 Intel Corporation
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+*/
#include <hardware/sensors.h>
#include <utils/Log.h>
#include "enumeration.h"
#include "control.h"
#include "description.h"
+#include "utils.h"
+
+#include <errno.h>
/* This is the IIO Sensors HAL module entry points file */
static int activate (__attribute__((unused)) struct sensors_poll_device_t* dev,
int handle, int enabled)
{
+ int64_t entry_ts;
+ int ret;
+ int elapsed_ms;
+
if (init_count == 0 || handle < 0 || handle >= sensor_count)
return -EINVAL;
+ entry_ts = get_timestamp_thread();
+
/*
* The Intel sensor hub seems to have trouble enabling sensors before
* a sampling rate has been configured, and setting the sampling rate
* a workaround for this behavior. We set the initial sampling rate to
* 10 events per second when the sensor is enabled for the first time.
*/
+
if (enabled && sensor_get_quirks(handle) & QUIRK_INITIAL_RATE) {
ALOGI("Forcing initial sampling rate\n");
- sensor_activate(handle, 1);
- sensor_set_delay(handle, 100000000L); /* Start with 100 ms */
- sensor_activate(handle, 0);
+ sensor_activate(handle, 1, 0);
+ sensor_set_delay(handle, 100000000); /* Start with 100 ms */
+ sensor_activate(handle, 0, 0);
/* Clear flag for this sensor as do this only once */
- sensor_info[handle].quirks ^= QUIRK_INITIAL_RATE;
+ sensor[handle].quirks ^= QUIRK_INITIAL_RATE;
}
- return sensor_activate(handle, enabled);
+ ret = sensor_activate(handle, enabled, 0);
+
+ elapsed_ms = (int) ((get_timestamp_thread() - entry_ts) / 1000000);
+
+ if (elapsed_ms) {
+ if (enabled)
+ ALOGI("Activation of sensor %s took %d ms\n", sensor[handle].friendly_name, elapsed_ms);
+ else
+ ALOGI("Deactivation of sensor %s took %d ms\n", sensor[handle].friendly_name, elapsed_ms);
+ }
+
+ return ret;
}
static int set_delay (__attribute__((unused)) struct sensors_poll_device_t* dev,
int handle, int64_t ns)
{
+ int i;
+
if (init_count == 0 || handle < 0 || handle >= sensor_count)
return -EINVAL;
+ /*
+ * If this sensor relies on other sensors, try to propagate the
+ * requested sampling rate to the base sensors.
+ */
+
+ for (i=0; i<sensor[handle].base_count; i++)
+ sensor_set_delay(sensor[handle].base[i], ns);
+
return sensor_set_delay(handle, ns);
}