예제 #1
0
/*!
 This is main function.
 */
int main(int argc, char **argv)
{
	AK8963PRMS prms;
	int retValue = 0;
	AKMD_PATNO pat;
	int16 outbit;

	/* Show the version info of this software. */
	Disp_StartMessage();

#if ENABLE_AKMDEBUG
	/* Register signal handler */
	signal(SIGINT, signal_handler);
#endif

#if ENABLE_FORMATION
	RegisterFormClass(&s_formClass);
#endif

	/* Open device driver. */
	if (AKD_InitDevice() != AKD_SUCCESS) {
		retValue = ERROR_INITDEVICE;
		goto THE_END_OF_MAIN_FUNCTION;
	}

	/* Parse command-line options */
	if (OptParse(argc, argv, &pat, &outbit) == 0) {
		retValue = ERROR_OPTPARSE;
		goto THE_END_OF_MAIN_FUNCTION;
	}

	/* Initialize parameters structure. */
	InitAK8963PRMS(&prms);

	/* Put argument to PRMS. */
	prms.m_layout = pat;
	prms.m_outbit = outbit;

	/* Read Fuse ROM */
	if (ReadAK8963FUSEROM(&prms) != AKRET_PROC_SUCCEED) {
		retValue = ERROR_FUSEROM;
		goto THE_END_OF_MAIN_FUNCTION;
	}

	/* Here is the Main Loop */
	if (g_opmode) {
		/*** Console Mode *********************************************/
		while (AKD_TRUE) {
			/* Select operation */
			switch (Menu_Main()) {
				case MODE_FctShipmntTestBody:
					FctShipmntTest_Body(&prms);
					break;

				case MODE_MeasureSNG:
					/* Read Parameters from file. */
					if (LoadParameters(&prms) == 0) {
						SetDefaultPRMS(&prms);
					}
					/* Reset flag */
					g_stopRequest = 0;
					/* Measurement routine */
					MeasureSNGLoop(&prms);

					/* Write Parameters to file. */
					SaveParameters(&prms);
					break;

				case MODE_Quit:
					goto THE_END_OF_MAIN_FUNCTION;
					break;

				default:
					AKMDEBUG(DBG_LEVEL0, "Unknown operation mode.\n");
					break;
			}
		}
	} else {
		/*** Daemon Mode *********************************************/
		while (g_mainQuit == AKD_FALSE) {
			int st = 0;
			/* Wait until device driver is opened. */
			if (AKD_GetOpenStatus(&st) != AKD_SUCCESS) {
				retValue = ERROR_GETOPEN_STAT;
				goto THE_END_OF_MAIN_FUNCTION;
			}
			if (st == 0) {
				ALOGI("Suspended.");
			} else {
				ALOGI("Compass Opened.");
				/* Read Parameters from file. */
				if (LoadParameters(&prms) == 0) {
					SetDefaultPRMS(&prms);
				}
				/* Reset flag */
				g_stopRequest = 0;
				/* Start measurement thread. */
				if (startClone(&prms) == 0) {
					retValue = ERROR_STARTCLONE;
					goto THE_END_OF_MAIN_FUNCTION;
				}

				/* Wait until device driver is closed. */
				if (AKD_GetCloseStatus(&st) != AKD_SUCCESS) {
					retValue = ERROR_GETCLOSE_STAT;
					g_mainQuit = AKD_TRUE;
				}
				/* Wait thread completion. */
				g_stopRequest = 1;
				pthread_join(s_thread, NULL);
				ALOGI("Compass Closed.");

				/* Write Parameters to file. */
				SaveParameters(&prms);
			}
		}
	}

THE_END_OF_MAIN_FUNCTION:

	/* Close device driver. */
	AKD_DeinitDevice();

	/* Show the last message. */
	Disp_EndMessage(retValue);

	return retValue;
}
예제 #2
0
/* .! :
 This is main function.
 */
int main(int argc, char **argv)
{
	AK8975PRMS prms;
	int retValue = 0;
	int mainQuit = FALSE;
	int i;
	
	for (i = 1; i < argc; i++) {
		if (0 == strncmp("-s", argv[i], 2)) {
			s_opmode = 1;
		}
	}
	
#ifdef COMIF
	//// Initialize Library
	//// AKSC_Version functions are called in Disp_StartMessage().
	//// Therefore, AKSC_ActivateLibrary function has to be called previously.
	//retValue = AKSC_ActivateLibrary(GUID_AKSC);
	//if (retValue < 0) {
	//	LOGE("akmd2 : Failed to activate library (%d).\n", retValue);
	//	goto THE_END_OF_MAIN_FUNCTION;
	//}
	//LOGI("akmd2 : Activation succeeded (%d).\n", retValue);
#endif
	
	// Show the version info of this software.
	Disp_StartMessage();
	
	// Open device driver.
	if (AKD_InitDevice() != AKD_SUCCESS) {
		LOGE("akmd2 : Device initialization failed.\n");
		retValue = -1;
		goto THE_END_OF_MAIN_FUNCTION;
	}
	
	// Initialize parameters structure.
	InitAK8975PRMS(&prms);
	
	// Read Fuse ROM
	if (ReadAK8975FUSEROM(&prms) == 0) {
		LOGE("akmd2 : Fuse ROM read failed.\n");
		retValue = -2;
		goto THE_END_OF_MAIN_FUNCTION;
	}

	// Here is the Main Loop
	if (s_opmode) {
		//*** Console Mode *********************************************
		while (mainQuit == FALSE) {
			// Select operation
			switch (Menu_Main()) {
				case MODE_FctShipmntTestBody:
					FctShipmntTest_Body(&prms);
					break;
					
				case MODE_MeasureSNG:
					// Read Parameters from file.
					if (LoadParameters(&prms) == 0) {
						LOGE("akmd2 : Setting file can't be read.\n");
						SetDefaultPRMS(&prms);
					}
					
#ifdef COMIF
					//// Activation
					//retValue = AKSC_ActivateLibrary(GUID_AKSC);
					//if (retValue < 0) {
					//	LOGE("akmd2 : Failed to activate library (%d).\n", retValue);
					//	goto THE_END_OF_MAIN_FUNCTION;
					//}
					//LOGI("akmd2 : Activation succeeded (%d).\n", retValue);
#endif
					// Measurement routine
					MeasureSNGLoop(&prms);
					
					// Write Parameters to file.
					if (SaveParameters(&prms) == 0) {
						LOGE("akmd2 : Setting file can't be saved.\n");
					}
					break;
					
				case MODE_Quit:
					mainQuit = TRUE;
					break;
					
				default:
					DBGPRINT(DBG_LEVEL1, "Unknown operation mode.\n");
					break;
			}
		}
	} else {
		//*** Daemon Mode *********************************************
        I("AKMD runs in daemon mode.");
		while (mainQuit == FALSE) {
			int st = 0;
            // .! : 
			// Wait until device driver is opened.
			if (ioctl(g_file, ECS_IOCTL_GET_OPEN_STATUS, &st) < 0) {
				retValue = -3;
				goto THE_END_OF_MAIN_FUNCTION;
			}
			if (st == 0) {
				LOGI("akmd2 : Suspended.\n");
			} else {
				LOGI("akmd2 : Compass Opened.\n");
                V("m_hs : [%d, %d, %d].", (prms.m_hs).v[0], (prms.m_hs).v[1], (prms.m_hs).v[2] );
				// Read Parameters from file.
				if (LoadParameters(&prms) == 0) {
					LOGE("akmd2 : Setting file can't be read.\n");
					SetDefaultPRMS(&prms);
				}
                V("m_hs : [%d, %d, %d].", (prms.m_hs).v[0], (prms.m_hs).v[1], (prms.m_hs).v[2] );
				
#ifdef COMIF
				//// Activation
				//retValue = AKSC_ActivateLibrary(GUID_AKSC);
				//if (retValue < 0) {
				//	LOGE("akmd2 : Failed to activate library (%d).\n", retValue);
				//	retValue = -4;
				//	goto THE_END_OF_MAIN_FUNCTION;
				//}
				//LOGI("akmd2 : Activation succeeded (%d).\n", retValue);
#endif
				
                // .! : 
				// Start measurement thread.
				if (startClone(&prms) == 0) {
					retValue = -5;
					goto THE_END_OF_MAIN_FUNCTION;
				}
				
				// Wait until device driver is closed.
				if (ioctl(g_file, ECS_IOCTL_GET_CLOSE_STATUS, &st) < 0) {
					retValue = -6;
					goto THE_END_OF_MAIN_FUNCTION;
				}
				// Wait thread completion.
				s_stopRequest = 1;
				pthread_join(s_thread, NULL);
				LOGI("akmd2 : Compass Closed.\n");
				// Write Parameters to file.
				if (SaveParameters(&prms) == 0) {
					LOGE("akmd2 : Setting file can't be saved.\n");
				}
			}
		}
	}
	
THE_END_OF_MAIN_FUNCTION:
	
#ifdef COMIF
	//// Close library
	//AKSC_ReleaseLibrary(); 
	//LOGI("akmd2 : Library released.\n");
#endif
	
	// Close device driver.
	AKD_DeinitDevice();
	
	// Show the last message.
	Disp_EndMessage();
	
	return retValue;
}
예제 #3
0
int main(int argc, char **argv)
{
	int			retValue = 0;
	AKMPRMS		prms;
	AKFS_PATNO	pat;
	uint8		regs[3];

	/* Show the version info of this software. */
	Disp_StartMessage();

#if ENABLE_AKMDEBUG
	/* Register signal handler */
	signal(SIGINT, signal_handler);
#endif

	/* Open device driver */
	if(AKD_InitDevice() != AKD_SUCCESS) {
		retValue = ERROR_INITDEVICE;
		goto MAIN_QUIT;
	}

	/* Parse command-line options */
	/* This function calls device driver function to get layout */
	if (OptParse(argc, argv, &pat) == 0) {
		retValue = ERROR_OPTPARSE;
		goto MAIN_QUIT;
	}

	/* Self Test */
	/*
	if (g_opmode & OPMODE_FST){
		if (AKFS_SelfTest() != AKD_SUCCESS) {
			retValue = ERROR_SELF_TEST;
			goto MAIN_QUIT;
		}
	}*/

	/* OK, then start */
	if (AKFS_ReadConf(regs) != AKM_SUCCESS) {
		retValue = ERROR_READ_FUSE;
		goto MAIN_QUIT;
	}

	/* Initialize library. */
	if (AKFS_Init(&prms, pat, regs) != AKM_SUCCESS) {
		retValue = ERROR_INIT;
		goto MAIN_QUIT;
	}

	/* Start console mode */
	if (g_opmode & OPMODE_CONSOLE) {
		ConsoleMode((void *)&prms);
		goto MAIN_QUIT;
	}

	/*** Start Daemon ********************************************/
	while (g_mainQuit == AKD_FALSE) {
		int st = 0;
		/* Wait until device driver is opened. */
		if (AKD_GetOpenStatus(&st) != AKD_SUCCESS) {
			retValue = ERROR_GETOPEN_STAT;
			goto MAIN_QUIT;
		}
		if (st == 0) {
			AKMDEBUG(AKMDATA_LOOP, "Suspended.");
		} else {
			AKMDEBUG(AKMDATA_LOOP, "Compass Opened.");
			/* Reset flag */
			g_stopRequest = 0;
			/* Start measurement thread. */
			if (startClone((void *)&prms) == 0) {
				retValue = ERROR_STARTCLONE;
				goto MAIN_QUIT;
			}

			/* Wait until device driver is closed. */
			if (AKD_GetCloseStatus(&st) != AKD_SUCCESS) {
				retValue = ERROR_GETCLOSE_STAT;
				g_mainQuit = AKD_TRUE;
			}
			/* Wait thread completion. */
			g_stopRequest = 1;
			pthread_join(s_thread, NULL);
			AKMDEBUG(AKMDATA_LOOP, "Compass Closed.");
		}
	}

MAIN_QUIT:

	/* Release library */
	AKFS_Release(&prms);
	/* Close device driver. */
	AKD_DeinitDevice();
	/* Show the last message. */
	Disp_EndMessage(retValue);

	return retValue;
}
예제 #4
0
/*!
 This is main function.
 */
int main(int argc, char **argv)
{
	AKSCPRMS prms;
	int retValue = 0;

	/* Show the version info of this software. */
	Disp_StartMessage();

#if ENABLE_AKMDEBUG
	/* Register signal handler */
	signal(SIGINT, signal_handler);
#endif

#if ENABLE_FORMATION
	RegisterFormClass(&s_formClass);
#endif

	/* Initialize parameters structure. */
	InitAKSCPRMS(&prms);

	/* Parse command-line options */
	if (OptParse(argc, argv, &prms.m_hlayout) == 0) {
		retValue = ERROR_OPTPARSE;
		goto THE_END_OF_MAIN_FUNCTION;
	}

	/* Open device driver. */
	if (AKD_InitDevice() != AKD_SUCCESS) {
		retValue = ERROR_INITDEVICE;
		goto THE_END_OF_MAIN_FUNCTION;
	}

	/* If layout is not specified with argument, get parameter from driver */
	if (prms.m_hlayout == PAT_INVALID) {
		int16_t n;
		if (AKD_GetLayout(&n) == AKD_SUCCESS) {
			if ((PAT1 <= n) && (n <= PAT8)) {
				prms.m_hlayout = (AKMD_PATNO)n;
			}
		}
		/* Error */
		if (prms.m_hlayout == PAT_INVALID) {
			ALOGE("Magnetic sensor's layout is specified.");
			retValue = ERROR_HLAYOUT;
			goto THE_END_OF_MAIN_FUNCTION;
		}
	}

	/* Read Fuse ROM */
	if (ReadFUSEROM(&prms) != AKRET_PROC_SUCCEED) {
		retValue = ERROR_FUSEROM;
		goto THE_END_OF_MAIN_FUNCTION;
	}

	/* PDC */
	LoadPDC(&prms);

	/* Here is the Main Loop */
	if (g_opmode & OPMODE_CONSOLE) {
		/*** Console Mode *********************************************/
		while (AKD_TRUE) {
			/* Select operation */
			switch (Menu_Main()) {
				case MODE_FST:
					FST_Body();
					break;

				case MODE_MeasureSNG:
					/* Read Parameters from file. */
					if (LoadParameters(&prms) == 0) {
						SetDefaultPRMS(&prms);
					}
					/* Reset flag */
					g_stopRequest = 0;
					/* Measurement routine */
					MeasureSNGLoop(&prms);

					/* Write Parameters to file. */
					SaveParameters(&prms);
					break;

				case MODE_OffsetCalibration:
					/* Read Parameters from file. */
					if (LoadParameters(&prms) == 0) {
						SetDefaultPRMS(&prms);
					}
					/* measure offset (NOT sensitivity) */
					if (SimpleCalibration(&prms) == AKRET_PROC_SUCCEED) {
						SaveParameters(&prms);
					}
					break;

				case MODE_Quit:
					goto THE_END_OF_MAIN_FUNCTION;
					break;

				default:
					AKMDEBUG(AKMDBG_DEBUG, "Unknown operation mode.\n");
					break;
			}
		}
	} else {
		/*** Daemon Mode *********************************************/
		while (g_mainQuit == AKD_FALSE) {
			int st = 0;
			/* Wait until device driver is opened. */
			if (AKD_GetOpenStatus(&st) != AKD_SUCCESS) {
				retValue = ERROR_GETOPEN_STAT;
				goto THE_END_OF_MAIN_FUNCTION;
			}
			if (st == 0) {
				AKMDEBUG(AKMDBG_DEBUG, "Suspended.");
			} else {
				AKMDEBUG(AKMDBG_DEBUG, "Compass Opened.");
				/* Read Parameters from file. */
				if (LoadParameters(&prms) == 0) {
					SetDefaultPRMS(&prms);
				}
				/* Reset flag */
				g_stopRequest = 0;
				/* Start measurement thread. */
				if (startClone(&prms) == 0) {
					retValue = ERROR_STARTCLONE;
					goto THE_END_OF_MAIN_FUNCTION;
				}

				/* Wait until device driver is closed. */
				if (AKD_GetCloseStatus(&st) != AKD_SUCCESS) {
					retValue = ERROR_GETCLOSE_STAT;
					g_mainQuit = AKD_TRUE;
				}
				/* Wait thread completion. */
				g_stopRequest = 1;
				pthread_join(s_thread, NULL);
				AKMDEBUG(AKMDBG_DEBUG, "Compass Closed.");

				/* Write Parameters to file. */
				SaveParameters(&prms);
			}
		}
	}

THE_END_OF_MAIN_FUNCTION:

	/* Close device driver. */
	AKD_DeinitDevice();

	/* Show the last message. */
	Disp_EndMessage(retValue);

	return retValue;
}