Also improve debug messages.
(raw_data + 2), *(raw_data + 3), *(raw_data + 4), *(raw_data + 5));
sample = (struct accel_3d_sample*)raw_data;
mPendingEvent.data[0] = mPendingEvent.acceleration.x =
- CONVERT_A_G_VTF16E14_X(GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->accel_x);
+ CONVERT_A_G_VTF16E14_X(GetChannelBytesUsedSize(CHANNEL_X), GetScaleValue(), sample->accel_x);
mPendingEvent.data[1] = mPendingEvent.acceleration.y =
- CONVERT_A_G_VTF16E14_Y(GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->accel_y);
+ CONVERT_A_G_VTF16E14_Y(GetChannelBytesUsedSize(CHANNEL_Y), GetScaleValue(), sample->accel_y);
mPendingEvent.data[2] = mPendingEvent.acceleration.z =
- CONVERT_A_G_VTF16E14_Z(GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->accel_z);
+ CONVERT_A_G_VTF16E14_Z(GetChannelBytesUsedSize(CHANNEL_Z), GetScaleValue(), sample->accel_z);
ALOGV("ACCEL 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.acceleration.x,
mPendingEvent.acceleration.y, mPendingEvent.acceleration.z);
}
sample = (struct compass_3d_sample*)raw_data;
+ float sc = GetScaleValue();
mPendingEvent.data[0] = mPendingEvent.magnetic.x = CONVERT_M_MG_VTF16E14_X
- (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->compass_x);
+ (GetChannelBytesUsedSize(CHANNEL_X), sc, sample->compass_x);
mPendingEvent.data[1] = mPendingEvent.magnetic.y = CONVERT_M_MG_VTF16E14_Y
- (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->compass_y);
+ (GetChannelBytesUsedSize(CHANNEL_Y), sc, sample->compass_y);
mPendingEvent.data[2] = mPendingEvent.magnetic.z = CONVERT_M_MG_VTF16E14_Z
- (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->compass_z);
+ (GetChannelBytesUsedSize(CHANNEL_Z), sc, sample->compass_z);
ALOGV("COMPASS 3D Sample %fuT %fuT %fuT\n", mPendingEvent.magnetic.x,
mPendingEvent.magnetic.y, mPendingEvent.magnetic.z);
return - 1;
}
sample = (struct gyro_3d_sample*)raw_data;
- switch (GetUnitValue()) {
- case HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED:
- case HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND:
- mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_G_D_VTF16E14_X
- (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->gyro_x)
- ;
- mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_G_D_VTF16E14_Y
- (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->gyro_y)
- ;
- mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_G_D_VTF16E14_Z
- (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->gyro_z)
- ;
- break;
- case HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND:
- mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_FROM_VTF16
- (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->gyro_x)
- ;
- mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_FROM_VTF16
- (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->gyro_y)
- ;
- mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_FROM_VTF16
- (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->gyro_z)
- ;
- break;
- default:
- ALOGE("Gyro Unit is not supported");
- break;
- }
-
- ALOGV("GYRO 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.gyro.x,
+ float sc = GetScaleValue();
+ mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_FROM_VTF16
+ (GetChannelBytesUsedSize(CHANNEL_X), sc, sample->gyro_x);
+ mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_FROM_VTF16
+ (GetChannelBytesUsedSize(CHANNEL_Y), sc, sample->gyro_y);
+ mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_FROM_VTF16
+ (GetChannelBytesUsedSize(CHANNEL_Z), sc, sample->gyro_z);
+ ALOGD("GYRO 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.gyro.x,
mPendingEvent.gyro.y, mPendingEvent.gyro.z);
ALOGV("<<%s", __func__);
return 0;
float vals[3];
unsigned int *sample = (unsigned int*)data;
- long ex = GetExponentValue();
+ float sc = GetScaleValue();
for (int i=0; i<3; i++) {
int sz = GetChannelBytesUsedSize(i);
- vals[i] = convert_from_vtf_format(sz, ex, sample[i]);
+ vals[i] = convert_from_vtf_format(sz, sc, sample[i]);
}
// When held in the Android convention frame (X to the right, Y
};
RotVecSensor::RotVecSensor()
- : SensorIIODev("dev_rotation", // name
- "in_rot_scale", // units sysfs node
- "in_rot_offset", // exponent sysfs node
+ : SensorIIODev("magn_3d", // name
+ "in_magn_scale", // units sysfs node
+ "in_magn_offset",// exponent sysfs node
"in_rot_", // channel_prefix
10) // retry count
{
return -1;
}
- if (len < 4*sizeof(unsigned int)) {
- ALOGE("Insufficient length \n");
- return -1;
- }
-
// The Intel Sensor Hub emits a normalized x/y/z/w quaternion
// which acts to rotate points in the device coordinate system
// (left/up/out) to the world coordinate system (north/east/down).
// copy out the raw data.
unsigned int *sample = (unsigned int*)data;
- long ex = GetExponentValue();
- for (int i=0; i<4; i++) {
+ float sc = GetScaleValue();
+ for (int i=0; i < (len / sizeof(*sample)); i++) {
int sz = GetChannelBytesUsedSize(i);
- mPendingEvent.data[i] = convert_from_vtf_format(sz, ex, sample[i]);
+ mPendingEvent.data[i] = convert_from_vtf_format(sz, sc, sample[i]);
}
if (mSynthCompass)
static const int DEF_BUFFER_LEN = 2;
static const int DEF_HYST_VALUE = 0;
-SensorIIODev::SensorIIODev(const std::string& dev_name, const std::string& units,
- const std::string& exponent,
+SensorIIODev::SensorIIODev(const std::string& dev_name, const std::string& scale,
+ const std::string& offset,
const std::string& channel_prefix, int retry_cnt)
: SensorBase(""),
initialized(false),
- unit_expo_str(exponent),
- unit_str(units),
+ scale_str(scale),
+ offset_str(offset),
device_name(dev_name),
channel_prefix_str(channel_prefix),
- unit_expo_value(0),
- units_value(0),
+ scale(0.0),
+ offset(0.0),
retry_count(retry_cnt),
raw_buffer(NULL),
mRefCount(0),
ALOGV("%s", __func__);
}
-SensorIIODev::SensorIIODev(const std::string& dev_name, const std::string& units,
- const std::string& exponent,
- const std::string& channel_prefix)
- : SensorBase(""),
- initialized(false),
- unit_expo_str(exponent),
- unit_str(units),
- device_name(dev_name),
- channel_prefix_str(channel_prefix),
- unit_expo_value(0),
- units_value(0),
- retry_count(1),
- raw_buffer(NULL),
- mRefCount(0)
-{
-
- ALOGV("%s", __func__);
-}
-
int SensorIIODev::discover()
{
int cnt;
if(*sampmin)
sample_delay_min_ms = strtol(sampmin, NULL, 10);
- ALOGD(">>%s discover", __func__);
+ ALOGD(">>discover %s", device_name.c_str());
for (cnt = 0; cnt < retry_count; cnt++) {
status = ParseIIODirectory(device_name);
if (status >= 0){
initialized = true;
filename << "/dev/iio:device" << device_number;
mDevPath = filename.str();
- ALOGV("mDevPath %s", mDevPath.c_str());
+ ALOGI("found %s at %s", device_name.c_str(), mDevPath.c_str());
ret = 0;
break;
- }
- else{
- ALOGE("Sensor IIO Init failed, retry left:%d\n", retry_count-cnt);
+ } else {
+ ALOGE("%s not found, retry left: %d", device_name.c_str(), retry_count-cnt);
mDevPath = "";
ret = -1;
}
int ret =0;
double sensitivity;
- ALOGD(">>%s enabled:%d", __func__, enabled);
+ ALOGD(">>%s enabled: %d", device_name.c_str(), enabled);
if (enabled){
if ((ret = discover()) < 0) {
EnableBuffer(1);
EnableBuffer(0);
- if (ReadHIDExponentValue(&unit_expo_value) < 0)
+ if (ReadHIDScaleValue(&scale) < 0)
goto err_ret;
- if (ReadHIDMeasurmentUnit(&units_value) < 0)
+ if (ReadHIDOffsetValue(&offset) < 0)
goto err_ret;
if (SetDataReadyTrigger(GetDeviceNumber(), true) < 0)
goto err_ret;
goto err_ret;
if (AllocateRxBuffer() < 0)
goto err_ret;
+ ALOGI("%s: scale=%f offset=%f", device_name.c_str(), scale, offset);
}
else{
if (SetDataReadyTrigger(GetDeviceNumber(), false) < 0)
err_ret:
close();
- ALOGE("SesnorIIO: Enable failed\n");
+ ALOGE("SesnorIIO: %s Enable failed", device_name.c_str());
return -1;
}
ALOGV(">>%s %ld", __func__, delay_ns);
if (IsDeviceInitialized() == false){
- ALOGE("Device was not initialized \n");
+ ALOGE("Device %s was not initialized", device_name.c_str());
return -EFAULT;
}
if (ms){
return 0;
}
-long SensorIIODev::GetUnitValue()
+float SensorIIODev::GetScaleValue()
{
- return units_value;
+ return scale;
}
-long SensorIIODev::GetExponentValue()
+float SensorIIODev::GetOffsetValue()
{
- return unit_expo_value;
+ return offset;
}
bool SensorIIODev::IsDeviceInitialized(){
ifs.close();
iio_channel.enabled = 1;
- iio_channel.scale = 1.0;
- iio_channel.offset = 0;
iio_channel.name = files[i].substr(0, files[i].length() - 3);
device_number = dev_num = FindDeviceNumberFromName(name, "iio:device");
if (dev_num < 0){
- ALOGE("Failed to find device %s\n", (char*)name.c_str());
+ ALOGE("Failed to find device %s", (char*)name.c_str());
return -EFAULT;
}
}
datum_size = GetSizeFromChannels();
- ALOGV("Datum Size %d", datum_size);
+ ALOGD("%s Datum Size %d", device_name.c_str(), datum_size);
ALOGV("<<%s", __func__);
return 0;
}
return numEventReceived;
}
-int SensorIIODev::ReadHIDMeasurmentUnit(long *unit){
+static int ReadHIDSysValue(int dev, const std::string& sys_str, float *value){
std::stringstream filename;
int size;
std::string long_str;
- filename << IIO_DIR << "/" << "iio:device" << device_number << "/" << unit_str;
+ filename << IIO_DIR << "/" << "iio:device" << dev << "/" << sys_str;
std::ifstream its(filename.str().c_str(), std::ifstream::in);
if (!its.good()){
its.close();
if (long_str.length() > 0){
- *unit = atol(long_str.c_str());
+ *value = atof(long_str.c_str());
return 0;
}
- ALOGE("ReadHIDMeasurmentUnit failed");
+ ALOGE("%s: read %s failed", __func__, filename.str().c_str());
return -EINVAL;
}
-int SensorIIODev::ReadHIDExponentValue(long *exponent){
- std::stringstream filename;
- int size;
- std::string long_str;
-
- filename << IIO_DIR << "/" << "iio:device" << device_number << "/" << unit_expo_str;
-
- std::ifstream its(filename.str().c_str(), std::ifstream::in);
- if (!its.good()){
- ALOGE("%s: Can't Open :%s",
- __func__, filename.str().c_str());
- its.close();
- return -EINVAL;
- }
- std::getline(its, long_str);
- its.close();
+int SensorIIODev::ReadHIDScaleValue(float *scale){
+ return ReadHIDSysValue(device_number, scale_str, scale);
+}
- if (long_str.length() > 0){
- *exponent = atol(long_str.c_str());
- return 0;
- }
- ALOGE("ReadHIDExponentValue failed");
- return -EINVAL;
+int SensorIIODev::ReadHIDOffsetValue(float *offset){
+ return ReadHIDSysValue(device_number, offset_str, offset);
}
// Used by SensorIIO device containers
struct SensorIIOChannel{
std::string name;
- float scale;
- float offset;
unsigned index;
unsigned real_bytes;
unsigned bytes;
int enable_buffer;
int file_id;
int datum_size;
- std::string unit_expo_str;
- std::string unit_str;
+ std::string scale_str;
+ std::string offset_str;
std::string device_name;
std::string channel_prefix_str;
- long unit_expo_value;
- long units_value;
+ float scale;
+ float offset;
int retry_count;
unsigned char *raw_buffer;
int mRefCount;
int DeviceActivate(int dev_num, int state);
double DeviceGetSensitivity(int dev_num);
int DeviceSetSensitivity(int dev_num, double value);
- long GetUnitValue();
- long GetExponentValue();
- int ReadHIDMeasurmentUnit(long *unit);
- int ReadHIDExponentValue(long *exponent);
+ float GetScaleValue();
+ float GetOffsetValue();
+ int ReadHIDScaleValue(float *scale);
+ int ReadHIDOffsetValue(float *offset);
int GetChannelBytesUsedSize(unsigned int channel_no);
virtual int processEvent(unsigned char *raw_data, size_t raw_data_len)
= 0;
virtual int setInitialState();
public:
- SensorIIODev(const std::string& dev_name, const std::string& units, const std::string& exponent, const std::string& channel_prefix);
- SensorIIODev(const std::string& dev_name, const std::string& units, const std::string& exponent, const std::string& channel_prefix, int retry_cnt);
+ SensorIIODev(const std::string& dev_name, const std::string& scale, const std::string& offset, const std::string& channel_prefix, int retry_cnt = 1);
// start/stop stream without changing "enabled" status. For slaves.
int startStop(int enabled);
return syncompass;
case ID_O:
return orientation;
- default:
+ default:
return -EINVAL;
}
return -EINVAL;
return value;
}
-inline float convert_from_vtf_format(int size, int exponent, unsigned int value)
+inline float convert_from_vtf_format(int size, float scale, unsigned int value)
{
int divider=1;
int i;
- float sample;
- int mul = 1.0;
+ float mul = 1.0;
value = value & set_bit_range(0, size*8);
if (value & BIT(size*8-1)) {
value = ((1LL << (size*8)) - value);
mul = -1.0;
}
- sample = value * 1.0;
- if (exponent < 0) {
- exponent = abs(exponent);
- for (i = 0; i < exponent; ++i) {
- divider = divider*10;
- }
- return mul * sample/divider;
- } else {
- return mul * sample * pow(10.0, exponent);
- }
+ return mul * scale * value;
}
// Platform sensor orientatation
// G to m/s2
#define CONVERT_FROM_VTF16(s,d,x) (convert_from_vtf_format(s,d,x))
#define CONVERT_A_G_VTF16E14_X(s,d,x) (DEF_ORIENT_ACCEL_X *\
- convert_from_vtf_format(s,d,x)*GRAVITY)
+ convert_from_vtf_format(s,d,x))
#define CONVERT_A_G_VTF16E14_Y(s,d,x) (DEF_ORIENT_ACCEL_Y *\
- convert_from_vtf_format(s,d,x)*GRAVITY)
+ convert_from_vtf_format(s,d,x))
#define CONVERT_A_G_VTF16E14_Z(s,d,x) (DEF_ORIENT_ACCEL_Z *\
- convert_from_vtf_format(s,d,x)*GRAVITY)
+ convert_from_vtf_format(s,d,x))
// Degree/sec to radian/sec
#define CONVERT_G_D_VTF16E14_X(s,d,x) (DEF_ORIENT_GYRO_X *\
struct hw_device_t** device);
-static int sensors__get_sensors_list(struct sensors_module_t* module,
+static int sensors__get_sensors_list(struct sensors_module_t*,
struct sensor_t const** list)
{
*list = BoardConfig::sensorList();
name: "Samsung Sensor module",
author: "Samsung Electronic Company",
methods: &sensors_module_methods,
- dso: NULL,
+ dso: NULL,
+ reserved: {}
},
get_sensors_list: sensors__get_sensors_list,
};