typedef struct _Sensor_Event_
{
Sensor mSenor;
float values[4];
}SensorEvent_t;
/*
* Defines the prototype to which timer callback functions must conform.
*/
typedef void (*SensorCallbackFunction_t)(SensorEvent_t * mListener);
typedef struct _Sensor_Listener
{
int mSensorType;
SensorCallbackFunction_t pxCallbackFunction;
ListItem_t xSensorListenerListItem;
SensorEvent_t *mEvent;
}SensorListener_t;
void ap_RegisterSensorListener(int RegiterID,int mSensorType,SensorCallbackFunction_t mpxCallbackFunction,SensorEvent_t* mEvent)
{
//Create the new Sensor Listener
SensorListener_t *pxNewSensorListener;
pxNewSensorListener =(SensorListener_t *)pvPortMalloc( sizeof( SensorListener_t ) );
pxNewSensorListener->mSensorType = mSensorType;
pxNewSensorListener->pxCallbackFunction = mpxCallbackFunction;
pxNewSensorListener->mEvent=mEvent;
vListInitialiseItem( &( pxNewSensorListener->xSensorListenerListItem ) );
#ifdef SUPPORT_GSENSOR
//Add the new Item to the list by the Sensor Type
if(mSensorType == TYPE_GYROSCOPE)
{
listSET_LIST_ITEM_VALUE( &( pxNewSensorListener->xSensorListenerListItem ), RegiterID );
listSET_LIST_ITEM_OWNER( &( pxNewSensorListener->xSensorListenerListItem ), pxNewSensorListener );
vListInsert( &xGsensorList, &( pxNewSensorListener->xSensorListenerListItem ) );
}
#endif
PRINTF("The xGsensorList length is %d\n",listCURRENT_LIST_LENGTH(&xGsensorList));
}
void mw_sensor_init(void)
{
//Add Listener List for Sensor Listenor
#ifdef SUPPORT_GSENSOR
vListInitialise( &xGsensorList );
#endif
}
#ifdef SUPPORT_GSENSOR
//Called by the HAL_Sensor
void OnGyroSensorChangedCallBack(float Gxf, float Gyf,float Gzf)
{
List_t * pxConstList;
SensorListener_t* vSensorListener;
pxCOnstList= &xGsensorList;
pxConstList->pxIndex = pxConstList->pxIndex->pxNext;
while(( void * ) ( pxConstList )->pxIndex != ( void * ) &( ( pxConstList )->xListEnd ))
{
vSensorListener = (SensorListener_t *)listGET_LIST_ITEM_OWNER( ( pxConstList )->pxIndex );
vSensorListener->mEvent->values[0] = Gxf;
vSensorListener->mEvent->values[1] = Gyf;
vSensorListener->mEvent->values[2] = Gzf;
vSensorListener->pxCallbackFunction( ( SensorEvent_t *) vSensorListener->mEvent);
pxConstList->pxIndex = pxConstList->pxIndex->pxNext;
}
}
#endif
BaseType_t ap_unRegisterSensorListener(int RegiterID,int mSensorType)
{
SensorListener_t* vSensorListener;
List_t * pxConstList;
if(mSensorType == TYPE_GYROSCOPE)
{
pxCOnstList= &xGsensorList;
}else
{
return pdFAIL;
}
while( (( pxConstList )->pxIndex->xItemValue == RegiterID)
&&(( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) )
)
{
( pxConstList )->pxIndex = ( pxConstList )->pxIndex->pxNext;
}
if(( void * ) ( pxConstList )->pxIndex == ( void * ) &( ( pxConstList )->xListEnd ) )
{
return pdFAIL;
}
vSensorListener = (SensorListener_t *)listGET_LIST_ITEM_OWNER( ( pxConstList )->pxIndex );
( void ) uxListRemove(&(vSensorListener->xSensorListenerListItem));
vPortFree(vSensorListener);
return pdPASS;
}
|