/*
- * Copyright (C) 2014-2015 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 <ctype.h>
#include <dirent.h>
#include "control.h"
#include "calibration.h"
+#include <errno.h>
+
/*
* This table maps syfs entries in scan_elements directories to sensor types,
* and will also be used to determine other sysfs names as well as the iio
#define PANEL_FRONT 4
#define PANEL_BACK 5
+/* Buffer default length */
+#define BUFFER_LENGTH 16
+
/* We equate sensor handles to indices in these tables */
struct sensor_t sensor_desc[MAX_SENSORS]; /* Android-level descriptors */
int num_channels;
char suffix[MAX_NAME_SIZE + 8];
int calib_bias;
+ int buffer_length;
if (sensor_count == MAX_SENSORS) {
ALOGE("Too many sensors!\n");
sysfs_write_int(sysfs_path, calib_bias);
}
+ /* Change buffer length according to the property or use default value */
+ if (mode == MODE_TRIGGER) {
+ if (sensor_get_prop(s, "buffer_length", &buffer_length)) {
+ buffer_length = BUFFER_LENGTH;
+ }
+
+ sprintf(sysfs_path, BUFFER_LENGTH_PATH, dev_num);
+
+ if (sysfs_write_int(sysfs_path, buffer_length) <= 0) {
+ ALOGE("Failed to set buffer length on dev%d", dev_num);
+ }
+ }
+
/* Read name attribute, if available */
sprintf(sysfs_path, NAME_PATH, dev_num);
sysfs_read_str(sysfs_path, sensor[s].internal_name, MAX_NAME_SIZE);
sensor[s].channel[c].raw_path_present = (access(sysfs_path, R_OK) != -1);
}
+ sensor_get_available_frequencies(s);
+
if (sensor_get_mounting_matrix(s, sensor[s].mounting_matrix))
sensor[s].quirks |= QUIRK_MOUNTING_MATRIX;
else
}
}
+extern float sensor_get_max_static_freq(int s);
+extern float sensor_get_min_freq (int s);
+
static int create_hrtimer_trigger(int s, int trigger)
{
struct stat dir_status;
char buf[MAX_NAME_SIZE];
char hrtimer_path[PATH_MAX];
char hrtimer_name[MAX_NAME_SIZE];
+ float min_supported_rate = 1, min_rate_cap, max_supported_rate;
snprintf(buf, MAX_NAME_SIZE, "hrtimer-%s-hr-dev%d", sensor[s].internal_name, sensor[s].dev_num);
snprintf(hrtimer_name, MAX_NAME_SIZE, "%s-hr-dev%d", sensor[s].internal_name, sensor[s].dev_num);
strncpy (sensor[s].hrtimer_trigger_name, hrtimer_name, MAX_NAME_SIZE);
sensor[s].trigger_nr = trigger;
+
+ max_supported_rate = sensor_get_max_static_freq(s);
+
+ /* set 0 for wrong values */
+ if (max_supported_rate < 0.1) {
+ max_supported_rate = 0;
+ }
+
+ sensor[s].max_supported_rate = max_supported_rate;
+ sensor_desc[s].minDelay = max_supported_rate ? (int32_t) (1000000.0 / max_supported_rate) : 0;
+
+ /* Check if a minimum rate was specified for this sensor */
+ min_rate_cap = sensor_get_min_freq(s);
+
+ if (min_supported_rate < min_rate_cap) {
+ min_supported_rate = min_rate_cap;
+ }
+
+ sensor[s].min_supported_rate = min_supported_rate;
+ sensor_desc[s].maxDelay = (max_delay_t) (1000000.0 / min_supported_rate);
+
return 0;
}