コード例 #1
0
ファイル: menu_listen.c プロジェクト: exander77/openomf
void menu_listen_tick(component *c) {
    listen_menu_data *local = menu_get_userdata(c);
    game_state *gs = local->s->gs;
    if(local->host) {
        ENetEvent event;
        if(enet_host_service(local->host, &event, 0) > 0 && event.type == ENET_EVENT_TYPE_CONNECT) {
            ENetPacket * packet = enet_packet_create("0", 2,  ENET_PACKET_FLAG_RELIABLE);
            enet_peer_send(event.peer, 0, packet);
            enet_host_flush(local->host);

            DEBUG("client connected!");
            controller *player1_ctrl, *player2_ctrl;
            keyboard_keys *keys;
            game_player *p1 = game_state_get_player(gs, 0);
            game_player *p2 = game_state_get_player(gs, 1);

            // force the speed to 3
            game_state_set_speed(gs, 5);

            p1->har_id = HAR_JAGUAR;
            p1->pilot_id = 0;
            p2->har_id = HAR_JAGUAR;
            p2->pilot_id = 0;

            player1_ctrl = malloc(sizeof(controller));
            controller_init(player1_ctrl);
            player1_ctrl->har = p1->har;
            player2_ctrl = malloc(sizeof(controller));
            controller_init(player2_ctrl);
            player2_ctrl->har = p2->har;

            // Player 1 controller -- Keyboard
            settings_keyboard *k = &settings_get()->keys;
            keys = malloc(sizeof(keyboard_keys));
            keys->up = SDL_GetScancodeFromName(k->key1_up);
            keys->down = SDL_GetScancodeFromName(k->key1_down);
            keys->left = SDL_GetScancodeFromName(k->key1_left);
            keys->right = SDL_GetScancodeFromName(k->key1_right);
            keys->punch = SDL_GetScancodeFromName(k->key1_punch);
            keys->kick = SDL_GetScancodeFromName(k->key1_kick);
            keys->escape = SDL_GetScancodeFromName(k->key1_escape);
            keyboard_create(player1_ctrl, keys, 0);
            game_player_set_ctrl(p1, player1_ctrl);

            // Player 2 controller -- Network
            net_controller_create(player2_ctrl, local->host, event.peer, ROLE_SERVER);
            game_player_set_ctrl(p2, player2_ctrl);
            local->host = NULL;
            game_player_set_selectable(p2, 1);

            chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 0)), AI_DIFFICULTY_CHAMPION);
            chr_score_set_difficulty(game_player_get_score(game_state_get_player(gs, 1)), AI_DIFFICULTY_CHAMPION);

            game_state_set_next(gs, SCENE_MELEE);
        }
    }
}
コード例 #2
0
ファイル: demo.c プロジェクト: kerichsen/asf
int main(void)
{
  init_sys_clocks();

  init_dbg_rs232(FPBA_HZ);

  print_dbg("AVR UC3 DSP DEMO\r\n");

  irq_initialize_vectors();

  // GUI, Controller and DSP process init
  gui_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);
  gui_text_print(GUI_COMMENT_ID, TEXT_IDLE);
  gui_text_print(GUI_FILTER_ID, filter_active_get_description());
  controller_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);
  twi_init();
  dsp_process_init(FCPU_HZ, FHSB_HZ, FPBA_HZ, FPBB_HZ);

  cpu_irq_enable();

  // Main loop
  while (1)
  {
    gui_task();
    controller_task();
    dsp_process_task();
    state_machine_task();
  }
}
コード例 #3
0
int control_loop_setup( int ms_period, int ctrl_gain, int ubisense,
                        double *offset_r, double *offset_p )
{
    /* initialize global variables */
    running             = 1;
    period              = ms_period / 1000.0;
    us_period           = ms_period * 1000;
    heli_state          = HELI_STATE_SHUTDOWN;
    heli_settled        = 1;
    yaw_wn_imu          = 0;
    yaw_wn_cmd          = 0;
    new_data_z          = 0;
    cmd_roll            = 0;
    cmd_pitch           = 0;
    next_period         = 0;
    motor_speed_revving = 0;
    motor_speed_liftoff = 0;

    /* initialize filter objects */
    iir_lp_filter_init ( &iir_acc_x,     "ACC_X",     IIR_GAIN_LACC );
    iir_lp_filter_init ( &iir_acc_y,     "ACC_Y",     IIR_GAIN_LACC );
    iir_lp_filter_init ( &iir_acc_z,     "ACC_Z",     IIR_GAIN_LACC );
    iir_lp_filter_init ( &iir_cmd_roll,  "CMD_Roll",  IIR_GAIN_RCMD );
    iir_lp_filter_init ( &iir_cmd_pitch, "CMD_Pitch", IIR_GAIN_RCMD );
    iir_lp_filter_init ( &iir_cmd_yaw,   "CMD_Yaw",   IIR_GAIN_RCMD );
    iir_lp_filter_init ( &iir_cmd_z,     "CMD_Z",     IIR_GAIN_RCMD );
    median_filter_init ( &med_bat_level, "Bat_Level", MED_SIZE_BATT );
    position_ekf_init  ( &ekf_pos_z,     "POS_Z",     EKF_POS_STD_P, EKF_POS_STD_V, EKF_POS_STD_A, period );

    /* initialize controller objects */
    controller_init    ( &ctrl_roll,     "Roll",      CTRL_PIDD_DEF, period );
    controller_init    ( &ctrl_pitch,    "Pitch",     CTRL_PIDD_DEF, period );
    controller_init    ( &ctrl_yaw,      "Yaw",       CTRL_PIDD_DEF, period );
    controller_init    ( &ctrl_z,        "Z",         CTRL_PIDD_DEF, period );

    /* initialize transformations */
    transformation_init( );

    /* clear data structures */
    memset( &command_data,  0, sizeof( command_data ) );
    memset( &javiator_data, 0, sizeof( javiator_data ) );
    memset( &sensor_data,   0, sizeof( sensor_data ) );
    memset( &motor_signals, 0, sizeof( motor_signals ) );
    memset( &motor_offsets, 0, sizeof( motor_offsets ) );

    return( 0 );
}
コード例 #4
0
ファイル: rift.c プロジェクト: RIFTIO/RIFT.ware
int
boot_(Module m)
{
  char* dummy = NULL;

  controller_init(&rwcli_controller);

  // Authenticate in case of RW.MSG mode
  rwcli_user_mode_t user_mode = RWCLI_USER_MODE_NONE;
  if (rwcli_controller.agent_type == RWCLI_TRANSPORT_MODE_RWMSG) {
    user_mode = rift_authenticate(&rift_cmdargs);
    if (user_mode == RWCLI_USER_MODE_INVALID) {
      printf("\nERROR: Invalid username/password\n");
      exit(-1);
    }
  }

  rwcli_zsh_plugin_init(rwcli_controller.agent_type, user_mode);
  rwcli_set_messaging_hook(messaging_hook);
  rwcli_set_history_hook(history_hook);

  // Always load the rwmsg_agent module, If netconf is enabled then 
  // this module will only receive logging notifications
  if (load_module("zsh/rwmsg_agent", NULL, 0) != 0) {
    printf("\nCRITICAL: Loading the messaging agent module failed\n");
    fflush(stdout);
    return -1;
  }

  // Load the agent that is required
  if (rwcli_controller.agent_type == RWCLI_TRANSPORT_MODE_NETCONF) {
    if (load_module("zsh/rwnetconf_agent", NULL, 0) != 0) {
      printf("\nCRITICAL: Loading the netconf agent module failed\n");
      fflush(stdout);
      return -1;
    }
    rwcli_controller.is_netconf_agent_loaded = true;
  }

  /* Register the completion widget */
  rwcli_controller.w_comp = addzlefunction("rift-complete", rift_complete, 0);
  Keymap km = openkeymap("main");
  rwcli_controller.t_orig_tab_bind = keybind(km, "\t", &dummy);
  bindkey(km, "\t", refthingy(rwcli_controller.w_comp->first), NULL);

  /* Bind ? to generate help */
  rwcli_controller.w_gen_help = addzlefunction("rift-gen-help", 
                                      rift_generate_help, 0);
  bindkey(km, "?", refthingy(rwcli_controller.w_gen_help->first), NULL);

  /* Set the lookup hook */
  rw_lookup_fn = rift_lookup;

  /* Set the prompt hook */
  addprepromptfn(rift_prompt);

  return 0;
}
コード例 #5
0
ファイル: robo1.c プロジェクト: cksystemsgroup/JAviator
int main( void )
{
    uint8_t already_converted = 0;

    /* initialize Robostix 1 */
    controller_init( );

    while( 1 )
    {
        /* check if communication is upright */
        if( flag_check_delay )
        {
            check_receive_delay( );
        }

        /* check if new serial or parallel data available */
        if( serial_is_new_data( ) )//|| parallel_is_new_data( ) )
        {
            process_data_packet( );
        }

        /* check if new IMU data available */
        if( dm3gx1_is_new_data( ) &&
            !dm3gx1_get_data( &javiator_data ) )
        {
            javiator_data.state |= ST_NEW_DATA_IMU;
        }

        /* check if new analog sonar data available */
        if( minia_is_new_data( ) && !already_converted )
        {
            /* convert sonar data */
            adc_convert( ADC_CH_SONAR );

            already_converted = 1;
        }
        else
        if( !minia_is_new_data( ) )
        {
            already_converted = 0;
        }

        /* check if new converted sonar data available */
        if( adc_is_new_data( ADC_CH_SONAR ) &&
            !adc_get_data( ADC_CH_SONAR, &javiator_data.sonar ) )
        {
            javiator_data.state |= ST_NEW_DATA_SONAR;
        }

        /* check if new converted battery data available */
        if( adc_is_new_data( ADC_CH_BATT ) )
        {
            adc_get_data( ADC_CH_BATT, &javiator_data.batt );
        }
    }

    return( 0 );
}
コード例 #6
0
ファイル: robo2.c プロジェクト: cksystemsgroup/JAviator
/* Runs the control loop
*/
int main( void )
{
    /* initialize Robostix 2 */
    controller_init( );

    while( 1 )
    {
        /* check if communication is upright */
        if( flag_check_delay )
        {
            check_receive_delay( );
        }

        /* check if new parallel data available */
        if( parallel_is_new_data( ) )
        {
            process_data_packet( );
        }

        /* check if new BMU data available */
        if( bmu09a_is_new_data( ) &&
            !bmu09a_get_data( &javiator_data ) )
        {
            javiator_data.state |= ST_NEW_DATA_BMU;
        }
#if 0
        /* check if new sonar data available */
        if( adc_is_new_data( ADC_CH_SONAR ) &&
            !adc_get_data( ADC_CH_SONAR, &javiator_data.sonar ) )
        {
            javiator_data.state |= ST_NEW_DATA_SONAR;
        }

        if( adc_is_new_data( ADC_CH_BATT ) )
        {
            adc_get_data( ADC_CH_BATT, &javiator_data.batt );
        }
#endif
        /* check if new x-laser data available */
        if( lsm215_is_new_x_data( ) &&
            !lsm215_get_x_data( javiator_data.x_pos ) )
        {
            javiator_data.state |= ST_NEW_DATA_POS_X;
            LED_OFF( BLUE );
        }

        /* check if new y-laser data available */
        if( lsm215_is_new_y_data( ) &&
            !lsm215_get_y_data( javiator_data.y_pos ) )
        {
            javiator_data.state |= ST_NEW_DATA_POS_Y;
            LED_ON( BLUE );
        }
    }

    return( 0 );
}
コード例 #7
0
ファイル: utils.c プロジェクト: ArtemioUrbina/240pTestSuite
void init_n64()
{
	init_interrupts();
	
	init_video();
	set_video();
	dfs_init(DFS_DEFAULT_LOCATION);
	controller_init();
	timer_init();
}
コード例 #8
0
void
view_type_edit_contact_init()
{
	struct controller *con;

	con = controller_init();

	view_type_register("edit_contact", con,
			&view_edit_contact_init, &view_edit_contact_free, &view_edit_contact_draw);
}
コード例 #9
0
int main(int argc, char *argv[])
{
	parseCommandLineParameters(argc, argv);
	kheperaApi_setup();
	controller_init();
	while(1) {
		controller_act();
	}
	printf("Controller terminated\n");
	return 0;
}
コード例 #10
0
ファイル: main.c プロジェクト: OpenSorcery/libdragon
/* initialize console hardware */
void init_n64(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( RESOLUTION_320x240, DEPTH_32_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );

    register_VI_handler(vblCallback);

    controller_init();
}
コード例 #11
0
int main(int argc, char *argv[])
{
	parseCommandLineParameters(argc, argv);
	mtranApi_ussrSetup(portRC, portEvent, host, handleMessage);
	mtranApi_yield();
	controller_init();
	mtranApi_yield();
	while(1) {
		controller_act();
		mtranApi_yield();
	}
	printf("Controller terminated\n");
	return 0;
}
コード例 #12
0
ファイル: main.c プロジェクト: mariusadam/simple-mvc-c-style
void run_app() {
	/*  
	 * Builder for the application
	 */
	Repository* repo = repository_init("Files/cheltuieli.txt");
	Validator* valid = validator_init();
	Controller* ctr = controller_init(repo, valid);
	Console* cons = console_init(ctr);
	
	console_run(cons);

	console_destroy(cons);
	controller_destroy(ctr);
	validator_destroy(valid);
	repository_destroy(repo);
}
コード例 #13
0
void    main(void)
{
    controller_init();/* This must be done first! */
    //custom_init();

    while (TRUE) // evaluates true every 18.5ms
    {

       // pwm_write(LEFT_MOTOR, LEFT_MOTOR_POWER);
       // pwm_write(RIGHT_MOTOR, RIGHT_MOTOR_POWER);

       // controller_submit_data(NO_WAIT);
        printf("%d,%d,%d,%d,%d,%d,%d,%d\n",
               pwm_read(1),pwm_read(2),pwm_read(3),pwm_read(4),
               pwm_read(5),pwm_read(6),pwm_read(7),pwm_read(2));

    }
}
コード例 #14
0
// Returns 0 if no problem
int user_initialization(MBSdataStruct *MBSdata, LocalDataStruct *lds)
#endif
{

	// inputs of the controller
	controller_inputs(MBSdata);



	//  controller initialization
    controller_init(MBSdata->user_IO->cvs);

    //init_SEAStruct(1);

    #ifdef CMEX
    return 0;
    #endif
}
コード例 #15
0
void
view_type_contacts_init()
{
	struct controller *con;

	con = controller_init();
	controller_add_key(con, '\n', &view_contacts_key_enter);
	controller_add_key(con, '\t', &view_contacts_key_tab);
	controller_add_key(con, KEY_DC, &view_contacts_key_del);
	controller_add_key(con, KEY_UP, &view_contacts_key_up);
	controller_add_key(con, 'k', &view_contacts_key_up);
	controller_add_key(con, KEY_DOWN, &view_contacts_key_down);
	controller_add_key(con, 'j', &view_contacts_key_down);
	controller_add_key(con, KEY_HOME, &view_contacts_key_home);
	controller_add_key(con, KEY_END, &view_contacts_key_end);

	view_type_register("contacts", con,
			&view_contacts_init, &view_contacts_free, &view_contacts_draw);
}
コード例 #16
0
ファイル: main.c プロジェクト: Mazetti/asf
/*!
 * \brief init function : do init and loop (poll if configured so)
 */
static int app_engine(void)
{

	// configure GUI
	gui_init(CPU_CLK_FREQ(),CPU_CLK_FREQ(),CPU_CLK_FREQ(),PBA_CLK_FREQ());

	// configure controller
	controller_init(CPU_CLK_FREQ(),CPU_CLK_FREQ(),CPU_CLK_FREQ(),
		PBA_CLK_FREQ());

	// initializes t2BF
	AppEngineInit( gui_callback, "Atmel Spp Lite" );

	/* do a loop */
	while (true) {
		OSTimeDlyHMSM(0, 0, 0, 200);

		controller_task();

		if (controller_inquiry() == true) {
			AppEngineInquiryButton( );
		}
		else if (controller_select() == true) {
			AppEngineSelectDeviceButton( );
		}
		else if (controller_connect() == true) {
			AppEngineConnectButton( );
		}
		else if (controller_send() == true) {
			AppEngineJoystickButton( AppEngine_Left );
		}

		if (display) {
			OSTimeDlyHMSM(0, 0, 0, 200);
			// A delay so that it is humanly possible to see the
			OSTimeDlyHMSM(0, 0, 0, 200);
			// character(s) before they are cleared
			display = 0;
		}
	}
}
コード例 #17
0
ファイル: comm.c プロジェクト: samjacoby/avr
void setup(void) {
    // Set the i2c device address;
    uint8_t device_address; 

    // Set chip to run at 8MHz
    CLKPR = (1 << CLKPCE);
    CLKPR = 0;


    // Set the device address. This can be loaded from EEPROM if need be.
    device_address = 0x4A;
    i2c_init(device_address);

    i2c_set_read_fn(&interface_read_reg);
    i2c_set_write_fn(&interface_write_reg);

    // Set up ADC and PWM
    adc_init();
    pwm_init();
    controller_init();

}
コード例 #18
0
ファイル: main.cpp プロジェクト: matthewbot/FlamewheelFC
int main() {
    board_init();
    uart_init();
    esc_init();
    rgbled_init();
    rgbled_set(0xFF8000, 100);
    spektrum_init();
    rgbled_set(0xFF8000, 100);
    xbee_init();
    i2c_init();
    alt_init();
    mag_init();
    mpu_init();
    sonar_init();
    ins_init();
    inscomp_init();
    altitude_init();
    controller_init();
    basestation_init();
    flight_init();

    controlpanel_run();
}
コード例 #19
0
ファイル: rqd.c プロジェクト: hyper/rqd
static void init_controllers(system_data_t *sysdata)
{
	char         *str;
	controller_t *ct;
	
	assert(sysdata);
	assert(sysdata->controllers == NULL);
	
	sysdata->controllers = (list_t *) malloc(sizeof(list_t));
	ll_init(sysdata->controllers);
	
	// now that everything else is configured, connect to other controllers.
	assert(sysdata->controllers);
	while ((str = ll_pop_head(sysdata->settings->controllers))) {
		ct = (controller_t *) malloc(sizeof(controller_t));
		controller_init(ct, str);
		ct->sysdata = sysdata;

		logger(sysdata->logging, 1, "Connecting to controller: %s.", str);
		controller_connect(ct);
		ll_push_tail(sysdata->controllers, ct);
		ct = NULL;
	}
}
コード例 #20
0
// main entry point
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR paCmdLine, int nCmdShow) {
    WNDCLASSEXW WndClass;
    MSG Msg;
    unsigned long result;

    zhInstance = hInstance;

    //PWSTR pCmdLine = GetCommandLineW();

    WndClass.cbSize = sizeof(WNDCLASSEXW);
    WndClass.style = 0; // disable CS_DBLCLKS
    WndClass.lpfnWndProc = WndProc;
    WndClass.cbClsExtra = 0;
    WndClass.cbWndExtra = 0;
    WndClass.hInstance = zhInstance;
    WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    WndClass.hbrBackground = NULL;
    //WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW);
    WndClass.lpszMenuName = NULL;
    WndClass.lpszClassName = L"MyClass";

    if (!RegisterClassExW(&WndClass)) {
        MessageBoxW(0, L"Error Registering Class!", L"Error!", MB_ICONSTOP | MB_OK);
        return 0;
    }

    hwndMain = CreateWindowExW(
        0,
        L"MyClass",
        L"MIDI controller test harness",
        WS_OVERLAPPEDWINDOW & ~WS_THICKFRAME,
        CW_USEDEFAULT,
        CW_USEDEFAULT,
        (int)(inWidth * dpi) + 6,
        (int)(inHeight * dpi) + 28,
        NULL,
        NULL,
        zhInstance,
        NULL
        );

    if (hwndMain == NULL) {
        MessageBoxW(0, L"Error Creating Window!", L"Error!", MB_ICONSTOP | MB_OK);
        return 0;
    }

    // register the window for touch instead of gestures
    RegisterTouchWindow(hwndMain, TWF_WANTPALM);

#define TARGET_RESOLUTION 1         // 1-millisecond target resolution

#ifdef FEAT_MIDI
    TIMECAPS tc;
    UINT     wTimerRes;

    if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR)
    {
        return -1;
    }

    wTimerRes = min(max(tc.wPeriodMin, TARGET_RESOLUTION), tc.wPeriodMax);
    timeBeginPeriod(wTimerRes);
#endif

    // TODO: really should FreeConsole() and fclose(stdout) later but it'll be open til process end anyway.
    AllocConsole();
    freopen("CONOUT$", "wb", stdout);

    // display the possible MIDI output devices:
    show_midi_output_devices();

#ifdef FEAT_MIDI
    // Open the MIDI Mapper
    UINT midiDeviceID = (UINT)1;
    if (strlen(paCmdLine) > 0) {
        if (sscanf(paCmdLine, "\"%d\"", &midiDeviceID) == 0) {
            midiDeviceID = (UINT) 1;
        }
    }
    printf("Opening MIDI device ID #%d...\r\n", midiDeviceID);
    result = midiOutOpen(&outHandle, midiDeviceID, 0, 0, CALLBACK_WINDOW);
    if (result)
        printf("There was an error opening MIDI device!  Disabling MIDI output...\r\n\r\n");
    else
        printf("Opened MIDI device successfully.\r\n\r\n");
#endif

#ifdef HWFEAT_LABEL_UPDATES

    for (int i = 0; i < 8; i++) {
        labels[0][i] = (WCHAR *)malloc(sizeof(WCHAR) * 21);
        labels[1][i] = (WCHAR *)malloc(sizeof(WCHAR) * 21);
        labels_ascii[0][i] = (char *)malloc(sizeof(char) * 20);
        labels_ascii[1][i] = (char *)malloc(sizeof(char) * 20);
    }

#endif

    // initialize UI bits:
    fsw_state.bot.byte = 0;
    fsw_state.top.byte = 0;
    led_state.bot.byte = 0;
    led_state.top.byte = 0;

    // initialize the logic controller
    controller_init();

    // Show main window:
    ShowWindow(hwndMain, nCmdShow);
    UpdateWindow(hwndMain);

    SetTimer(hwndMain, IDT_TIMER10MS, 10, (TIMERPROC) NULL);

    PeekMessage(&Msg, NULL, 0, 0, PM_NOREMOVE);

    // default Win32 message pump
    //DWORD timeLast = timeGetTime();
    while (Msg.message != WM_QUIT) {
        if (!GetMessage(&Msg, NULL, 0, 0)) {
            break;
        }
        TranslateMessage(&Msg);
        DispatchMessage(&Msg);
    }

    return 0;
}
コード例 #21
0
ファイル: ser2net.c プロジェクト: MBARI-ESP/ESP2Glinux
int
main(int argc, char *argv[])
{
    int i;
    int err;

    err = sel_alloc_selector(&ser2net_sel);
    if (err) {
	fprintf(stderr,
		"Could not initialize ser2net selector: '%s'\n",
		strerror(err));
	return -1;
    }

    for (i=1; i<argc; i++) {
	if ((argv[i][0] != '-') || (strlen(argv[i]) != 2)) {
	    fprintf(stderr, "Invalid argument: '%s'\n", argv[i]);
	    arg_error(argv[0]);
	}

	switch (argv[i][1]) {
	case 'n':
	    detach = 0;
	    break;

	case 'd':
	    detach = 0;
	    debug = 1;
	    break;

	case 'b':
	    cisco_ios_baud_rates = 1;
	    break;

	case 'C':
	    /* Get a config line. */
	    i++;
	    if (i == argc) {
		fprintf(stderr, "No config line specified with -C\n");
		arg_error(argv[0]);
	    }
	    handle_config_line(argv[i]);
	    config_file = NULL;
	    break;

	case 'c':
	    /* Get a config file. */
	    i++;
	    if (i == argc) {
		fprintf(stderr, "No config file specified with -c\n");
		arg_error(argv[0]);
	    }
	    config_file = argv[i];
	    break;

	case 'p':
	    /* Get the control port. */
	    i++;
	    if (i == argc) {
		fprintf(stderr, "No control port specified with -p\n");
		arg_error(argv[0]);
	    }
	    config_port = argv[i];
	    break;
	
	case 'P':
	    i++;
	    if (i == argc) {
		fprintf(stderr, "No pid file specified with -P\n");
		arg_error(argv[0]);
	    }
	    pid_file = argv[i];
	    break;

#ifdef USE_UUCP_LOCKING
	case 'u':
	    uucp_locking_enabled = 0;
	    break;
#endif

	case 'v':
	    printf("%s version %s\n", argv[0], VERSION);
	    exit(0);

	default:
	    fprintf(stderr, "Invalid option: '%s'\n", argv[i]);
	    arg_error(argv[0]);
	}
    }

    setup_sighup();
    if (config_port != NULL) {
	if (controller_init(config_port) == -1) {
	    fprintf(stderr, "Invalid control port specified with -p\n");
	    arg_error(argv[0]);
	}
    }

    if (debug && !detach)
	openlog("ser2net", LOG_PID | LOG_CONS | LOG_PERROR, LOG_DAEMON);

    if (config_file) {
	if (readconfig(config_file) == -1) {
	    return 1;
	}
    }

    if (detach) {
	int pid;

	/* Detach from the calling terminal. */
	openlog("ser2net", LOG_PID | LOG_CONS, LOG_DAEMON);
	syslog(LOG_NOTICE, "ser2net startup");
	if ((pid = fork()) > 0) {
	    exit(0);
	} else if (pid < 0) {
	    syslog(LOG_ERR, "Error forking first fork");
	    exit(1);
	} else {
	    /* setsid() is necessary if we really want to demonize */
	    setsid();
	    /* Second fork to really deamonize me. */
	    if ((pid = fork()) > 0) {
		exit(0);
	    } else if (pid < 0) {
		syslog(LOG_ERR, "Error forking second fork");
		exit(1);
	    }
	}

	/* Close all my standard I/O. */
	chdir("/");
	close(0);
	close(1);
	close(2);
    }

    /* write pid file */
    make_pidfile(pid_file);

    /* Ignore SIGPIPEs so they don't kill us. */
    signal(SIGPIPE, SIG_IGN);

    set_sighup_handler(reread_config);

    sel_select_loop(ser2net_sel);

    return 0;
}
コード例 #22
0
ファイル: vrutest.c プロジェクト: OpenSorcery/libdragon
int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    console_init();
    controller_init();

    console_set_render_mode(RENDER_MANUAL);

    /* Main loop test */
    while(1) 
    {
        console_clear();

        /* To do initialize routines */
        controller_scan();

        int controllers = get_controllers_present();

        if( controllers & CONTROLLER_1_INSERTED )
        {
            int accessories = get_accessories_present();

            if( (accessories & CONTROLLER_4_INSERTED) && identify_accessory( 3 ) == ACCESSORY_VRU )
            {
                uint8_t out[64];
                uint8_t in[64];

                // Initial sequence
                out[0] = 0x00;
                out[1] = 0x00;
                print_request( 2, out );
                execute_raw_command( 3, 0xB, 2, 3, out, in );
                print_result( 3, in );

                // LODS OF 0x0B
                out[0] = 0x1E;
                out[1] = 0x0C;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x6E;
                out[1] = 0x07;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x08;
                out[1] = 0x0E;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x56;
                out[1] = 0x18;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                out[0] = 0x03;
                out[1] = 0x0F;
                print_request( 2, out );
                execute_raw_command( 3, 0xD, 2, 1, out, in );
                print_result( 1, in );

                // Some C's and B's
                out[0] = 0x00;
                out[1] = 0x00;
                out[2] = 0x00;
                out[3] = 0x00;
                out[4] = 0x01;
                out[5] = 0x00;
                print_request( 6, out );
                execute_raw_command( 3, 0xC, 6, 1, out, in );
                print_result( 1, in );

                out[0] = 0x00;
                out[1] = 0x00;
                print_request( 2, out );
                execute_raw_command( 3, 0xB, 2, 3, out, in );
                print_result( 3, in );
                
                out[0] = 0x00;
                out[1] = 0x00;
                out[2] = 0x02;
                out[3] = 0x00;
                out[4] = 0x3B;
                out[5] = 0x00;
                print_request( 6, out );
                execute_raw_command( 3, 0xC, 6, 1, out, in );
                print_result( 1, in );

                out[0] = 0x00;
                out[1] = 0x00;
                print_request( 2, out );
                execute_raw_command( 3, 0xB, 2, 3, out, in );
                print_result( 3, in );

                // Give that A a try
                memset( out, 0, sizeof( out ) );
                print_request( 22, out );
                execute_raw_command( 3, 0xA, 22, 1, out, in );
                print_result( 1, in );

                memset( out, 0, sizeof( out ) );
                print_request( 22, out );
                execute_raw_command( 3, 0xA, 22, 1, out, in );
                print_result( 1, in );

                memset( out, 0, sizeof( out ) );
                out[14] = 0x03;
                out[18] = 0x12;
                out[20] = 0x08;
                print_request( 22, out );
                execute_raw_command( 3, 0xA, 22, 1, out, in );
                print_result( 1, in );

                // Render it!
                console_render();
                while(1){;}
            }
            else
            {
                printf( "Please insert a VRU into slot 4.\n" );
            }
        }
        else
        {
            printf( "Please insert a standard\ncontroller into slot 1.\n" );
        }

        console_render();
    }
}
コード例 #23
0
void    main(void)

{
    /* 
     *  Gory hardware initialization.  This will set the controller
     *  to a reasonable default state.
     *
     *  Must be done first!
     */
    controller_init();
    
    /* Initialize ports, etc. for this robot configuration. */
    custom_init();

    /*
     *  If digital input port COMPETITION_JUMPER_PORT is jumpered, then
     *  the robot should run autonomous mode for the given number of
     *  seconds as soon as a signal is detected from the RC.
     *
     *  Field control should enable the RC momentarily to trigger
     *  this code to start autonomous, disable it for the remainder
     *  of the autonomous period, and re-enable it for teleoperated mode.
     */
    if ( io_read_digital(COMPETITION_JUMPER_PORT) == 0 )
    {
	/* Wait for RC signal */
	printf("Waiting for RC signal to begin autonomous period...\n");
	while ( rc_read_status() != 1 )
	    ;
	
	autonomous_routine_competition(20);
    }

    /* 
     *  Main loop.  Watch for the master processor to indicate
     *  that new data is available.
     */
    while (TRUE)
    {
	/*
	 *  This program runs on the VEX "user" processor. The VEX
	 *  "master" processor monitors the remote control and
	 *  generates PWMs (pulse-width modulation for motor power).  It
	 *  interrupts the user processor every 18.5ms to signal the
	 *  availability of new data.
	 *
	 *  Code that processes new data from the master processor
	 *  should go inside this if statement.  The if condition will
	 *  only evaluate to true every 18.5ms, so this loop "spins"
	 *  a lot waiting for new data, unless
	 *  process_master_data() takes up a good chunk of 18.5ms.
	 *  If it takes more than 18.5ms, data from the master processor
	 *  will be lost.  ( May or may not be a big deal. )
	 */
	
	if ( rc_new_data_available() )
	{
	    rc_routine();
#if ENABLE_AUTONOMOUS_ROUTINES
	    /*
	     *  Autonomous routines are triggered by a binary
	     *  sequence on button AUTO_TRIGGER_BUTTON.
	     *  Down = 0, Up = 1.  00 runs
	     *  autonomout_routine0(), 01 runs autonomous_routine1(),
	     *  etc.
	     */
	    switch( rc_button_sequence(AUTO_TRIGGER_BUTTON, AUTO_TRIGGER_SEQ_LEN) )
	    {
		case    0:
		    autonomous_routine0();
		    break;
		case    1:
		    //autonomous_routine1();
		    break;
		case    2:
		    autonomous_routine2();
		    break;
		case    3:
		    //autonomous_routine3();
		    break;
		default:
		    break;
	    }
#endif  /* ENABLE_AUTONOMOUS_ROUTINES */
	} 
    }
}
コード例 #24
0
ファイル: dfsdemo.c プロジェクト: DragonMinded/libdragon
int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize audio and video */
    audio_init(44100,2);
    console_init();

    /* Initialize key detection */
    controller_init();

    MikMod_RegisterAllDrivers();
    MikMod_RegisterAllLoaders();

    md_mode |= DMODE_16BITS;
    md_mode |= DMODE_SOFT_MUSIC;
    md_mode |= DMODE_SOFT_SNDFX;
    //md_mode |= DMODE_STEREO;
                                            
    md_mixfreq = audio_get_frequency();

    MikMod_Init("");

    if(dfs_init( DFS_DEFAULT_LOCATION ) != DFS_ESUCCESS)
    {
        printf("Filesystem failed to start!\n");
    }
    else
    {
        direntry_t *list;
        int count = 0;
        int page = 0;
        int cursor = 0; 

        console_set_render_mode(RENDER_MANUAL);
        console_clear();

        list = populate_dir(&count);

        while(1)
        {
            console_clear();
            display_dir(list, cursor, page, MAX_LIST, count);
            console_render();

            controller_scan();
            struct controller_data keys = get_keys_down();

            if(keys.c[0].up)
            {
                cursor--;
                new_scroll_pos(&cursor, &page, MAX_LIST, count);
            }

            if(keys.c[0].down)
            {
                cursor++;
                new_scroll_pos(&cursor, &page, MAX_LIST, count);
            }

            if(keys.c[0].C_right && list[cursor].type == DT_REG)
            {
                /* Module playing loop */
                MODULE *module = NULL;

                /* Concatenate to make file */
                char path[512];

                strcpy( path, dir );
                strcat( path, list[cursor].filename );

                module = Player_Load(path, 256, 0);
                
                /* Ensure that first part of module doesn't get cut off */
                audio_write_silence();
                audio_write_silence();

                if(module)
                {
                    char c = '-';
                    int sw = 0;

                    Player_Start(module);

                    while(1)
                    {
                        if(sw == 5)
                        {
                            console_clear();
                            display_dir(list, cursor, page, MAX_LIST, count);

                            sw = 0;
                            switch(c)
                            {
                                case '-':
                                    c = '\\';
                                    break;
                                case '\\':
                                    c = '|';
                                    break;
                                case '|':
                                    c = '/';
                                    break;
                                case '/':
                                    c = '-';
                                    break;
                            }
    
                            printf("\n\n\n%c Playing module", c);                        
                            console_render();
                        }
                        else
                        {
                            sw++;
                        }

                        MikMod_Update();

                        controller_scan();
                        struct controller_data keys = get_keys_down();

                        if(keys.c[0].C_left || !Player_Active())
                        {
                            /* End playback */
                            audio_write_silence();
                            audio_write_silence();
                            audio_write_silence();
                            audio_write_silence();

                            break;
                        }
                    }
                
                    Player_Stop();
                    Player_Free(module);
                }
            }

            if(keys.c[0].L)
            {
                /* Open the SD card */
                strcpy( dir, "sd://" );

                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }

            if(keys.c[0].R)
            {
                /* Open the ROM FS card */
                strcpy( dir, "rom://" );

                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }

            if(keys.c[0].A && list[cursor].type == DT_DIR)
            {
                /* Change directories */
                chdir(list[cursor].filename);
       
                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }

            if(keys.c[0].B)
            {
                /* Up! */
                chdir("..");
       
                /* Populate new directory */
                free_dir(list);
                list = populate_dir(&count);

                page = 0;
                cursor = 0;
            }
        }
    }

    while(1);

    return 0;
}
コード例 #25
0
ファイル: spritemap.c プロジェクト: DragonMinded/libdragon
int main(void)
{
    int mode = 0;

    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( RESOLUTION_320x240, DEPTH_16_BPP, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    dfs_init( DFS_DEFAULT_LOCATION );
    rdp_init();
    controller_init();
    timer_init();

    /* Read in single sprite */
    int fp = dfs_open("/mudkip.sprite");
    sprite_t *mudkip = malloc( dfs_size( fp ) );
    dfs_read( mudkip, 1, dfs_size( fp ), fp );
    dfs_close( fp );
    
    fp = dfs_open("/earthbound.sprite");
    sprite_t *earthbound = malloc( dfs_size( fp ) );
    dfs_read( earthbound, 1, dfs_size( fp ), fp );
    dfs_close( fp );

    fp = dfs_open("/plane.sprite");
    sprite_t *plane = malloc( dfs_size( fp ) );
    dfs_read( plane, 1, dfs_size( fp ), fp );
    dfs_close( fp );

    /* Kick off animation update timer to fire thirty times a second */
    new_timer(TIMER_TICKS(1000000 / 30), TF_CONTINUOUS, update_counter);

    /* Main loop test */
    while(1) 
    {
        static display_context_t disp = 0;

        /* Grab a render buffer */
        while( !(disp = display_lock()) );
       
        /*Fill the screen */
        graphics_fill_screen( disp, 0xFFFFFFFF );

        /* Set the text output color */
        graphics_set_color( 0x0, 0xFFFFFFFF );
    
        switch( mode )
        {
            case 0:
                /* Software spritemap test */
                graphics_draw_text( disp, 20, 20, "Software spritemap test" );

                /* Display a stationary sprite of adequate size to fit in TMEM */
                graphics_draw_sprite_trans( disp, 20, 50, plane );

                /* Display a stationary sprite to demonstrate backwards compatibility */
                graphics_draw_sprite_trans( disp, 50, 50, mudkip );

                /* Display walking NESS animation */
                graphics_draw_sprite_stride( disp, 20, 100, earthbound, ((animcounter / 15) & 1) ? 1: 0 );

                /* Display rotating NESS animation */
                graphics_draw_sprite_stride( disp, 50, 100, earthbound, ((animcounter / 8) & 0x7) * 2 );

                break;
            case 1:
            {
                /* Hardware spritemap test */
                graphics_draw_text( disp, 20, 20, "Hardware spritemap test" );

                /* Assure RDP is ready for new commands */
                rdp_sync( SYNC_PIPE );

                /* Remove any clipping windows */
                rdp_set_default_clipping();

                /* Enable sprite display instead of solid color fill */
                rdp_enable_texture_copy();

                /* Attach RDP to display */
                rdp_attach_display( disp );
                    
                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture( 0, 0, MIRROR_DISABLED, plane );
                
                /* Display a stationary sprite of adequate size to fit in TMEM */
                rdp_draw_sprite( 0, 20, 50 );

                /* Since the RDP is very very limited in texture memory, we will use the spritemap feature to display
                   all four pieces of this sprite individually in order to use the RDP at all */
                for( int i = 0; i < 4; i++ )
                {
                    /* Ensure the RDP is ready to receive sprites */
                    rdp_sync( SYNC_PIPE );

                    /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                    rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, mudkip, i );
                
                    /* Display a stationary sprite to demonstrate backwards compatibility */
                    rdp_draw_sprite( 0, 50 + (20 * (i % 2)), 50 + (20 * (i / 2)) );
                }

                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, earthbound, ((animcounter / 15) & 1) ? 1: 0 );
                
                /* Display walking NESS animation */
                rdp_draw_sprite( 0, 20, 100 );

                /* Ensure the RDP is ready to receive sprites */
                rdp_sync( SYNC_PIPE );

                /* Load the sprite into texture slot 0, at the beginning of memory, without mirroring */
                rdp_load_texture_stride( 0, 0, MIRROR_DISABLED, earthbound, ((animcounter / 8) & 0x7) * 2 );
                
                /* Display rotating NESS animation */
                rdp_draw_sprite( 0, 50, 100 );

                /* Inform the RDP we are finished drawing and that any pending operations should be flushed */
                rdp_detach_display();

                break;
            }
        }

        /* Force backbuffer flip */
        display_show(disp);

        /* Do we need to switch video displays? */
        controller_scan();
        struct controller_data keys = get_keys_down();

        if( keys.c[0].A )
        {
            /* Lazy switching */
            mode = 1 - mode;
        }
    }
}
コード例 #26
0
ファイル: newsroom.c プロジェクト: acasaccia/openomf
void newsroom_input_tick(scene *scene) {
    newsroom_local *local = scene_get_userdata(scene);

    game_player *player1 = game_state_get_player(scene->gs, 0);
    ctrl_event *p1=NULL, *i;
    controller_poll(player1->ctrl, &p1);
    i = p1;
    if (i) {
        do {
            if(i->type == EVENT_TYPE_ACTION) {
                if(dialog_is_visible(&local->continue_dialog)) {
                    dialog_event(&local->continue_dialog, i->event_data.action);
                } else if (
                        i->event_data.action == ACT_ESC ||
                        i->event_data.action == ACT_KICK ||
                        i->event_data.action == ACT_PUNCH) {
                    local->screen++;
                    newsroom_fixup_str(local);
                    if(local->screen >= 2) {
                        if (local->won) {
                            // pick a new player
                            game_player *p1 = game_state_get_player(scene->gs, 0);
                            game_player *p2 = game_state_get_player(scene->gs, 1);
                            DEBUG("wins are %d", p1->sp_wins);
                            if (p1->sp_wins == (4094 ^ (2 << p1->pilot_id)))  {
                                // won the game
                                game_state_set_next(scene->gs, SCENE_END);
                            } else {
                                if (p1->sp_wins == (2046 ^ (2 << p1->pilot_id))) {
                                    // everyone but kriessack
                                    p2->pilot_id = 10;
                                    p2->har_id = HAR_NOVA;
                                } else {
                                    // pick an opponent we have not yet beaten
                                    while(1) {
                                        int i = rand_int(10);
                                        if ((2 << i) & p1->sp_wins || i == p1->pilot_id) {
                                            continue;
                                        }
                                        p2->pilot_id = i;
                                        p2->har_id = rand_int(10);
                                        break;
                                    }
                                }
                                pilot p;
                                pilot_get_info(&p, p2->pilot_id);
                                p2->colors[0] = p.colors[0];
                                p2->colors[1] = p.colors[1];
                                p2->colors[2] = p.colors[2];

                                // make a new AI controller
                                controller *ctrl = malloc(sizeof(controller));
                                controller_init(ctrl);
                                ai_controller_create(ctrl, settings_get()->gameplay.difficulty);
                                game_player_set_ctrl(p2, ctrl);
                                game_state_set_next(scene->gs, SCENE_VS);
                            }
                        } else {
                            dialog_show(&local->continue_dialog, 1);
                        }
                    }
                }
            }
        } while((i = i->next));
    }
    controller_free_chain(p1);
}
コード例 #27
0
ファイル: ctest.c プロジェクト: OpenSorcery/libdragon
int main(void)
{
    /* enable interrupts (on the CPU) */
    init_interrupts();

    /* Initialize peripherals */
    display_init( res, bit, 2, GAMMA_NONE, ANTIALIAS_RESAMPLE );
    console_init();
    controller_init();

    console_set_render_mode(RENDER_MANUAL);

    int testv = 0;
    int press = 0;
    uint8_t data[32];
    memset( data, 0, 32 );

    /* Main loop test */
    while(1) 
    {
        console_clear();

        /* To do initialize routines */
        controller_scan();

        struct controller_data keys = get_keys_down();

        for( int i = 0; i < 4; i++ )
        {
            if( keys.c[i].A )
            {
                rumble_start( i );
            }

            if( keys.c[i].B )
            {
                rumble_stop( i );
            }

            if( keys.c[i].Z )
            {
                press = read_mempak_address( i, 0x0000, data );
            }
        }

        int controllers = get_controllers_present();

        printf( "Controller 1 %spresent\n", (controllers & CONTROLLER_1_INSERTED) ? "" : "not " );
        printf( "Controller 2 %spresent\n", (controllers & CONTROLLER_2_INSERTED) ? "" : "not " );
        printf( "Controller 3 %spresent\n", (controllers & CONTROLLER_3_INSERTED) ? "" : "not " );
        printf( "Controller 4 %spresent\n", (controllers & CONTROLLER_4_INSERTED) ? "" : "not " );

        int accessories = get_accessories_present();

        printf( "Accessory 1 %spresent %s\n", (accessories & CONTROLLER_1_INSERTED) ? "" : "not ", 
                                              (accessories & CONTROLLER_1_INSERTED) ? format_type( identify_accessory( 0 ) ) : "" );
        printf( "Accessory 2 %spresent %s\n", (accessories & CONTROLLER_2_INSERTED) ? "" : "not ",
                                              (accessories & CONTROLLER_2_INSERTED) ? format_type( identify_accessory( 1 ) ) : "" );
        printf( "Accessory 3 %spresent %s\n", (accessories & CONTROLLER_3_INSERTED) ? "" : "not ",
                                              (accessories & CONTROLLER_3_INSERTED) ? format_type( identify_accessory( 2 ) ) : "" );
        printf( "Accessory 4 %spresent %s\n", (accessories & CONTROLLER_4_INSERTED) ? "" : "not ",
                                              (accessories & CONTROLLER_4_INSERTED) ? format_type( identify_accessory( 3 ) ) : "" );

        printf("\n%d\n\n", testv++ );

        for( int i = 0; i < 32; i++ )
        {
            printf( "%02X", data[i] );
        }

        printf( "\n\n" );
        printf( "Operation returned: %d\n", press );

        console_render();
    }
}
コード例 #28
0
ファイル: controller.c プロジェクト: syy2868/787Project
/* Function block execution function */
void controllerrun(controller* me)
{
    me->_output.events = 0;

    if (me->_input.event.clock) {
        me->x = me->_x;
        me->timer1 = me->_timer1;
        me->timer2 = me->_timer2;
    }
    for (;;) {
        switch (me->_state) {
            case 0:
                // State: Start
                if (!me->_entered) {
                    controller_init(me);
                    me->_entered = true;
                }
                else {
                    me->_state = 1;
                    me->_entered = false;
                    continue;
                }
                break;
            case 1:
                // State: State1
                if (!me->_entered) {
                    me->_entered = true;
                }
                else {
                    if (true && (me->x >= 550 && me->timer2 >= me->c)) {
                        me->_state = 2;
                        me->_entered = false;
                        continue;
                    }
                    else if (true && (me->x >= 550 && me->timer1 >= me->c && me->timer2 <= me->c)) {
                        me->_state = 4;
                        me->_entered = false;
                        continue;
                    }
                }
                break;
            case 2:
                // State: State3
                if (!me->_entered) {
                    controller_signal_add2(me);
                    me->_output.event.add2 = 1;
                    me->_entered = true;
                }
                else {
                    if (true && (me->x <= 510)) {
                        me->_state = 3;
                        me->_entered = false;
                        continue;
                    }
                }
                break;
            case 3:
                // State: State5
                if (!me->_entered) {
                    controller_signal_remove2(me);
                    me->_output.event.remove2 = 1;
                    me->_output.event.refresh2 = 1;
                    me->_entered = true;
                }
                else {
                    me->_state = 1;
                    me->_entered = false;
                    continue;
                }
                break;
            case 4:
                // State: State2
                if (!me->_entered) {
                    controller_signal_add1(me);
                    me->_output.event.add1 = 1;
                    me->_entered = true;
                }
                else {
                    if (true && (me->x <= 510)) {
                        me->_state = 5;
                        me->_entered = false;
                        continue;
                    }
                }
                break;
            case 5:
                // State: State4
                if (!me->_entered) {
                    controller_signal_remove1(me);
                    me->_output.event.remove1 = 1;
                    me->_output.event.refresh1 = 1;
                    me->_entered = true;
                }
                else {
                    me->_state = 1;
                    me->_entered = false;
                    continue;
                }
                break;
        }
        break;
    }

    me->_input.events = 0;
}
コード例 #29
0
ファイル: audio_example.c プロジェクト: kerichsen/asf
/*! \brief Main function. Execution starts here.
 *
 * \retval 42 Fatal error.
 */
int main(void)
{
    init_hmatrix();

    // Configure standard I/O streams as unbuffered.
#if (defined __GNUC__) && (defined __AVR32__)
    setbuf(stdin, NULL);
#endif
    setbuf(stdout, NULL);

#if (defined USB_RESYNC_METHOD) && (USB_RESYNC_METHOD == USB_RESYNC_METHOD_EXT_CLOCK_SYNTHESIZER)
    // Initialize the TWI using the internal RCOSC
    init_twi_CS2200(AVR32_PM_RCOSC_FREQUENCY);

    // Initialize the CS2200 and produce a default 11.2896 MHz frequency
    cs2200_setup(11289600, FOSC0);
#endif

    // Initializes the MCU system clocks
    init_sys_clocks();

    // Initialize the TWI
    init_twi(FPBA_HZ);

    audio_mixer_enable_dacs(DEFAULT_DACS);
    audio_mixer_dacs_start(DEFAULT_DAC_SAMPLE_RATE_HZ,
                           DEFAULT_DAC_NUM_CHANNELS,
                           DEFAULT_DAC_BITS_PER_SAMPLE,
                           DEFAULT_DAC_SWAP_CHANNELS);

    // Initialize the display
    et024006_Init(  FCPU_HZ, FHSB_HZ);

    // Set Backlight
    gpio_set_gpio_pin(ET024006DHU_BL_PIN);

    // Clear the display
    et024006_DrawFilledRect(0, 0, ET024006_WIDTH, ET024006_HEIGHT, WHITE );

    // Display a logo.
    et024006_PutPixmap(avr32_logo, AVR32_LOGO_WIDTH, 0, 0
                       ,(ET024006_WIDTH - AVR32_LOGO_WIDTH)/2
                       ,(ET024006_HEIGHT - AVR32_LOGO_HEIGHT)/2, AVR32_LOGO_WIDTH, AVR32_LOGO_HEIGHT);

    et024006_PrintString(AUDIO_DEMO_STRING, (const unsigned char *)&FONT8x16, 30, 5, BLACK, -1);
    et024006_PrintString("Please plug the USB.", (const unsigned char *)&FONT8x8, 30, 30, BLACK, -1);

    // Initialize USB task
    usb_task_init();

    // Initialize Controller
    controller_init(FCPU_HZ, FHSB_HZ, FPBB_HZ, FPBA_HZ);

#if USB_DEVICE_FEATURE == true
    // Initialize device audio USB task
    device_audio_task_init();

    // Initialize the HID USB task
    device_hid_task_init();
#endif
#if USB_HOST_FEATURE == true
    // Initialize host audio USB task
    host_audio_task_init();
#endif

#ifdef FREERTOS_USED
    // Start OS scheduler
    vTaskStartScheduler();
    portDBG_TRACE("FreeRTOS returned.");
    return 42;
#else
    // No OS here. Need to call each task in round-robin mode.
    while (true)
    {
        usb_task();
#if USB_DEVICE_FEATURE == true
        device_audio_task();
        device_hid_task();
#endif
#if USB_HOST_FEATURE == true
        host_audio_task();
#endif
    }
#endif  // FREERTOS_USED
}
コード例 #30
0
int main() {
    INPUT_VAL iv;
    RETURN_VAL rv;

    // controller new state array
    int state_arr_[NUM_STATES];

    // controller output array
    int output_arr[NUM_OUTPUTS];

    // extraneous input arr
    int input_arr[NUM_INPUTS];

    // controller present state array
    //int state_arr[NUM_STATES] = { 1, 12, 123 };
    int state_arr[NUM_STATES];

    // plant state array
    int x_arr[NUM_X];

    int dummy_nextstate_arr[NUM_STATES];
    int dummy_output_arr[NUM_OUTPUTS];


#if CONTROLLER_MODE == UNROLL
"I can not be compiled"
#elif CONTROLLER_MODE == CONCOLIC
    // do nothing
#elif CONTROLLER_MODE == SYMBOLIC
    //make state symbolic
    klee_make_symbolic(state_arr, sizeof(state_arr), "state_arr");
#else
"I can not be compiled"
#endif

    // make X symbolic
    klee_make_symbolic(x_arr, sizeof(x_arr), "x_arr");

    // make extraneous inputs symbolic
    klee_make_symbolic(input_arr, sizeof(input_arr), "input_arr");

    klee_make_symbolic(dummy_nextstate_arr, sizeof(dummy_nextstate_arr), "dummy_nextstate_arr");
    klee_make_symbolic(dummy_output_arr, sizeof(dummy_output_arr), "dummy_output_arr");

    // not sure what the below commented code is showing...? Test it out?
    /*
    klee_make_symbolic(&s[0], sizeof(int), "s0");
    klee_make_symbolic(&x[0], sizeof(int), "x0");
    klee_make_symbolic(&s[1], sizeof(int), "s1");
    klee_make_symbolic(&x[1], sizeof(int), "x1");
    */

    /*
    s[0] = klee_int("s0");
    s[1] = klee_int("s1");
    x[0] = klee_int("x0");
    x[1] = klee_int("x1");
    */

    // write klee assumes
    // klee_assume((x[0] >= 0)&(s[0] >= 0)&(x[0] <= 10)&(s[0] <= 10));
    // klee_assume((x[1] >= 0)&(s[1] >= 0)&(x[1] <= 10)&(s[1] <= 10));

    /*
    klee_assume(x_arr[0] >= 2800);
    klee_assume(x_arr[0] <= 2900);

    klee_assume(state_arr[0] >= 0);
    klee_assume(state_arr[0] <= 0);
    */


//klee_assume(state_arr[2] >= 0);
//klee_assume(state_arr[2] <= 999);

//klee_assume(input_arr[0] >= 0);
//klee_assume(input_arr[0] <= 0);


    // controller init functions need to be defined
    controller_init();

    iv.state_arr = state_arr;
    iv.x_arr = x_arr;
    iv.input_arr = input_arr; 

    rv.state_arr = state_arr_;
    rv.output_arr = output_arr;

    // ignore return value.
    controller(&iv, &rv);

    //klee_assert(dummy_nextstate_arr[0] == state_arr_[0] & dummy_nextstate_arr[1] == state_arr_[1] & dummy_nextstate_arr[2] == state_arr_[2] & dummy_output_arr[0] == output_arr[0]);
    {
      int i = 0;
      int dummy_output_assert = 1;
      int dummy_state_assert = 1;
      for(i=0;i<NUM_OUTPUTS;i++){
        dummy_output_assert &= (dummy_output_arr[i] == output_arr[i]);
      }
      for(i=0;i<NUM_STATES;i++){
        dummy_state_assert &= (dummy_nextstate_arr[i] == state_arr_[i]);
      }
      /*
      int a1 = (dummy_output_arr[0] == output_arr[0]);
      int a2 = (dummy_nextstate_arr[0] == state_arr_[0]);
      int a3 = (dummy_nextstate_arr[1] == state_arr_[1]);
      int a4 = (dummy_nextstate_arr[2] == state_arr_[2]);
      klee_assert(a1 & a2 & a3 & a4);
      */
      klee_assert(dummy_output_assert & dummy_state_assert);
    }

    // add provided klee asserts
    //klee_assert(rv.output_arr[0] == 0U);

    return 0;
}