取GVector信息
GVector SamsungGSensor::GetGVector()
{
SmiAccelerometerVector accel;
if(SmiAccelerometerGetVector(&accel) == SMI_SUCCESS)
{
GVector gVector;
gVector.x = accel.x;
gVector.y = accel.y;
gVector.z = accel.z;
return gVector;
}
throw;
}
调用SmiAccelerometerGetVector() API取出GVector信息。
订阅GVector信息
Samsung的API提供订阅功能。
void SamsungGSensor::Register()
{
SmiAccelerometerCapabilities cap;
if( SmiAccelerometerGetCapabilities(&cap) != SMI_SUCCESS)
{
throw;
}
SmiAccelerometerHandler h = &GetVectorHandler;
if(SmiAccelerometerRegisterHandler(1000, h) != SMI_SUCCESS)
{
throw;
}
//Execute the task every second.
//Start(1000);
}
SmiAccelerometerGetCapabilities()函数检查GSensor的情况,SmiAccelerometerRegisterHandler()注册GetVectorHandler处理函数定期取出GVector信息,SmiAccelerometerRegisterHandler()的第一个参数为interval(取数据的间隔),第二个为回调处理函数,该函数只能为static。
void SamsungGSensor::Unregister()
{
SmiAccelerometerUnregisterHandler();
//Stop();
}
上面是反注册函数。
void SamsungGSensor::GetVectorHandler(SmiAccelerometerVector accel)
{
GVector gVector;
gVector.x = accel.x;
gVector.y = accel.y;
gVector.z = accel.z;
SamsungGSensor::GetInstance()->GVectorChanged(gVector);
}