Beispiel #1
0
/*
 * 'diagnostic-mode?' - diagnostic-mode? is equivalent to NVRAM 'diag-switch?'
 */
static void
diagnostic_mode(fcode_env_t *env)
{
    char *diag_str;
    int diag_value;

    if (!diag_mode_is_valid) {
        diag_str = get_eeprom_value(env, "diag-switch?");
        if (diag_str != NULL && strcmp(diag_str, "false") == 0)
            diag_value = FALSE;
        else
            diag_value = TRUE;
        PUSH(DS, diag_value);
        set_diagnostic_mode(env);
    }

    push_diagnostic_mode(env);
}
/*!
 @brief High level task for wiimote.

 Handles initializing wiimote.
 */
void control_tasks(char *dev_name)
{
	WiimoteState_t WiimoteState = WII_PROMPT;
	bdaddr_t bdaddr = *BDADDR_ANY; /* bluetooth device address */

	init_tick_count();

#if _MUTEX_ENABLE
	pthread_mutex_lock(&mutex);
#endif

#if HAVE_GTK
	int argc_dummy = 0;
	char **argv_dummy = NULL;
	init_gui(argc_dummy, argv_dummy);

	set_comm_trace(true);
	set_diagnostic_mode(true);
#else
	if (0 >= comm_init(dev_name))
	{
		debug_print("@%u: Cannot initialize %s\n", get_tick_count(), dev_name);
		exit(4);
	}
	else
	{
		debug_print("@%u: %s initialized.\n", get_tick_count(), dev_name);
	}

	do
	{
		debug_print("Connecting to controller board... ");
		if (0 > send_password("WIFIBOT123"))
		{
			debug_print("Error\n");
		}
		else
		{
			debug_print("Done\n");
			break;
		}
	}while (1);

#endif

	set_lcd(0, "%s", PACKAGE_NAME);
	set_lcd(1, "Rev: %s", PACKAGE_VERSION);

	// display startup for 1 s
	sleep(1);

	cwiid_set_err(err);

	for (;;)
	{

		switch (WiimoteState)
		{
		case WII_PROMPT:
			/* Connect to the wiimote */
			debug_print(
					"Put Wiimote in discoverable mode now (press 1+2)...\n");

			set_lcd(0, "Connecting...");
			set_lcd(1, "Press 1+2 now");
			WiimoteState = WII_WAIT_FOR_CONNECTION;
			break;
		case WII_WAIT_FOR_CONNECTION:
			if (!(wiimote = cwiid_open(&bdaddr, 0)))
			{
				fprintf(stderr, "Unable to connect to wiimote, retrying...\n");
				WiimoteState = WII_PROMPT;
			}
			else if (cwiid_set_mesg_callback(wiimote, cwiid_callback))
			{
				fprintf(stderr,
						"Unable to set message callback, retrying...\n");
				WiimoteState = WII_PROMPT;
			}
			else
			{
				WiimoteState = WII_OPERATE;
			}
			break;
		case WII_OPERATE:
		default:
			main_menu(wiimote, &wiimote_status_data);
			debug_print("exiting.\n");
			shutdown_application(0);
			break;
		}
	}
}