#define LSG (1024.0f)
#define NUMOFACCDATA (8.0f)
-//min delay for accelerometer
-#define HID_ACCEL3D_MIN_DELAY 16000
// conversion of acceleration data to SI units (m/s^2)
#define RANGE_A (2*GRAVITY_EARTH)
mPendingEvent.sensor = ID_L;
mPendingEvent.type = SENSOR_TYPE_LIGHT;
memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
+
+ // CDD is silent on ALS requirements. Fix default at 2Hz pending
+ // better numbers from somewhere.
+ sample_delay_min_ms = 500;
+
ALOGV("<<ALSSensor 3D: constructor!");
}
const struct sensor_t AccelSensor::sSensorInfo_accel3D = {
"HID_SENSOR Accelerometer 3D", "Intel", 1, SENSORS_ACCELERATION_HANDLE,
- SENSOR_TYPE_ACCELEROMETER, RANGE_A, RESOLUTION_A, 0.23f, HID_ACCEL3D_MIN_DELAY, {}
+ SENSOR_TYPE_ACCELEROMETER, RANGE_A, RESOLUTION_A, 0.23f, 0, {}
};
const long HID_USAGE_SENSOR_UNITS_G = 0x1A;
mPendingEvent.sensor = ID_A;
mPendingEvent.type = SENSOR_TYPE_ACCELEROMETER;
memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
+
+ // CDD requires 120Hz, but HSB caps out at ~62Hz. Use that as default.
+ sample_delay_min_ms = 16;
+
ALOGV("<<AccelSensor 3D: constructor!");
}
mPendingEvent.sensor = ID_M;
mPendingEvent.type = SENSOR_TYPE_MAGNETIC_FIELD;
memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
+
+ // CDD 4.2 requires 10Hz. 20Hz is the maximum for HSB.
+ sample_delay_min_ms = 50;
+
ALOGV("<<ComassSensor 3D: constructor!");
}
mPendingEvent.type = SENSOR_TYPE_GYROSCOPE;
memset(mPendingEvent.data, 0, sizeof(mPendingEvent.data));
+ // CDD requires 200Hz (!), but HSB caps out at ~62Hz. Use that as
+ // default.
+ sample_delay_min_ms = 16;
}
int GyroSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
unit_expo_value(0),
units_value(0),
retry_count(retry_cnt),
- raw_buffer(NULL)
+ raw_buffer(NULL),
+ sample_delay_min_ms(0)
{
-
ALOGV("%s", __func__);
}
ALOGV("%s: sample_rate:%d", __func__, rate);
+ if (sample_delay_min_ms && period < sample_delay_min_ms)
+ period = sample_delay_min_ms;
+
filename << IIO_DIR << "/" << "iio:device" << dev_num << "/" << channel_prefix_str << "sampling_frequency";
if (period <= 0) {
ALOGE("%s: Invalid_rate:%d", __func__, period);
int FreeRxBuffer();
protected:
+
+ // Subclasses (e.g. HID devices) may implement "non-streaming"
+ // sensors with a non-constant sample rate, leveraging a
+ // microcontroller "sensor hub" to do the sampling and interrupt
+ // the CPU only on change. Google allows this in the api by
+ // setting minDelay to 0 in sensor_t. But if we do that, the
+ // framework has no idea what values can be set so often tries
+ // implausibly high values for "game" mode. Setting this to
+ // non-zero allows the subclasses to clamp to device-specific
+ // values.
+ int sample_delay_min_ms;
+
bool IsDeviceInitialized();
int GetDeviceNumber();
int SetDataReadyTrigger(int dev_num, bool status);