Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

hardware-intel-libsensors: Commit

hardware/intel/libsensors


Commit MetaInfo

Revisionfb40472042b7c1eef2f19af718ba6df3cbac50df (tree)
Time2014-12-28 21:12:37
AuthorChih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Merge remote-tracking branch 'x86/kitkat-x86' into lollipop-x86

Change Summary

Incremental Difference

--- a/HidSensor_Accel3D.cpp
+++ b/HidSensor_Accel3D.cpp
@@ -76,11 +76,11 @@ int AccelSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
7676 (raw_data + 2), *(raw_data + 3), *(raw_data + 4), *(raw_data + 5));
7777 sample = (struct accel_3d_sample*)raw_data;
7878 mPendingEvent.data[0] = mPendingEvent.acceleration.x =
79- CONVERT_A_G_VTF16E14_X(GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->accel_x);
79+ CONVERT_A_G_VTF16E14_X(GetChannelBytesUsedSize(CHANNEL_X), GetScaleValue(), sample->accel_x);
8080 mPendingEvent.data[1] = mPendingEvent.acceleration.y =
81- CONVERT_A_G_VTF16E14_Y(GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->accel_y);
81+ CONVERT_A_G_VTF16E14_Y(GetChannelBytesUsedSize(CHANNEL_Y), GetScaleValue(), sample->accel_y);
8282 mPendingEvent.data[2] = mPendingEvent.acceleration.z =
83- CONVERT_A_G_VTF16E14_Z(GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->accel_z);
83+ CONVERT_A_G_VTF16E14_Z(GetChannelBytesUsedSize(CHANNEL_Z), GetScaleValue(), sample->accel_z);
8484
8585 ALOGV("ACCEL 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.acceleration.x,
8686 mPendingEvent.acceleration.y, mPendingEvent.acceleration.z);
--- a/HidSensor_Compass3D.cpp
+++ b/HidSensor_Compass3D.cpp
@@ -69,12 +69,13 @@ int CompassSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
6969 }
7070 sample = (struct compass_3d_sample*)raw_data;
7171
72+ float sc = GetScaleValue();
7273 mPendingEvent.data[0] = mPendingEvent.magnetic.x = CONVERT_M_MG_VTF16E14_X
73- (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->compass_x);
74+ (GetChannelBytesUsedSize(CHANNEL_X), sc, sample->compass_x);
7475 mPendingEvent.data[1] = mPendingEvent.magnetic.y = CONVERT_M_MG_VTF16E14_Y
75- (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->compass_y);
76+ (GetChannelBytesUsedSize(CHANNEL_Y), sc, sample->compass_y);
7677 mPendingEvent.data[2] = mPendingEvent.magnetic.z = CONVERT_M_MG_VTF16E14_Z
77- (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->compass_z);
78+ (GetChannelBytesUsedSize(CHANNEL_Z), sc, sample->compass_z);
7879
7980 ALOGV("COMPASS 3D Sample %fuT %fuT %fuT\n", mPendingEvent.magnetic.x,
8081 mPendingEvent.magnetic.y, mPendingEvent.magnetic.z);
--- a/HidSensor_Gyro3D.cpp
+++ b/HidSensor_Gyro3D.cpp
@@ -70,36 +70,14 @@ int GyroSensor::processEvent(unsigned char *raw_data, size_t raw_data_len){
7070 return - 1;
7171 }
7272 sample = (struct gyro_3d_sample*)raw_data;
73- switch (GetUnitValue()) {
74- case HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED:
75- case HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND:
76- mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_G_D_VTF16E14_X
77- (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->gyro_x)
78- ;
79- mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_G_D_VTF16E14_Y
80- (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->gyro_y)
81- ;
82- mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_G_D_VTF16E14_Z
83- (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->gyro_z)
84- ;
85- break;
86- case HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND:
87- mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_FROM_VTF16
88- (GetChannelBytesUsedSize(CHANNEL_X), GetExponentValue(), sample->gyro_x)
89- ;
90- mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_FROM_VTF16
91- (GetChannelBytesUsedSize(CHANNEL_Y), GetExponentValue(), sample->gyro_y)
92- ;
93- mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_FROM_VTF16
94- (GetChannelBytesUsedSize(CHANNEL_Z), GetExponentValue(), sample->gyro_z)
95- ;
96- break;
97- default:
98- ALOGE("Gyro Unit is not supported");
99- break;
100- }
101-
102- ALOGV("GYRO 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.gyro.x,
73+ float sc = GetScaleValue();
74+ mPendingEvent.data[0] = mPendingEvent.gyro.x = CONVERT_FROM_VTF16
75+ (GetChannelBytesUsedSize(CHANNEL_X), sc, sample->gyro_x);
76+ mPendingEvent.data[1] = mPendingEvent.gyro.y = CONVERT_FROM_VTF16
77+ (GetChannelBytesUsedSize(CHANNEL_Y), sc, sample->gyro_y);
78+ mPendingEvent.data[2] = mPendingEvent.gyro.z = CONVERT_FROM_VTF16
79+ (GetChannelBytesUsedSize(CHANNEL_Z), sc, sample->gyro_z);
80+ ALOGD("GYRO 3D Sample %fm/s2 %fm/s2 %fm/s2\n", mPendingEvent.gyro.x,
10381 mPendingEvent.gyro.y, mPendingEvent.gyro.z);
10482 ALOGV("<<%s", __func__);
10583 return 0;
--- a/OrientationSensor.cpp
+++ b/OrientationSensor.cpp
@@ -67,10 +67,10 @@ int OrientationSensor::processEvent(unsigned char *data, size_t len)
6767
6868 float vals[3];
6969 unsigned int *sample = (unsigned int*)data;
70- long ex = GetExponentValue();
70+ float sc = GetScaleValue();
7171 for (int i=0; i<3; i++) {
7272 int sz = GetChannelBytesUsedSize(i);
73- vals[i] = convert_from_vtf_format(sz, ex, sample[i]);
73+ vals[i] = convert_from_vtf_format(sz, sc, sample[i]);
7474 }
7575
7676 // When held in the Android convention frame (X to the right, Y
--- a/RotVecSensor.cpp
+++ b/RotVecSensor.cpp
@@ -39,9 +39,9 @@ const struct sensor_t RotVecSensor::sSensorInfo_rotvec = {
3939 };
4040
4141 RotVecSensor::RotVecSensor()
42- : SensorIIODev("dev_rotation", // name
43- "in_rot_scale", // units sysfs node
44- "in_rot_offset", // exponent sysfs node
42+ : SensorIIODev("magn_3d", // name
43+ "in_magn_scale", // units sysfs node
44+ "in_magn_offset",// exponent sysfs node
4545 "in_rot_", // channel_prefix
4646 10) // retry count
4747 {
@@ -62,11 +62,6 @@ int RotVecSensor::processEvent(unsigned char *data, size_t len)
6262 return -1;
6363 }
6464
65- if (len < 4*sizeof(unsigned int)) {
66- ALOGE("Insufficient length \n");
67- return -1;
68- }
69-
7065 // The Intel Sensor Hub emits a normalized x/y/z/w quaternion
7166 // which acts to rotate points in the device coordinate system
7267 // (left/up/out) to the world coordinate system (north/east/down).
@@ -74,10 +69,10 @@ int RotVecSensor::processEvent(unsigned char *data, size_t len)
7469 // copy out the raw data.
7570
7671 unsigned int *sample = (unsigned int*)data;
77- long ex = GetExponentValue();
78- for (int i=0; i<4; i++) {
72+ float sc = GetScaleValue();
73+ for (int i=0; i < (len / sizeof(*sample)); i++) {
7974 int sz = GetChannelBytesUsedSize(i);
80- mPendingEvent.data[i] = convert_from_vtf_format(sz, ex, sample[i]);
75+ mPendingEvent.data[i] = convert_from_vtf_format(sz, sc, sample[i]);
8176 }
8277
8378 if (mSynthCompass)
--- a/SensorIIODev.cpp
+++ b/SensorIIODev.cpp
@@ -27,17 +27,17 @@ static const std::string IIO_DIR = "/sys/bus/iio/devices";
2727 static const int DEF_BUFFER_LEN = 2;
2828 static const int DEF_HYST_VALUE = 0;
2929
30-SensorIIODev::SensorIIODev(const std::string& dev_name, const std::string& units,
31- const std::string& exponent,
30+SensorIIODev::SensorIIODev(const std::string& dev_name, const std::string& scale,
31+ const std::string& offset,
3232 const std::string& channel_prefix, int retry_cnt)
3333 : SensorBase(""),
3434 initialized(false),
35- unit_expo_str(exponent),
36- unit_str(units),
35+ scale_str(scale),
36+ offset_str(offset),
3737 device_name(dev_name),
3838 channel_prefix_str(channel_prefix),
39- unit_expo_value(0),
40- units_value(0),
39+ scale(0.0),
40+ offset(0.0),
4141 retry_count(retry_cnt),
4242 raw_buffer(NULL),
4343 mRefCount(0),
@@ -46,25 +46,6 @@ SensorIIODev::SensorIIODev(const std::string& dev_name, const std::string& units
4646 ALOGV("%s", __func__);
4747 }
4848
49-SensorIIODev::SensorIIODev(const std::string& dev_name, const std::string& units,
50- const std::string& exponent,
51- const std::string& channel_prefix)
52- : SensorBase(""),
53- initialized(false),
54- unit_expo_str(exponent),
55- unit_str(units),
56- device_name(dev_name),
57- channel_prefix_str(channel_prefix),
58- unit_expo_value(0),
59- units_value(0),
60- retry_count(1),
61- raw_buffer(NULL),
62- mRefCount(0)
63-{
64-
65- ALOGV("%s", __func__);
66-}
67-
6849 int SensorIIODev::discover()
6950 {
7051 int cnt;
@@ -80,7 +61,7 @@ int SensorIIODev::discover()
8061 if(*sampmin)
8162 sample_delay_min_ms = strtol(sampmin, NULL, 10);
8263
83- ALOGD(">>%s discover", __func__);
64+ ALOGD(">>discover %s", device_name.c_str());
8465 for (cnt = 0; cnt < retry_count; cnt++) {
8566 status = ParseIIODirectory(device_name);
8667 if (status >= 0){
@@ -88,12 +69,11 @@ int SensorIIODev::discover()
8869 initialized = true;
8970 filename << "/dev/iio:device" << device_number;
9071 mDevPath = filename.str();
91- ALOGV("mDevPath %s", mDevPath.c_str());
72+ ALOGI("found %s at %s", device_name.c_str(), mDevPath.c_str());
9273 ret = 0;
9374 break;
94- }
95- else{
96- ALOGE("Sensor IIO Init failed, retry left:%d\n", retry_count-cnt);
75+ } else {
76+ ALOGE("%s not found, retry left: %d", device_name.c_str(), retry_count-cnt);
9777 mDevPath = "";
9878 ret = -1;
9979 }
@@ -145,7 +125,7 @@ int SensorIIODev::startStop(int enabled)
145125 int ret =0;
146126 double sensitivity;
147127
148- ALOGD(">>%s enabled:%d", __func__, enabled);
128+ ALOGD(">>%s enabled: %d", device_name.c_str(), enabled);
149129
150130 if (enabled){
151131 if ((ret = discover()) < 0) {
@@ -163,9 +143,9 @@ int SensorIIODev::startStop(int enabled)
163143 EnableBuffer(1);
164144 EnableBuffer(0);
165145
166- if (ReadHIDExponentValue(&unit_expo_value) < 0)
146+ if (ReadHIDScaleValue(&scale) < 0)
167147 goto err_ret;
168- if (ReadHIDMeasurmentUnit(&units_value) < 0)
148+ if (ReadHIDOffsetValue(&offset) < 0)
169149 goto err_ret;
170150 if (SetDataReadyTrigger(GetDeviceNumber(), true) < 0)
171151 goto err_ret;
@@ -178,6 +158,7 @@ int SensorIIODev::startStop(int enabled)
178158 goto err_ret;
179159 if (AllocateRxBuffer() < 0)
180160 goto err_ret;
161+ ALOGI("%s: scale=%f offset=%f", device_name.c_str(), scale, offset);
181162 }
182163 else{
183164 if (SetDataReadyTrigger(GetDeviceNumber(), false) < 0)
@@ -195,7 +176,7 @@ int SensorIIODev::startStop(int enabled)
195176
196177 err_ret:
197178 close();
198- ALOGE("SesnorIIO: Enable failed\n");
179+ ALOGE("SesnorIIO: %s Enable failed", device_name.c_str());
199180 return -1;
200181 }
201182
@@ -205,7 +186,7 @@ int SensorIIODev::setDelay(int64_t delay_ns){
205186
206187 ALOGV(">>%s %ld", __func__, delay_ns);
207188 if (IsDeviceInitialized() == false){
208- ALOGE("Device was not initialized \n");
189+ ALOGE("Device %s was not initialized", device_name.c_str());
209190 return -EFAULT;
210191 }
211192 if (ms){
@@ -221,14 +202,14 @@ int SensorIIODev::setInitialState(){
221202 return 0;
222203 }
223204
224-long SensorIIODev::GetUnitValue()
205+float SensorIIODev::GetScaleValue()
225206 {
226- return units_value;
207+ return scale;
227208 }
228209
229-long SensorIIODev::GetExponentValue()
210+float SensorIIODev::GetOffsetValue()
230211 {
231- return unit_expo_value;
212+ return offset;
232213 }
233214
234215 bool SensorIIODev::IsDeviceInitialized(){
@@ -439,8 +420,6 @@ int SensorIIODev::BuildChannelList(){
439420 ifs.close();
440421
441422 iio_channel.enabled = 1;
442- iio_channel.scale = 1.0;
443- iio_channel.offset = 0;
444423
445424 iio_channel.name = files[i].substr(0, files[i].length() - 3);
446425
@@ -520,7 +499,7 @@ int SensorIIODev::ParseIIODirectory(const std::string& name){
520499
521500 device_number = dev_num = FindDeviceNumberFromName(name, "iio:device");
522501 if (dev_num < 0){
523- ALOGE("Failed to find device %s\n", (char*)name.c_str());
502+ ALOGE("Failed to find device %s", (char*)name.c_str());
524503 return -EFAULT;
525504 }
526505
@@ -561,7 +540,7 @@ int SensorIIODev::ParseIIODirectory(const std::string& name){
561540 }
562541
563542 datum_size = GetSizeFromChannels();
564- ALOGV("Datum Size %d", datum_size);
543+ ALOGD("%s Datum Size %d", device_name.c_str(), datum_size);
565544 ALOGV("<<%s", __func__);
566545 return 0;
567546 }
@@ -700,12 +679,12 @@ int SensorIIODev::readEvents(sensors_event_t *data, int count){
700679 return numEventReceived;
701680 }
702681
703-int SensorIIODev::ReadHIDMeasurmentUnit(long *unit){
682+static int ReadHIDSysValue(int dev, const std::string& sys_str, float *value){
704683 std::stringstream filename;
705684 int size;
706685 std::string long_str;
707686
708- filename << IIO_DIR << "/" << "iio:device" << device_number << "/" << unit_str;
687+ filename << IIO_DIR << "/" << "iio:device" << dev << "/" << sys_str;
709688
710689 std::ifstream its(filename.str().c_str(), std::ifstream::in);
711690 if (!its.good()){
@@ -718,34 +697,17 @@ int SensorIIODev::ReadHIDMeasurmentUnit(long *unit){
718697 its.close();
719698
720699 if (long_str.length() > 0){
721- *unit = atol(long_str.c_str());
700+ *value = atof(long_str.c_str());
722701 return 0;
723702 }
724- ALOGE("ReadHIDMeasurmentUnit failed");
703+ ALOGE("%s: read %s failed", __func__, filename.str().c_str());
725704 return -EINVAL;
726705 }
727706
728-int SensorIIODev::ReadHIDExponentValue(long *exponent){
729- std::stringstream filename;
730- int size;
731- std::string long_str;
732-
733- filename << IIO_DIR << "/" << "iio:device" << device_number << "/" << unit_expo_str;
734-
735- std::ifstream its(filename.str().c_str(), std::ifstream::in);
736- if (!its.good()){
737- ALOGE("%s: Can't Open :%s",
738- __func__, filename.str().c_str());
739- its.close();
740- return -EINVAL;
741- }
742- std::getline(its, long_str);
743- its.close();
707+int SensorIIODev::ReadHIDScaleValue(float *scale){
708+ return ReadHIDSysValue(device_number, scale_str, scale);
709+}
744710
745- if (long_str.length() > 0){
746- *exponent = atol(long_str.c_str());
747- return 0;
748- }
749- ALOGE("ReadHIDExponentValue failed");
750- return -EINVAL;
711+int SensorIIODev::ReadHIDOffsetValue(float *offset){
712+ return ReadHIDSysValue(device_number, offset_str, offset);
751713 }
--- a/SensorIIODev.h
+++ b/SensorIIODev.h
@@ -37,8 +37,6 @@
3737 // Used by SensorIIO device containers
3838 struct SensorIIOChannel{
3939 std::string name;
40- float scale;
41- float offset;
4240 unsigned index;
4341 unsigned real_bytes;
4442 unsigned bytes;
@@ -68,12 +66,12 @@ private:
6866 int enable_buffer;
6967 int file_id;
7068 int datum_size;
71- std::string unit_expo_str;
72- std::string unit_str;
69+ std::string scale_str;
70+ std::string offset_str;
7371 std::string device_name;
7472 std::string channel_prefix_str;
75- long unit_expo_value;
76- long units_value;
73+ float scale;
74+ float offset;
7775 int retry_count;
7876 unsigned char *raw_buffer;
7977 int mRefCount;
@@ -114,10 +112,10 @@ protected:
114112 int DeviceActivate(int dev_num, int state);
115113 double DeviceGetSensitivity(int dev_num);
116114 int DeviceSetSensitivity(int dev_num, double value);
117- long GetUnitValue();
118- long GetExponentValue();
119- int ReadHIDMeasurmentUnit(long *unit);
120- int ReadHIDExponentValue(long *exponent);
115+ float GetScaleValue();
116+ float GetOffsetValue();
117+ int ReadHIDScaleValue(float *scale);
118+ int ReadHIDOffsetValue(float *offset);
121119 int GetChannelBytesUsedSize(unsigned int channel_no);
122120 virtual int processEvent(unsigned char *raw_data, size_t raw_data_len)
123121 = 0;
@@ -127,8 +125,7 @@ protected:
127125 virtual int setInitialState();
128126
129127 public:
130- SensorIIODev(const std::string& dev_name, const std::string& units, const std::string& exponent, const std::string& channel_prefix);
131- SensorIIODev(const std::string& dev_name, const std::string& units, const std::string& exponent, const std::string& channel_prefix, int retry_cnt);
128+ SensorIIODev(const std::string& dev_name, const std::string& scale, const std::string& offset, const std::string& channel_prefix, int retry_cnt = 1);
132129
133130 // start/stop stream without changing "enabled" status. For slaves.
134131 int startStop(int enabled);
--- a/hsb/BoardConfig.cpp
+++ b/hsb/BoardConfig.cpp
@@ -124,7 +124,7 @@ int BoardConfig::handleToDriver(int handle)
124124 return syncompass;
125125 case ID_O:
126126 return orientation;
127- default:
127+ default:
128128 return -EINVAL;
129129 }
130130 return -EINVAL;
--- a/hsb/SensorConfig.h
+++ b/hsb/SensorConfig.h
@@ -125,28 +125,18 @@ inline unsigned int set_bit_range(int start, int end)
125125 return value;
126126 }
127127
128-inline float convert_from_vtf_format(int size, int exponent, unsigned int value)
128+inline float convert_from_vtf_format(int size, float scale, unsigned int value)
129129 {
130130 int divider=1;
131131 int i;
132- float sample;
133- int mul = 1.0;
132+ float mul = 1.0;
134133
135134 value = value & set_bit_range(0, size*8);
136135 if (value & BIT(size*8-1)) {
137136 value = ((1LL << (size*8)) - value);
138137 mul = -1.0;
139138 }
140- sample = value * 1.0;
141- if (exponent < 0) {
142- exponent = abs(exponent);
143- for (i = 0; i < exponent; ++i) {
144- divider = divider*10;
145- }
146- return mul * sample/divider;
147- } else {
148- return mul * sample * pow(10.0, exponent);
149- }
139+ return mul * scale * value;
150140 }
151141
152142 // Platform sensor orientatation
@@ -161,11 +151,11 @@ inline float convert_from_vtf_format(int size, int exponent, unsigned int value)
161151 // G to m/s2
162152 #define CONVERT_FROM_VTF16(s,d,x) (convert_from_vtf_format(s,d,x))
163153 #define CONVERT_A_G_VTF16E14_X(s,d,x) (DEF_ORIENT_ACCEL_X *\
164- convert_from_vtf_format(s,d,x)*GRAVITY)
154+ convert_from_vtf_format(s,d,x))
165155 #define CONVERT_A_G_VTF16E14_Y(s,d,x) (DEF_ORIENT_ACCEL_Y *\
166- convert_from_vtf_format(s,d,x)*GRAVITY)
156+ convert_from_vtf_format(s,d,x))
167157 #define CONVERT_A_G_VTF16E14_Z(s,d,x) (DEF_ORIENT_ACCEL_Z *\
168- convert_from_vtf_format(s,d,x)*GRAVITY)
158+ convert_from_vtf_format(s,d,x))
169159
170160 // Degree/sec to radian/sec
171161 #define CONVERT_G_D_VTF16E14_X(s,d,x) (DEF_ORIENT_GYRO_X *\
--- a/sensors.cpp
+++ b/sensors.cpp
@@ -47,7 +47,7 @@ static int open_sensors(const struct hw_module_t* module, const char* id,
4747 struct hw_device_t** device);
4848
4949
50-static int sensors__get_sensors_list(struct sensors_module_t* module,
50+static int sensors__get_sensors_list(struct sensors_module_t*,
5151 struct sensor_t const** list)
5252 {
5353 *list = BoardConfig::sensorList();
@@ -67,7 +67,8 @@ struct sensors_module_t HAL_MODULE_INFO_SYM = {
6767 name: "Samsung Sensor module",
6868 author: "Samsung Electronic Company",
6969 methods: &sensors_module_methods,
70- dso: NULL,
70+ dso: NULL,
71+ reserved: {}
7172 },
7273 get_sensors_list: sensors__get_sensors_list,
7374 };
Show on old repository browser