コード例 #1
0
ファイル: i2cshell.cpp プロジェクト: meesokim/circle
unsigned CI2CShell::GetNumber (const char *pName, unsigned nMinimum, unsigned nMaximum)
{
	assert (pName != 0);

	CString Token;
	if (!GetToken (&Token))
	{
		Print ("%s expected\n", pName);
		return INVALID_NUMBER;
	}

	unsigned nValue = ConvertNumber (Token);
	if (nValue == INVALID_NUMBER)
	{
		Print ("Invalid number: %s\n", (const char *) Token);
		return INVALID_NUMBER;
	}

	assert (nMinimum < nMaximum);
	if (   nValue < nMinimum
	    || nValue > nMaximum)
	{
		Print ("%s out of range: %s\n", pName, (const char *) Token);
		return INVALID_NUMBER;
	}

	return nValue;
}
コード例 #2
0
ファイル: i2cshell.cpp プロジェクト: meesokim/circle
boolean CI2CShell::Write (void)
{
	u8 Buffer[256];

	CString Data;
	unsigned nCount;
	for (nCount = 0; nCount < sizeof Buffer && GetToken (&Data); nCount++)
	{
		unsigned nData = ConvertNumber (Data);
		if (nData == INVALID_NUMBER)
		{
			UnGetToken (Data);
			break;
		}

		if (nData > 255)
		{
			Print ("Data byte out of range: %s\n", (const char *) Data);
			return FALSE;
		}

		Buffer[nCount] = (u8) nData;
	}

	if (nCount == 0)
	{
		Print ("Data byte expected\n");
		return FALSE;
	}

	if (m_ucSlaveAddress == INVALID_SLAVE)
	{
		Print ("Slave address not set\n");
		return FALSE;
	}

	assert (m_pI2CMaster != 0);
	m_pI2CMaster->SetClock (m_nI2CClockHz);

	int nResult = m_pI2CMaster->Write (m_ucSlaveAddress, Buffer, nCount);
	if (nResult <= 0)
	{
		PrintI2CError (nResult);
		return FALSE;
	}

	return TRUE;
}
コード例 #3
0
ファイル: math_3d.cpp プロジェクト: ohtorii/math_3d
int _tmain(int argc, _TCHAR* argv[])
{
	bool		result = false;
	TArgInfo	info;

	ParseArg(info,argc,argv);
	const std::string &m = info.m_mode;

	//printf("mode=%s\n", m.c_str());

	if("f32_hex" == m){
		result = Float32ToHex(info);
	}else if("f64_hex" == m){
		result = Float64ToHex(info);
	}else if("hex_f32" == m){
		result = HexToFloat32(info);
	}else if("hex_f64" == m){
		result = HexToFloat64(info);
	}else if("2_10" == m){
		result = ConvertNumber(info,10,2);
	}else if("2_16" == m){
		result = ConvertNumber(info,16,2);
	}else if("10_2" == m){
		result = ConvertNumber(info,2,10);
	}else if("10_16" == m){
		result = ConvertNumber(info,16,10);
	}else if("16_2" == m){
		result = ConvertNumber(info,2,16);
	}else if("16_10" == m){
		result = ConvertNumber(info,10,16);
	}else if("r_d" == m){
		result = RadianToDegree(info);
	}else if("d_r" == m){
		result = DegreeToRadian(info);
	}else if("v_h" == m){
		result = MatrixSub(info,FovVerticalToHorizontal,3);
	}else if("h_v" == m){
		result = MatrixSub(info,FovHorizontalToVertical,3);
	}else if("ql" == m){
		result = MatrixSub(info,QuatLength,4);
	}else if("qn" == m){
		result = MatrixSub(info,QuatNormalize,4);
	}else if("qi" == m){
		result = MatrixSub(info,QuatInverse,4);
	}else if("q_m33" == m){
		result = MatrixSub(info,QuatToMat,4);
	}else if("q_a" == m){
		result = MatrixSub(info,QuatToAAng,4);
	}else if("q_xyz" == m){
		result = MatrixSub(info,QuatToXYZ,4);
	}else if("m33_q" == m){
		result = MatrixSub(info,Mat33ToQuat,9);
	}else if("m33_a" == m){
		result = MatrixSub(info,Mat33ToAAng,9);
	}else if("m33t" == m){
		result = MatrixSub(info,Mat33Transpose,9);
	}else if("m33d" == m){
		result = MatrixSub(info,Mat33Determinant,9);
	}else if("m33i" == m){
		result = MatrixSub(info,Mat33Invert,9);
	}else if("m33_s" == m){
		result = MatrixSub(info,Mat33Scale,9);
	}else if("x_m33" == m){
		result = MatrixSub(info,Mat33RotX,1);
	}else if("y_m33" == m){
		result = MatrixSub(info,Mat33RotY,1);
	}else if("z_m33" == m){
		result = MatrixSub(info,Mat33RotZ,1);
	}else if("yxz_m33" == m){
		result = MatrixSub(info,Mat33RotYXZ,3);
	}else if("zxy_m33" == m){
		result = MatrixSub(info,Mat33RotZXY,3);
	}else if("zyx_m33" == m){
		result = MatrixSub(info,Mat33RotZYX,3);
	}else if("yzx_m33" == m){
		result = MatrixSub(info,Mat33RotYZX,3);
	}else if("xzy_m33" == m){
		result = MatrixSub(info,Mat33RotXZY,3);
	}else if("xyz_m33" == m){
		result = MatrixSub(info,Mat33RotXYZ,3);
	}else if("m33_yxz" == m){
		result = MatrixSub(info,Mat33EulerYXZ,9);
	}else if("m33_zxy" == m){
		result = MatrixSub(info,Mat33EulerZXY,9);
	}else if("m33_zyx" == m){
		result = MatrixSub(info,Mat33EulerZYX,9);
	}else if("m33_yzx" == m){
		result = MatrixSub(info,Mat33EulerYZX,9);
	}else if("m33_xzy" == m){
		result = MatrixSub(info,Mat33EulerXZY,9);
	}else if("m33_xyz" == m){
		result = MatrixSub(info,Mat33EulerXYZ,9);
	}else if("v3l" == m){
		result = MatrixSub(info,Vector3Length,3);
	}else if("v3n" == m){
		result = MatrixSub(info,Vector3Normalize,3);
	}

	if(result){
		return 0;
	}
	usage();

	return 1;
}