Exemplo n.º 1
0
/*!
  Get orientation sensor's elements. The vector format and coordination system
   follow the Android definition.  Before this function is called, magnetic
   field vector and acceleration vector should be stored in the buffer by 
   calling #AKFS_Get_MAGNETIC_FIELD and #AKFS_Get_ACCELEROMETER.
  @return The return value is #AKM_SUCCESS when function succeeds. Otherwise
   the return value is #AKM_FAIL.
  @param[out] azimuth Azimuthal angle in degree.
  @param[out] pitch Pitch angle in degree.
  @param[out] roll Roll angle in degree.
  @param[out] accuracy Accuracy of orientation sensor.
 */
int16 AKFS_Get_ORIENTATION(
			AKFLOAT*	azimuth,
			AKFLOAT*	pitch,
			AKFLOAT*	roll,
			int16*		accuracy
)
{
	int16 akret;

	/* Azimuth calculation */
	/* Coordination system follows the Android coordination. */
	akret = AKFS_Direction(
		AKFS_HDATA_SIZE,
		g_prms.mfv_hvbuf,
		CSPEC_HNAVE_D,
		AKFS_ADATA_SIZE,
		g_prms.mfv_avbuf,
		CSPEC_ANAVE_D,
		&g_prms.mf_azimuth,
		&g_prms.mf_pitch,
		&g_prms.mf_roll
	);

	if(akret == AKFS_ERROR) {
		AKMERROR;
		return AKM_FAIL;
	}
	*azimuth  = g_prms.mf_azimuth;
	*pitch    = g_prms.mf_pitch;
	*roll     = g_prms.mf_roll;
	*accuracy = g_prms.mi_hstatus;

	/* Debug output */
	AKMDATA(AKMDATA_ORI, "Ori(%d):%8.2f, %8.2f, %8.2f\n",
			*accuracy, *azimuth, *pitch, *roll);

	return AKM_SUCCESS;
}
Exemplo n.º 2
0
/*!
  Get orientation sensor's elements. The vector format and coordination system
   follow the Android definition.  Before this function is called, magnetic
   field vector and acceleration vector should be stored in the buffer by 
   calling #AKFS_Get_MAGNETIC_FIELD and #AKFS_Get_ACCELEROMETER.
  @return The return value is #AKM_SUCCESS when function succeeds. Otherwise
   the return value is #AKM_ERROR.
  @param[out] azimuth Azimuthal angle in degree.
  @param[out] pitch Pitch angle in degree.
  @param[out] roll Roll angle in degree.
  @param[out] accuracy Accuracy of orientation sensor.
 */
int16 AKFS_Get_ORIENTATION(
			void		*mem,
			AKFLOAT		*azimuth,
			AKFLOAT		*pitch,
			AKFLOAT		*roll,
			int16		*accuracy
)
{
	int16 akret;
	AKMPRMS *prms;
#ifdef AKM_VALUE_CHECK
	if (mem == NULL) {
		AKMDEBUG(AKMDATA_CHECK, "%s: Invalid mem pointer.", __FUNCTION__);
		return AKM_ERROR;
	}
	if (pitch== NULL || pitch == NULL || roll == NULL || accuracy == NULL) {
		AKMDEBUG(AKMDATA_CHECK, "%s: Invalid data pointer.", __FUNCTION__);
		return AKM_ERROR;
	}
#endif

	/* Copy pointer */
	prms = (AKMPRMS *)mem;

	/* Azimuth calculation */
	/* hvbuf[in] : Android coordinate, sensitivity adjusted, */
	/*			   offset subtracted. */
	/* avbuf[in] : Android coordinate, sensitivity adjusted, */
	/*			   offset subtracted. */
	/* azimuth[out]: Android coordinate and unit (degree). */
	/* pitch  [out]: Android coordinate and unit (degree). */
	/* roll   [out]: Android coordinate and unit (degree). */
	akret = AKFS_Direction(
		AKFS_HDATA_SIZE,
		prms->fva_hvbuf,
		CSPEC_HNAVE_D,
		AKFS_ADATA_SIZE,
		prms->fva_avbuf,
		CSPEC_ANAVE_D,
		&prms->f_azimuth,
		&prms->f_pitch,
		&prms->f_roll
	);

	if (akret == AKFS_ERROR) {
		AKMERROR;
		return AKM_ERROR;
	}

	/* Success */
	*azimuth = prms->f_azimuth;
	*pitch   = prms->f_pitch;
	*roll    = prms->f_roll;
	*accuracy = 3;

	/* Debug output */
	AKMDEBUG(AKMDATA_ORI, "Ori(?):%8.2f, %8.2f, %8.2f\n",
			*azimuth, *pitch, *roll);

	return AKM_SUCCESS;
}