mirror of https://github.com/axmolengine/axmol.git
150 lines
4.3 KiB
C++
150 lines
4.3 KiB
C++
|
/****************************************************************************
|
||
|
Copyright (c) 2010 cocos2d-x.org
|
||
|
|
||
|
http://www.cocos2d-x.org
|
||
|
|
||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||
|
of this software and associated documentation files (the "Software"), to deal
|
||
|
in the Software without restriction, including without limitation the rights
|
||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||
|
copies of the Software, and to permit persons to whom the Software is
|
||
|
furnished to do so, subject to the following conditions:
|
||
|
|
||
|
The above copyright notice and this permission notice shall be included in
|
||
|
all copies or substantial portions of the Software.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||
|
THE SOFTWARE.
|
||
|
****************************************************************************/
|
||
|
|
||
|
#include "CCAccelerometer_bada.h"
|
||
|
#include "ccMacros.h"
|
||
|
|
||
|
using namespace Osp::Uix;
|
||
|
|
||
|
NS_CC_BEGIN;
|
||
|
|
||
|
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
|
||
|
|
||
|
CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL)
|
||
|
{
|
||
|
}
|
||
|
|
||
|
CCAccelerometer::~CCAccelerometer()
|
||
|
{
|
||
|
m_spCCAccelerometer = NULL;
|
||
|
}
|
||
|
|
||
|
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
|
||
|
{
|
||
|
|
||
|
if (m_spCCAccelerometer == NULL)
|
||
|
{
|
||
|
m_spCCAccelerometer = new CCAccelerometer();
|
||
|
}
|
||
|
|
||
|
return m_spCCAccelerometer;
|
||
|
}
|
||
|
|
||
|
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
||
|
{
|
||
|
m_pAccelDelegate = pDelegate;
|
||
|
|
||
|
if (pDelegate)
|
||
|
{
|
||
|
// enableAccelerometerJNI();
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
// disableAccelerometerJNI();
|
||
|
}
|
||
|
}
|
||
|
void CCAccelerometer::update(float x, float y, float z, long sensorTimeStamp)
|
||
|
{
|
||
|
|
||
|
}
|
||
|
/*
|
||
|
void CCAccelerometer::addDelegate(CCAccelerometerDelegate* pDelegate)
|
||
|
{
|
||
|
CCAccelerometerHandler* pHandler = CCAccelerometerHandler::handlerWithDelegate(pDelegate);
|
||
|
|
||
|
if (pHandler)
|
||
|
{
|
||
|
m_pDelegates->addObject(pHandler);
|
||
|
|
||
|
if (!m_pSensor)
|
||
|
{
|
||
|
long interval = 10;
|
||
|
bool available = false;
|
||
|
result r = E_INVALID_STATE;
|
||
|
m_pSensor = new SensorManager();
|
||
|
m_pSensor->Construct();
|
||
|
|
||
|
available = m_pSensor->IsAvailable(SENSOR_TYPE_ACCELERATION);
|
||
|
|
||
|
if (true == available)
|
||
|
{
|
||
|
long intervalTemp = 0;
|
||
|
m_pSensor->GetMaxInterval(SENSOR_TYPE_ACCELERATION, intervalTemp);
|
||
|
if (interval > intervalTemp)
|
||
|
interval = intervalTemp;
|
||
|
m_pSensor->GetMinInterval(SENSOR_TYPE_ACCELERATION, intervalTemp);
|
||
|
if (interval < intervalTemp)
|
||
|
interval = intervalTemp;
|
||
|
|
||
|
r = m_pSensor->AddSensorListener(*this, SENSOR_TYPE_ACCELERATION, interval, false);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void CCAccelerometer::didAccelerate(CCAcceleration* pAccelerationValue)
|
||
|
{
|
||
|
CCAccelerometerHandler *pHandler;
|
||
|
CCAccelerometerDelegate *pDelegate;
|
||
|
CCMutableArray<CCAccelerometerHandler*>::CCMutableArrayIterator iter;
|
||
|
|
||
|
if (m_pDelegates->count() > 0)
|
||
|
{
|
||
|
for (iter = m_pDelegates->begin(); iter != m_pDelegates->end(); ++iter)
|
||
|
{
|
||
|
pHandler = *iter;
|
||
|
pDelegate = pHandler->getDelegate();
|
||
|
pDelegate->didAccelerate(pAccelerationValue);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
*/
|
||
|
void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorData, result r)
|
||
|
{
|
||
|
long timeStamp = 0;
|
||
|
float x = 0.0, y = 0.0, z = 0.0;
|
||
|
|
||
|
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_TIMESTAMP, timeStamp);
|
||
|
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_X, x);
|
||
|
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Y, y);
|
||
|
sensorData.GetValue((SensorDataKey)ACCELERATION_DATA_KEY_Z, z);
|
||
|
|
||
|
CCAcceleration AccValue;
|
||
|
AccValue.x = -x;
|
||
|
AccValue.y = -y;
|
||
|
AccValue.z = -z;
|
||
|
AccValue.timestamp = timeStamp;
|
||
|
// AppLog("x = %d, y = %d, z = %d, timestamp = %d", AccValue.x, AccValue.y, AccValue.z, AccValue.timestamp);
|
||
|
// call delegates' didAccelerate function
|
||
|
//cjh didAccelerate(&AccValue);
|
||
|
// bHandled = TRUE;
|
||
|
|
||
|
AppLog("####################TimeStamp:[%d], Accel.x,y,z:[%f,%f,%f]",
|
||
|
timeStamp,
|
||
|
x, y, z);
|
||
|
|
||
|
}
|
||
|
|
||
|
NS_CC_END;
|