Пример #1
0
//*****************************************************************************
//
//! Initializes the CM3218 driver.
//!
//! \param psInst is a pointer to the CM3218 instance data.
//! \param psI2CInst is a pointer to the I2C driver instance data.
//! \param ui8I2CAddr is the I2C address of the CM3218 device.
//! \param pfnCallback is the function to be called when the initialization has
//! completed (can be \b NULL if a callback is not required).
//! \param pvCallbackData is a pointer that is passed to the callback function.
//!
//! This function initializes the CM3218 driver, preparing it for operation.
//!
//! \return Returns 1 if the CM3218 driver was successfully initialized and 0
//! if it was not.
//
//*****************************************************************************
uint_fast8_t
CM3218Init(tCM3218 *psInst, tI2CMInstance *psI2CInst, uint_fast8_t ui8I2CAddr,
           tSensorCallback *pfnCallback, void *pvCallbackData)
{
    //
    // Initialize the CM3218 instance structure
    //
    psInst->psI2CInst = psI2CInst;
    psInst->ui8Addr = ui8I2CAddr;
    psInst->ui8State = CM3218_STATE_IDLE;
    psInst->ui8IntTime = CM3218_CMD_CONFIG_IT_10 >> CM3218_CMD_CONFIG_IT_S;
    psInst->ui8NewIntTime = CM3218_CMD_CONFIG_IT_10 >> CM3218_CMD_CONFIG_IT_S;

    //
    // The default settings are ok.  Call the callback function if provided.
    //
    if(pfnCallback)
    {
        pfnCallback(pvCallbackData, 0);
    }

    //
    // Success
    //
    return(1);
}
Пример #2
0
//*****************************************************************************
//
//! Initializes the BQ27510G3 driver.
//!
//! \param psInst is a pointer to the BQ27510G3 instance data.
//! \param psI2CInst is a pointer to the I2C driver instance data.
//! \param ui8I2CAddr is the I2C address of the BQ27510G3 device.
//! \param pfnCallback is the function to be called when the initialization has
//! completed (can be \b NULL if a callback is not required).
//! \param pvCallbackData is a pointer that is passed to the callback function.
//!
//! This function initializes the BQ27510G3 driver, preparing it for operation.
//!
//! \return Returns 1 if the BQ27510G3 driver was successfully initialized and
//! 0 if it was not.
//
//*****************************************************************************
uint_fast8_t
BQ27510G3Init(tBQ27510G3 *psInst, tI2CMInstance *psI2CInst,
              uint_fast8_t ui8I2CAddr, tSensorCallback *pfnCallback,
              void *pvCallbackData)
{
    //
    // Initialize the BQ27510G3 instance structure
    //
    psInst->psI2CInst = psI2CInst;
    psInst->ui8Addr = ui8I2CAddr;
    psInst->ui8State = BQ27510G3_STATE_IDLE;

    //
    // Save the callback information.
    //
    psInst->pfnCallback = pfnCallback;
    psInst->pvCallbackData = pvCallbackData;

    //
    // The default settings are ok.  Return success and call the callback.
    //
    if(pfnCallback)
    {
        pfnCallback(pvCallbackData, 0);
    }

    //
    // Success
    //
    return(1);
}
Пример #3
0
		// 遍历子对象。
		XUI_Wnd* XUI_Wnd::ForAllChild( ElementCallback pfnCallback, void* pData )
		{
			for( size_t i = 0; i < m_pChildren.size(); ++i )
			{
				XUI_Wnd* pElement=m_pChildren[i];
				if( pfnCallback( pElement, pData ) )	return pElement;
			}
			return NULL;
		}
Пример #4
0
	bool Composite::EnumChildren(ID idData, ID idChunk, bool (* pfnCallback) (Chunk *, void *), void * pData) const
	{
		if (m_idData != idData) return true;
		
		for (ChildNode * pNode = GetFirstChild(idChunk); pNode; pNode = GetNextChild(pNode,idChunk))
		{
			if (!pfnCallback(pNode->GetChunk(),pData)) return false;
		}
		
		return true;
	}
Пример #5
0
int FileCopy( const char *pFileIn, const char *pFileOut,
			  int (*pfnCallback)( const char *p1, const char *p2, unsigned int nCopied,
			  unsigned int nTotal ) )
{

	FHANDLE fh_in, fh_out;
	u8 chunk[CHUNK_SIZE];
	int read;
	u64 copied, total;

	fh_in = FileOpen( pFileIn, O_RDONLY );
	if( fh_in.fh == -1 )
		return 0;

	fh_out = FileOpen( pFileOut, O_RDWR | O_CREAT | O_TRUNC );
	if( fh_out.fh == -1 )
		return 0;

	total = FileSeek( fh_in, 0, SEEK_END );
	FileSeek( fh_in, 0, SEEK_SET );

	// copy file in chunks
	copied = 0;

	while(1)
	{
		read = FileRead( fh_in, chunk, sizeof(chunk) );

		if( read <= 0 )
			break;

		FileWrite( fh_out, chunk, read );
		copied += read;

		if( pfnCallback )
		{
			if( !pfnCallback( pFileIn, pFileOut, copied, total ) )
			{
				FileClose(fh_in);
				FileClose(fh_out);
				return 0;
			}
		}
	}

	FileClose(fh_in);
	FileClose(fh_out);
	return 1;
}
Пример #6
0
void EnumBinaryModels (FN_EBMCALLBACK *pfnCallback)
{
	CNwnKeyFile &sKeyFile = *g_sLoader .GetNthKeyFile (0);

	//
	// Loop through the resources
	//

	for (int i = 0; i < sKeyFile .GetResCount (); i++)
//	for (int i = 3714; i <= 3714; i++)
	{

		//
		// Skip if not a model
		//

		const CNwnKeyFile::Resource *psRes = sKeyFile .GetRes (i);
		if (psRes ->usType != NwnResType_MDL)
			continue;

		//
		// Print the name of the model as we process
		//

		char szName [17];
		memmove (szName, psRes ->szName, 16);
		szName [16] = 0;
		printf ("Model %s (%d) - ", szName, i);

		//
		// Read the model
		//

		bool fAllocated;
		UINT32 ulSize;
		long lUnknown = 0;
		unsigned char *pauchData = sKeyFile .LoadRes (
			psRes, &ulSize, &fAllocated);

		//
		// If failed, then skip
		//

		if (pauchData == NULL || ulSize < 12)
		{
			printf ("Unable to read or invalid model\n");
			continue;
		}

		//
		// If not binary, skip
		//

		if (pauchData [0] != 0 || pauchData [1] != 0 ||
			pauchData [2] != 0 || pauchData [3] != 0)
		{
			if (fAllocated)
				free (pauchData);
			printf ("ASCII Model, skipped\n");
			continue;
		}

		//
		// Invoke routine
		//

		pfnCallback (psRes, pauchData, ulSize, fAllocated);
	}
}
Пример #7
0
NDASDI_API
BOOL 
WINAPI
NdasDiDeleteOEMInf(
	IN LPCTSTR szFindSpec OPTIONAL, /* if null, oem*.inf */
	IN LPCTSTR mszHardwareIDs, /* should be double _T('\0') terminated */
	IN DWORD dwFlags,
	IN NDASDI_DELETE_OEM_INF_CALLBACK_PROC pfnCallback OPTIONAL,
	IN LPVOID lpContext OPTIONAL)
{
	_ASSERTE(NULL == pfnCallback || !::IsBadCodePtr((FARPROC)pfnCallback));

	BOOL fSuccess = FALSE;

	TCHAR szInfPath[MAX_PATH];
	TCHAR szInfFindSpec[MAX_PATH];

	UINT uichInfPath = ::GetSystemWindowsDirectory(szInfPath, MAX_PATH);
	_ASSERTE(0 != uichInfPath);

	fSuccess = ::PathAppend(szInfPath, _T("INF"));
	_ASSERTE(fSuccess);

	HRESULT hr = ::StringCchCopy(szInfFindSpec, MAX_PATH, szInfPath);
	_ASSERTE(SUCCEEDED(hr));

	fSuccess = ::PathAppend(szInfFindSpec, szFindSpec ? szFindSpec : _T("oem*.inf"));
	_ASSERTE(fSuccess);
	if (!fSuccess)
	{
		return FALSE;
	}

	WIN32_FIND_DATA ffData = {0};

	// prevent file open error dialog from the system
	UINT oldErrorMode = ::SetErrorMode(SEM_FAILCRITICALERRORS);

	HANDLE hFindFile = ::FindFirstFile(szInfFindSpec, &ffData);
	if (INVALID_HANDLE_VALUE == hFindFile) 
	{
		::SetErrorMode(oldErrorMode);
		return FALSE;
	}

	do 
	{

		if (pCompareINF(ffData.cFileName, mszHardwareIDs)) 
		{
			BOOL fSuccess = Setupapi_SetupUninstallOEMInf(
				ffData.cFileName, 
				dwFlags, 
				NULL);

			if (pfnCallback) 
			{
				BOOL fCont = pfnCallback(
					fSuccess ? 0 : ::GetLastError(),
					szInfPath,
					ffData.cFileName,
					lpContext);
				if (!fCont) 
				{
					break;
				}
			}
		}

		fSuccess = ::FindNextFile(hFindFile, &ffData);

	} while (fSuccess);

	::FindClose(hFindFile);
	::SetErrorMode(oldErrorMode);

	return TRUE;
}