Пример #1
0
SINT main(void)
{
#ifdef NO_RUN_ENTER_STOP_EXIT
	 
	init_OS_flag(); /* this should be called before device init */
	nxt_device_init();
	ecrobot_initDeviceStatus(); // added 10/28/2010 to fix a bug by tchikama
	ecrobot_init_nxtstate();

	if  (execution_mode() == EXECUTED_FROM_FLASH)
	{
		/*
		 * Call buttons_get() because ecrobot_get_button_state() has button bouncer.
		 * The button bouncer requires multiple periodical calls to make it work, but
		 * in this case, only single call (no while loop), so buttons_get is called. 
		 */
		if ((buttons_get() & 0x0F) == (ENTER_PRESSED | STOP_PRESSED))
		{
			/* set flash request and shut down the NXT
	 	 	 * at the next start, NXT BIOS will be executed.
	 	 	 */
			display_clear(0);
   			display_goto_xy(0, 0);
   			display_string("PWR ON: NXT BIOS");
			display_update();
			systick_wait_ms(1000);
   		
			set_flash_request();
			display_clear(1);
			systick_wait_ms(10);
			nxt_lcd_power_down(); /* reset LCD hardware */
			systick_wait_ms(10);
			while(1)
			{
				nxt_avr_power_down();
			}
		}
	}

	/* device init should be called prior to running the application */
	ecrobot_device_initialize();
	ecrobot_setDeviceInitialized();
	
	nxt_motor_set_count(NXT_PORT_A, 0);
	nxt_motor_set_count(NXT_PORT_B, 0);
	nxt_motor_set_count(NXT_PORT_C, 0);
	cpp_constructor();
	display_clear(1);
	systick_wait_ms(10);

#ifdef NXT_JSP
	interrupts_get_and_disable();
#else
	disable_int(); /* set_OS_flag and Start OS have to be atomic */
#endif
	set_OS_flag(); /* this shoud be called before starting OS */
#ifdef NXT_JSP
	lejos_osek_run(); /* start TOPPERS JSP */
#else
	StartOS(1);    /* start TOPPERS OSEK */
#endif

	/* never reached here */


#else
	/* 
	 * Default start up sequence
	 */
	U32 st;
	U32 last_act_time = 0;
	U32 flash_req_cnt = 0;

	init_OS_flag(); /* this should be called before device init */
	nxt_device_init();
	ecrobot_initDeviceStatus(); // added 10/28/2010 to fix a bug by tchikama
	ecrobot_init_nxtstate();

	show_splash_screen();
	show_main_screen();
	display_status_bar(1); /* clear status bar */
	add_status_info(execution_mode());
	display_status_bar(0); /* update status bar */
	while(1)
	{
		/* device init should be called prior to running the application */
		ecrobot_device_initialize();
		ecrobot_setDeviceInitialized();
		/* check the buttons every 10msec */
		st = systick_get_ms();
		if (st >= last_act_time + 10) 
		{
			last_act_time = st;
			ecrobot_poll_nxtstate();
			display_status_bar(0);

			/* 
			 * executed in FLASH: setup for the application flash
			 * executed in SRAM:  no effect
			 */
			if ((ecrobot_get_button_state() == (ENTER_PRESSED | STOP_PRESSED)) &&
			    (execution_mode() == EXECUTED_FROM_FLASH))
			{
				flash_req_cnt++;
				/* keep pusing ENTER + STOP buttons more than 1000msec */
				if (flash_req_cnt >= 100)
				{
					/* set flash request and shut down the NXT
				 	 * at the next start, NXT BIOS will be executed.
				 	 */
					ecrobot_device_terminate();
					set_flash_request();
					display_clear(1);
					systick_wait_ms(10);
					nxt_lcd_power_down(); /* reset LCD hardware */
					systick_wait_ms(10);
					while(1)
					{
						nxt_avr_power_down();
					}
				}
			}
			else
			{
				flash_req_cnt = 0;
				if ((ecrobot_get_button_state() == EXIT_PRESSED) || (systick_get_ms() > SLEEP_TIME))
				{
					/* shut down the NXT */
					ecrobot_device_terminate();
					display_clear(1);
					systick_wait_ms(10);
					nxt_lcd_power_down(); /* reset LCD hardware */
					systick_wait_ms(10);
					while(1)
					{
						nxt_avr_power_down();
					}
				}
				else if (ecrobot_get_button_state() == RUN_PRESSED)
				{
					nxt_motor_set_count(NXT_PORT_A, 0);
					nxt_motor_set_count(NXT_PORT_B, 0);
					nxt_motor_set_count(NXT_PORT_C, 0);
					cpp_constructor();
					display_clear(1);
					systick_wait_ms(10);
#ifdef NXT_JSP
					interrupts_get_and_disable();
#else
					disable_int(); /* set_OS_flag and Start OS have to be atomic */
#endif
					set_OS_flag(); /* this shoud be called before starting OS */
#ifdef NXT_JSP
					lejos_osek_run(); /* start TOPPERS JSP */
#else
					StartOS(1);    /* start TOPPERS OSEK */
#endif
					/* never reached here */
				}
			}
		}
    }
#endif    

    return 0;
}
Пример #2
0
int main (int argc, char **argv)
{
struct timeval timer;
gchar buffer[PATH_MAX];

GUI *appGUI = NULL;
CHART *chr = NULL;
STATISTICS *sts = NULL;
TEST *tst = NULL;
OPTIONS *opt = NULL;
#ifdef MAEMO
osso_context_t *osso_context = NULL;

    /* initialize maemo application */
    osso_context = osso_initialize(APP_NAME, APP_VER, TRUE, NULL);
    
    if (osso_context == NULL) {
        fprintf (stderr, "osso_initialize failed.\n");
        exit (1);
    }
#endif

    appGUI = g_new0 (GUI, 1);
    g_return_val_if_fail (appGUI != NULL, -1);

    chr = g_new0 (CHART, 1);
    g_return_val_if_fail (chr != NULL, -1);
    sts = g_new0 (STATISTICS, 1);
    g_return_val_if_fail (sts != NULL, -1);
    tst = g_new0 (TEST, 1);
    g_return_val_if_fail (tst != NULL, -1);

    opt = g_new0 (OPTIONS, 1);
    g_return_val_if_fail (opt != NULL, -1);

    /* register modules */
    appGUI->chr = chr;
    appGUI->sts = sts;
    appGUI->tst = tst;
    appGUI->opt = opt;

    /* default values */
    appGUI->old_kana_type = -1;
    appGUI->chr->chart_window = NULL;
    appGUI->tst->any_key = FALSE;
    appGUI->tst->test_state = FALSE;
    appGUI->sts->active_tab = -1;
    appGUI->opt->active_tab = -1;

    /* preferences update */

    g_snprintf (buffer, PATH_MAX, "%s%c%s", g_get_home_dir(), G_DIR_SEPARATOR, CONFIG_DIRNAME);

    if (g_file_test(buffer, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) != TRUE) {
        prefs_read_config (CONFIG_FILENAME_OLD, CONFIG_DIRNAME_OLD);
        prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME);
        if (g_file_test(prefs_get_config_filename (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD), G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR) == TRUE) {
            stats_read_list (STATS_FILENAME_OLD, CONFIG_DIRNAME_OLD, appGUI);
        }
        stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI);
    }

    prefs_read_config (CONFIG_FILENAME, CONFIG_DIRNAME);
    stats_read_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI);

    /* init */
#ifdef MAEMO
    hildon_gtk_init (&argc, &argv);
#else
    gtk_init (&argc, &argv);
#endif
    setlocale (LC_ALL, "");

#if defined(WIN32) || defined(WIN64)
    /* Set the locale directory as subdirectory of application path */
    char WINLOCALEDIR[MAX_PATH];
    strcpy(WINLOCALEDIR, g_path_get_dirname(argv[0]));
    strcat(WINLOCALEDIR, "\\share\\locale");

    bindtextdomain (PACKAGE, WINLOCALEDIR);
#else
    bindtextdomain (PACKAGE, LOCALEDIR);
#endif
    bind_textdomain_codeset (PACKAGE, "UTF-8");
    textdomain (PACKAGE);

    /* set seed */
    gettimeofday(&timer, NULL);

#if defined(WIN32) || defined(WIN64)
    srand((long)time(NULL));
#else
    srand48(timer.tv_usec + getpid());
#endif

#ifdef MAEMO
    show_splash_screen ();
#endif
    gui_create_window (appGUI);
    gtk_main ();

    stats_write_list (STATS_FILENAME, CONFIG_DIRNAME, appGUI);
    stats_free_list (appGUI);

    prefs_write_config (CONFIG_FILENAME, CONFIG_DIRNAME);

    g_free (opt);
    g_free (tst);
    g_free (sts);
    g_free (chr);
    g_free (appGUI);
#ifdef MAEMO
    /* deinitialize OSSO */
    osso_deinitialize (osso_context);
#endif
    return 0;
}