20130108
G-sensor的抖動問題:
現(xiàn)象:當(dāng)手機在桌面靜止的時候,測試應(yīng)用顯示z軸報點為10左右,但會頻繁出現(xiàn)-10。x和y軸也有這個現(xiàn)象。用測試應(yīng)用繪制曲線圖發(fā)現(xiàn)數(shù)據(jù)完全不平滑,高概率出現(xiàn)跳躍,跳躍到負(fù)方向!
調(diào)查描述:
1.硬件采樣和報點數(shù)據(jù)確認(rèn)正確!說明硬件和驅(qū)動沒有問題。
2.檢查event事件,getevent發(fā)現(xiàn),雖然硬件報點每次都有xyz沒有缺失,但是getevent的數(shù)據(jù)有消失一個點的現(xiàn)象。懷疑是這個引起的。便在驅(qū)動中注釋掉xy的report動作,只report Z 的值,然后直接sync。問題依舊!
再試試,在common/libs/libsensors_xxxx/Acc_Lis3dh.cpp中修改event read的代碼,因為懷疑是不是當(dāng)get的數(shù)據(jù)缺失一個的時候,相關(guān)代碼會自動填充一個隨機值導(dǎo)致問題。那么我就將每次讀到的數(shù)據(jù)臨時保存下來,只有讀到一個新的值后才會用新值取代舊值。每次讀到sync的時候才一次性把三個值全部寫入mPendingEvent.acceleration.* 這樣便能保證其他位置不會亂寫這個值!
但是測試結(jié)果依然失敗!情況依舊!
int AccSensor::readEvents(sensors_event_t * data, int count)
{
if (count < 1)
return -EINVAL;
if (mHasPendingEvent) {
mHasPendingEvent = false;
mPendingEvent.timestamp = getTimestamp();
*data = mPendingEvent;
return mEnabled ? 1 : 0;
}
ssize_t n = mInputReader.fill(data_fd);
if (n < 0)
return n;
int numEventReceived = 0;
input_event const *event;
while (count && mInputReader.readEvent(&event)) {
int type = event->type;
if (type == EV_ABS) {
float value = event->value;
if (event->code == EVENT_TYPE_ACCEL_X) {
mPendingEvent.acceleration.x = ACC_UNIT_CONVERSION(value);
} else if (event->code == EVENT_TYPE_ACCEL_Y) {
mPendingEvent.acceleration.y = ACC_UNIT_CONVERSION(value);
} else if (event->code == EVENT_TYPE_ACCEL_Z) {
mPendingEvent.acceleration.z = ACC_UNIT_CONVERSION(value);
}
} else if (type == EV_SYN) {
mPendingEvent.timestamp = timevalToNano(event->time);
if (mEnabled) {
//mSensorCoordinate.coordinate_data_convert(
// mPendingEvent.acceleration.v, INSTALL_DIR);
*data++ = mPendingEvent;
count--;
numEventReceived++;
}
} else {
LOGE("AccSensor: unknown event (type=%d, code=%d)",
type, event->code);
}
mInputReader.next();
}
return numEventReceived;
}
因為2.3.5中用同樣的硬件,沒有任何問題,現(xiàn)在只能采用比較代碼的辦法了!?。?br>比較路徑:
/home/yasin/mywork/xxxxroid235/3rdparty/app/app6820/special/android/hardware/xxxx/libsensors/Lis3dhSensor.cpp
&
/home/yasin/mywork/xxxxroid403code/device/xxxx/common/libs/libsensors_xxxx/Acc_Lis3dh.cpp
發(fā)現(xiàn)異常!
2.3.5的代碼中是沒有
mSensorCoordinate.coordinate_data_convert(mPendingEvent.acceleration.v,INSTALL_DIR);
這個東西的。這就是用來對sensor的貼片進行算法轉(zhuǎn)換的。因為我們不能要求硬件總是把芯片貼成Z軸朝天的樣子把。這就是個轉(zhuǎn)換方向的。但是,轉(zhuǎn)換有這么復(fù)雜嗎????竟然寫了這么多??而且還寫錯了!因為我把這個注釋掉,數(shù)據(jù)就正常了!只是方向錯誤而已,這個很好解決!
其實換方向本身是沒有錯誤的。但是換方向的代碼總是假設(shè)每次換方向之前,這個三個值,xyz都是新的。但問題是event事件會有漏掉的情況,如果漏掉了,那么被漏掉的那個軸的值就是隨機的。這就出了問題。解決的辦法就是每次都把值記錄下來,假如這次漏了X,那么就用上次X的值去代替!
代碼如下:
yasin@ubuntu:~/mywork/xxxxroid403code/device/xxxx/common/libs/libsensors_xxxx$ git diff
diff --git a/common/libs/libsensors_xxxx/Acc_Lis3dh.cpp b/common/libs/libsensors_xxxx/Acc_Lis3dh.cpp
index 79d625c..34509a6 100644
--- a/common/libs/libsensors_xxxx/Acc_Lis3dh.cpp
+++ b/common/libs/libsensors_xxxx/Acc_Lis3dh.cpp
@@ -188,21 +188,30 @@ int AccSensor::readEvents(sensors_event_t * data, int count)
int numEventReceived = 0;
input_event const *event;
+ static float temp_x;
+ static float temp_y;
+ static float temp_z;
while (count && mInputReader.readEvent(&event)) {
int type = event->type;
if (type == EV_ABS) {
float value = event->value;
if (event->code == EVENT_TYPE_ACCEL_X) {
- mPendingEvent.acceleration.x = ACC_UNIT_CONVERSION(value);
+ //mPendingEvent.acceleration.x = ACC_UNIT_CONVERSION(value);
+ temp_x = ACC_UNIT_CONVERSION(value);
} else if (event->code == EVENT_TYPE_ACCEL_Y) {
- mPendingEvent.acceleration.y = ACC_UNIT_CONVERSION(value);
+ //mPendingEvent.acceleration.y = ACC_UNIT_CONVERSION(value);
+ temp_y = ACC_UNIT_CONVERSION(value);
} else if (event->code == EVENT_TYPE_ACCEL_Z) {
- mPendingEvent.acceleration.z = ACC_UNIT_CONVERSION(value);
+ //mPendingEvent.acceleration.z = ACC_UNIT_CONVERSION(value);
+ temp_z = ACC_UNIT_CONVERSION(value);
}
} else if (type == EV_SYN) {
mPendingEvent.timestamp = timevalToNano(event->time);
if (mEnabled) {
+ mPendingEvent.acceleration.x = temp_x;
+ mPendingEvent.acceleration.y = temp_y;
+ mPendingEvent.acceleration.z = temp_z;
mSensorCoordinate.coordinate_data_convert(
mPendingEvent.acceleration.v, INSTALL_DIR);
*data++ = mPendingEvent;
yasin@ubuntu:~/mywork/xxxxroid403code/device/xxxx/common/libs/libsensors_xxxx$
yasin@ubuntu:~/mywork/xxxxroid403code/device/xxxx/common/libs/libsensors_xxxx$
yasin@ubuntu:~/mywork/xxxxroid403code/device/xxxx/common/libs/libsensors_xxxx$
yasin@ubuntu:~/mywork/xxxxroid403code/device/xxxx/common/libs/libsensors_xxxx$
yasin@ubuntu:~/mywork/xxxxroid403code/device/xxxx/common/libs/libsensors_xxxx$
但是為什么event系統(tǒng)會漏掉一些東西,我還沒找到原因
本站僅提供存儲服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請
點擊舉報。