Esempio n. 1
0
int		init_SDL(t_graph *graph)
{
  graph->pos = (HEIGHT / 2) - (HEIGHT / 4);
  graph->poscurs = 0;
  set_null(graph);
  SDL_WM_SetCaption(NAME, NULL);
  graph->charac_num = 0;
  if (TTF_Init() == -1)
    return (-1);
  init_font(graph);
  if (SDL_Init(SDL_INIT_EVERYTHING) == -1)
    return (-1);
  graph->screen = SDL_SetVideoMode(WIDTH, HEIGHT, BPP,
				   SDL_SWSURFACE | SDL_FULLSCREEN);
  if (graph->screen == NULL)
    return (-1);
  graph->quit = 0;
  set_character(graph);
  init_spaceship(graph);
  graph->background = load_image("img/space.bmp");
  graph->spacefactor = 1;
  init_joystick(graph);
  intro_music(graph);
  return (0);
}
Esempio n. 2
0
int
main()
{
  init_joystick();

  while(1){
    read_joystick();
    const rc_t * rc = get_rc();
    printf("throttle: % .3f, yaw: % .3f, pitch: % .3f, roll: % .3f, "
           "enable: %d, mode: %d, gear: %d, aux2: %d\n",
           rc->throttle,rc->yaw,rc->pitch,rc->roll,rc->enable,rc->mode,rc->gear,rc->aux2);
    usleep(100000);
  }

}
static void setupHardware(void) {
    // TODO: Put hardware configuration and initialisation in here
    disable_global_int();
    clk_system_init();
    init_leds();
    //init_pot();
    init_buttons();
    init_spi();
    init_lcd_write_task();
    init_uart0();
    init_joystick();
     
    enable_global_int();
     
 
    // Warning: If you do not initialize the hardware clock, the timings will be inaccurate
}
Esempio n. 4
0
int main (void)
{	
	board_init();
	init_sensor_interrupts();
	init_joystick();
	init_timer0();
	init_serial_stdio(9600,0);
	init_var();
	struct Motor* A = malloc(sizeof(Motor));
	struct Motor* B = malloc(sizeof(Motor));
	A->pos = 0;
	B->pos = 0;
	A->ID = 0;
	B->ID = 1;
	sei();
	printf_P(PSTR("WOOP------------------------------------------------------------------------------\n"));
	clear_terminal();
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//                                          uSEFUL cODE                                                       //                                                                  
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	//To test the sensors are working
	//banana();
	
	//Seminar demo code
	//DEMO(A,B);
	
	//To test the motors are working
	//Azathoth(A,B);
	
	//To test beta pan function
	//qwert(A,B);
	
	//Tuesday test code
	// Pin C0 acts as sensor input
	//  Pins D0-D7 run the motors
	//  Pin C1 is the Emitter control 
	//  Pin C2 is the Magnet Control */
		
	Nyarlathotep(A,B);
	
	return 0;
}
Esempio n. 5
0
int main(int argc ,char *argv[])
{
	SDL_Init(SDL_INIT_EVERYTHING);
	init_joystick();
	while(1)
	{
		if(SDL_PollEvent( &event))
		{
			joy_axis_motion();
			joy_button_down();
			joy_button_up();
#if ANALOG
			joy_hat_motion();
			joy_ball_motion();
#endif
		}
		SDL_Delay(10);
	}
	close_joystick();
}
Esempio n. 6
0
// Initializes an arduino.
// Parameters: the arduino pointer
//             the device the arduino is connected to
//             the device the joystick is connected to
// return: 0 on success, non-zero on failure.
int init_arduino(rov_arduino *a,const char *af,const char *jf){
    struct termios topts;
    if ((a->fd = open(af,O_RDWR | O_NONBLOCK)) == -1){
        perror("init_arduino: could not open af");
        return -1;
    }
    if (tcgetattr(a->fd,&topts) < 0){
        perror("init_arduino: could not get term attr");
        return -1;
    }
    // Sets up 'the terminal' settings, we treat the arduino as a tty.
    cfsetispeed(&topts,B9600);
    cfsetospeed(&topts,B9600);
    topts.c_cflag     &= ~PARENB;
    topts.c_cflag     &= ~CSTOPB;
    topts.c_cflag     &= ~CSIZE;
    topts.c_cflag     |= CS8;
    topts.c_cflag     &= ~CRTSCTS;
    topts.c_cflag     |= CREAD | CLOCAL;
    topts.c_iflag     &= ~(IXON | IXOFF | IXANY);
    topts.c_lflag     &= ~(ICANON | ECHO | ECHOE | ISIG);
    topts.c_oflag     &= ~OPOST;
    topts.c_cc[VMIN]  =  0;  // Minimum number of characters to read.
    topts.c_cc[VTIME] =  0;  // VTIME * 0.1 = Time to wait for input.
    tcsetattr(a->fd,TCSANOW,&topts);
    if (tcsetattr(a->fd,TCSAFLUSH,&topts) < 0){
        perror("init_arduino: could not set term attributes");
        return -1;
    }
    if (!init_joystick(&a->joystick,jf)){
        perror("init_arduino: could not read joystick file");
        return -1;
    }
    init_ctrlstate(&a->ctrl);
    init_pinlayout(&a->layout);
    init_queue(&a->queue,a,2500,100);
    return 0;
}
Esempio n. 7
0
/*
Self-explanatory.
*/
void init_at_startup(void)
{

   LOCK_FUNCTION (framecount);
   LOCK_FUNCTION (tickover);
   LOCK_VARIABLE (ticked);
   LOCK_VARIABLE (frames_per_second);
   LOCK_VARIABLE (framecounter);
   LOCK_VARIABLE (turns_per_second);
   LOCK_VARIABLE (turncounter);

   install_int (framecount, 1000);
   install_int (tickover, 20);

   set_color_depth(8);

   int randseed = get_config_int("Misc", "Seed", 0);
   srand(randseed);

   options.windowed = get_config_int("Misc", "Windowed", 0);


 int windowed;
 switch(options.windowed)
 {
    default:
     case 1: windowed = GFX_AUTODETECT_WINDOWED; break;
     case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break;
 }

//   windowed  = GFX_AUTODETECT_WINDOWED;
//   windowed = GFX_AUTODETECT_FULLSCREEN;

//   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
//   if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0)
   if (set_gfx_mode(windowed, 800, 600, 0, 0) != 0)
   {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 800x600 256 colour display mode. Sorry!\n%s\n", allegro_error);
      exit(1);
   }

 init_trig();

 prepare_display();
 init_sound();
/*
 PP.ckey [CKEY_UP] = KEY_UP;
 PP.ckey [CKEY_DOWN] = KEY_DOWN;
 PP.ckey [CKEY_LEFT] = KEY_LEFT;
 PP.ckey [CKEY_RIGHT] = KEY_RIGHT;
 PP.ckey [CKEY_FIRE1] = KEY_Z;
 PP.ckey [CKEY_FIRE2] = KEY_X;
 PP.ckey [CKEY_FIRE3] = KEY_C;
*/
 int p = 0;

 init_joystick();

 player[0].control = get_config_int("misc", "player1_control", CONTROL_KEY_A);
 player[1].control = get_config_int("misc", "player2_control", CONTROL_KEY_B);

// if a particular joystick isn't available, default to keyboard controls.
//  note that this doesn't set the config values
 for (p = 0; p < 2; p ++)
 {
  if (options.joystick_available [0] == 0
   && PP.control == CONTROL_JOY_A)
   {
    PP.control = CONTROL_KEY_A;
    if (PP.control == CONTROL_KEY_A)
     PP.control = CONTROL_KEY_B;
   }
  if (options.joystick_available [1] == 0
   && PP.control == CONTROL_JOY_B)
   {
    PP.control = CONTROL_KEY_A;
    if (PP.control == CONTROL_KEY_A)
     PP.control = CONTROL_KEY_B;
   }
 }

 options.ckey [0] [CKEY_UP] = get_config_int("Misc", "key1_up", KEY_8_PAD);
 options.ckey [0] [CKEY_DOWN] = get_config_int("Misc", "key1_down", KEY_2_PAD);
 options.ckey [0] [CKEY_LEFT] = get_config_int("Misc", "key1_left", KEY_4_PAD);
 options.ckey [0] [CKEY_RIGHT] = get_config_int("Misc", "key1_right", KEY_6_PAD);
 options.ckey [0] [CKEY_LEFT2] = get_config_int("Misc", "key1_left2", KEY_1_PAD);
 options.ckey [0] [CKEY_RIGHT2] = get_config_int("Misc", "key1_right2", KEY_3_PAD);
 options.ckey [0] [CKEY_FIRE1] = get_config_int("Misc", "key1_fire1", KEY_Z);
 options.ckey [0] [CKEY_FIRE2] = get_config_int("Misc", "key1_fire2", KEY_X);
 options.ckey [0] [CKEY_FIRE3] = get_config_int("Misc", "key1_fire3", KEY_C);
 options.ckey [0] [CKEY_FIRE4] = get_config_int("Misc", "key1_fire4", KEY_V);
 options.ckey [0] [CKEY_COMMAND] = get_config_int("Misc", "key1_command", KEY_A);

 options.ckey [1] [CKEY_UP] = get_config_int("Misc", "key2_up", KEY_UP);
 options.ckey [1] [CKEY_DOWN] = get_config_int("Misc", "key2_down", KEY_DOWN);
 options.ckey [1] [CKEY_LEFT] = get_config_int("Misc", "key2_left", KEY_LEFT);
 options.ckey [1] [CKEY_RIGHT] = get_config_int("Misc", "key2_right", KEY_RIGHT);
 options.ckey [1] [CKEY_LEFT2] = get_config_int("Misc", "key2_left2", KEY_J);
 options.ckey [1] [CKEY_RIGHT2] = get_config_int("Misc", "key2_right2", KEY_K);
 options.ckey [1] [CKEY_FIRE1] = get_config_int("Misc", "key2_fire1", KEY_T);
 options.ckey [1] [CKEY_FIRE2] = get_config_int("Misc", "key2_fire2", KEY_Y);
 options.ckey [1] [CKEY_FIRE3] = get_config_int("Misc", "key2_fire3", KEY_U);
 options.ckey [1] [CKEY_FIRE4] = get_config_int("Misc", "key2_fire4", KEY_I);
 options.ckey [1] [CKEY_COMMAND] = get_config_int("Misc", "key2_command", KEY_O);


/*
 PP.ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP);
 PP.ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN);
 PP.ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT);
 PP.ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT);
 PP.ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z);
 PP.ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X);
 PP.ckey [CKEY_FIRE3] = get_config_int("Misc", "key_fire3", KEY_C);
 PP.ckey [CKEY_FIRE4] = get_config_int("Misc", "key_fire4", KEY_V);
*/
/*
 player[1].ckey [CKEY_UP] = get_config_int("MiscP2", "key_up", KEY_UP);
 player[1].ckey [CKEY_DOWN] = get_config_int("MiscP2", "key_down", KEY_DOWN);
 player[1].ckey [CKEY_LEFT] = get_config_int("MiscP2", "key_left", KEY_LEFT);
 player[1].ckey [CKEY_RIGHT] = get_config_int("MiscP2", "key_right", KEY_RIGHT);
 player[1].ckey [CKEY_LEFT2] = get_config_int("MiscP2", "key_left2", KEY_K);
 player[1].ckey [CKEY_RIGHT2] = get_config_int("MiscP2", "key_right2", KEY_L);
 player[1].ckey [CKEY_FIRE1] = get_config_int("MiscP2", "key_fire1", KEY_0_PAD);
 player[1].ckey [CKEY_FIRE2] = get_config_int("MiscP2", "key_fire2", KEY_P);
 player[1].ckey [CKEY_FIRE3] = get_config_int("MiscP2", "key_fire3", KEY_O);
 player[1].ckey [CKEY_FIRE4] = get_config_int("MiscP2", "key_fire4", KEY_I);

 options.joy_stick = get_config_int("Misc", "joy_stick", 0);

 options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70);
 options.init_joystick = get_config_int("Misc", "joy_init", 1);*/

// options.joystick = 0;
// options.key_or_joy = 0; // don't put in initfile!

 options.sfx_volume = get_config_int("Misc", "sfx_volume", 70);
 options.ambience_volume = get_config_int("Misc", "ambience_volume", 100);
 options.run_vsync = get_config_int("Misc", "run_vsync", 0);
 options.fix_camera_angle = get_config_int("Misc", "fix_camera_angle", 0);
 options.joystick_dual = get_config_int("Misc", "joystick_dual", 1);

// set_config_int("Misc", "Tourist", 3);
// set_config_int("Misc", "joy_stick", 0);

// if (options.init_joystick)
// if (options.joystick == 1) // set in init_joystick
 {
  options.joy_button [0] [0] = get_config_int("Misc", "joy1_button_1", 0);
  if (options.joy_button [0] [0] > joy[0].num_buttons)
   options.joy_button [0] [0] = joy[0].num_buttons - 1;
  options.joy_button [0] [1] = get_config_int("Misc", "joy1_button_2", 1);
  if (options.joy_button [0] [1] > joy[0].num_buttons)
   options.joy_button [0] [1] = joy[0].num_buttons - 1;
  options.joy_button [0] [2] = get_config_int("Misc", "joy1_button_3", 2);
  if (options.joy_button [0] [2] > joy[0].num_buttons)
   options.joy_button [0] [2] = joy[0].num_buttons - 1;
  options.joy_button [0] [3] = get_config_int("Misc", "joy1_button_4", 4);
  if (options.joy_button [0] [3] > joy[0].num_buttons)
   options.joy_button [0] [3] = joy[0].num_buttons - 1;
  options.joy_button [0] [4] = get_config_int("Misc", "joy1_button_5", 5);
  if (options.joy_button [0] [4] > joy[0].num_buttons)
   options.joy_button [0] [4] = joy[0].num_buttons - 1;
  options.joy_button [0] [5] = get_config_int("Misc", "joy1_button_6", 6);
  if (options.joy_button [0] [5] > joy[0].num_buttons)
   options.joy_button [0] [5] = joy[0].num_buttons - 1;

  options.joy_button [1] [0] = get_config_int("Misc", "joy2_button_1", 0);
  if (options.joy_button [1] [0] > joy[0].num_buttons)
   options.joy_button [1] [0] = joy[0].num_buttons - 1;
  options.joy_button [1] [1] = get_config_int("Misc", "joy2_button_2", 1);
  if (options.joy_button [1] [1] > joy[0].num_buttons)
   options.joy_button [1] [1] = joy[0].num_buttons - 1;
  options.joy_button [1] [2] = get_config_int("Misc", "joy2_button_3", 2);
  if (options.joy_button [1] [2] > joy[0].num_buttons)
   options.joy_button [1] [2] = joy[0].num_buttons - 1;
  options.joy_button [1] [3] = get_config_int("Misc", "joy2_button_4", 4);
  if (options.joy_button [1] [3] > joy[0].num_buttons)
   options.joy_button [1] [3] = joy[0].num_buttons - 1;
  options.joy_button [1] [4] = get_config_int("Misc", "joy2_button_5", 5);
  if (options.joy_button [1] [4] > joy[0].num_buttons)
   options.joy_button [1] [4] = joy[0].num_buttons - 1;
  options.joy_button [1] [5] = get_config_int("Misc", "joy2_button_6", 6);
  if (options.joy_button [1] [5] > joy[0].num_buttons)
   options.joy_button [1] [5] = joy[0].num_buttons - 1;
 }

 ticked = 0;

 arena.players = 1;
// NOTE: it's assumed in a few places that if there's just one player, it's player[0].


}
Esempio n. 8
0
TJOYSTICK_EVENT test_joystick(){

TJOYSTICK_EVENT result;
result = no_pressing;

uint8_t j_status;
j_status = get_joystick_status();

switch(j_status)  //проверяем, что нажато
	{
	
		case UP_KEY_MASK: 
			{
				if(joystick_key_pressing_duration.key_up>= SHORT_DURATION)
				{
					result=key_up_pressing;
             		joystick_key_pressing_duration.key_up    =0;
                	joystick_key_pressing_duration.key_up_inc=0;
				} 
				else
				{
					joystick_key_pressing_duration.key_up += joystick_key_pressing_duration.key_up_inc;
					result = joystick_event;
				}
				
				
			}
		break;
		
		case RIGHT_KEY_MASK: 
			{
			
				if(joystick_key_pressing_duration.key_right>= SHORT_DURATION)
				{
					result=key_right_pressing;
             		joystick_key_pressing_duration.key_right    =0;
                	joystick_key_pressing_duration.key_right_inc=0;
				} 
				else
				{
					joystick_key_pressing_duration.key_right += joystick_key_pressing_duration.key_right_inc;
					result = joystick_event;
				}			
			
			}
		break;
	
		case DOWN_KEY_MASK: 
			{
				if(joystick_key_pressing_duration.key_down>= SHORT_DURATION)
				{
					result=key_down_pressing;
             		joystick_key_pressing_duration.key_down    =0;
                	joystick_key_pressing_duration.key_down_inc=0;
				} 
				else
				{
					joystick_key_pressing_duration.key_down += joystick_key_pressing_duration.key_down_inc;
					result = joystick_event;
				}						


			}
		break;

		case LEFT_KEY_MASK: 
			{
				if(joystick_key_pressing_duration.key_left>= SHORT_DURATION)
				{
					result=key_left_pressing;
             		joystick_key_pressing_duration.key_left    =0;
                	joystick_key_pressing_duration.key_left_inc=0;
				} 
				else
				{
					joystick_key_pressing_duration.key_left += joystick_key_pressing_duration.key_left_inc;
					result = joystick_event;
				}						
			
			}
		break;
		case CENTRAL_KEY_MASK: 
			{
				if(joystick_key_pressing_duration.key_central>= SHORT_DURATION)
				{
					result=key_central_pressing;
             		joystick_key_pressing_duration.key_central    =0;
                	joystick_key_pressing_duration.key_central_inc=0;
				} 
				else
				{
					joystick_key_pressing_duration.key_central += joystick_key_pressing_duration.key_central_inc;
					result = joystick_event;
				}						
			
			}
		break;

		case 0:
		{
			init_joystick();
		}
		break;
		default:
		{
			joystick_key_pressing_duration.key_up=0;
			joystick_key_pressing_duration.key_up_inc=0;
			joystick_key_pressing_duration.key_right=0;
			joystick_key_pressing_duration.key_right_inc=0;
			joystick_key_pressing_duration.key_down=0;
			joystick_key_pressing_duration.key_down_inc=0;
			joystick_key_pressing_duration.key_left=0;
			joystick_key_pressing_duration.key_left_inc=0;
			joystick_key_pressing_duration.key_central=0;
			joystick_key_pressing_duration.key_central_inc=0;
		} 
	
	}

return result;
} 
Esempio n. 9
0
void main_init() {

    int i;
    float starting_speed = 0.0;
    init_robot();
    flag = 0;
    robot_state = malloc(sizeof (float) *3);

    for (i = 0; i < LEN_PIC_BUFFER; i++) {
        set_vel_2_array(pic_buffer[i], starting_speed, starting_speed);
    }

    write(pic_fd, pic_message_reset_steps_acc, PACKET_TIMING_LENGTH + 1);
    tcflush(pic_fd, TCOFLUSH);
    sync();
    steps_anomaly = 0;

#ifdef TEST_KALMAN
float v=0;
float w=0;
set_robot_speed(&v,&w);
#endif

#ifdef OB_AV
	init_probstavoid_module();
#endif

#ifdef CARTESIAN_REGULATOR
	viapoints[0][0]=38;
	viapoints[0][1]=119;
	viapoints[0][2]=0;

	viapoints[1][0]=98;
	viapoints[1][1]=161;
	viapoints[1][2]=0;


	viapoints[2][0]=187;
	viapoints[2][1]=179;
	viapoints[2][2]=0;

	viapoints[3][0]=158;
	viapoints[3][1]=238;
	viapoints[3][2]=0;

	viapoints[4][0]=187;
	viapoints[4][1]=268;
	viapoints[4][2]=0;
	curr_via=0;
	via_done=0;

#endif

#ifdef HOKUYO
	init_urg_laser(&urg,ON_DEMAND);
#endif

#ifdef JOYSTICK
	init_joystick();
#endif
	
#ifdef EKF_LOC	
	load_map("ekf_map.txt");
        init_ekf();

#ifdef HOKUYO_SENSOR
    for (i=0; i< NUM_SENS; i++){
        ANGLE_IDX[i]=urg_rad2index(urg,ANGLE_H[i]);
        printf("angle: %f   \tidx: %d\n",ANGLE_H[i],urg_rad2index(urg,ANGLE_H[i]));
    }
#endif
	
        xpost.x=50;
	xpost.y=45;
	xpost.th=M_PI/2;	
	
	xpred.x=0;
	xpred.y=0;
	xpred.th=0;
	
#endif	
	
}
Esempio n. 10
0
void initialize(void) {
  init_joystick();
  init_timer0();
  init_stepmotor();
}
Esempio n. 11
0
int main( int argc, char **argv ) 
{
    /* Print copyright notice */

    fprintf( stderr, 
         "Tux Rider World Challenge -- http://www.barlow-server.com\n"
         "a fork from:\n"
         "Tux Racer " VERSION " -- a Sunspire Studios Production "
	     "(http://www.sunspirestudios.com)\n"
	     "(c) 1999-2000 Jasmin F. Patry "
	     "<*****@*****.**>\n"
	     "\"Tux Racer\" is a trademark of Jasmin F. Patry\n"
	     "Tux Rider World Challenge comes with ABSOLUTELY NO WARRANTY. "
	     "This is free software,\nand you are welcome to redistribute "
	     "it under certain conditions.\n"
	     "See http://www.gnu.org/copyleft/gpl.html for details.\n\n" );

    /* Init the game clock */
    g_game.secs_since_start = 0;

    /* Seed the random number generator */
    srand( time(NULL) );


    /*
     * Set up the game configuration
     */

    /* Don't support multiplayer, yet... */
    g_game.num_players = 2;

    /* Create a Tcl interpreter */
    g_game.tcl_interp = Tcl_CreateInterp();

    if ( g_game.tcl_interp == NULL ) {
	handle_error( 1, "cannot create Tcl interpreter" ); 
    }

    /* Setup the configuration variables and read the ~/.tuxracer/options file */
    init_game_configuration();
    read_config_file();

    /* Set up the debugging modes */
    init_debug();

    /* Setup diagnostic log if requested */
    if ( getparam_write_diagnostic_log() ) {
	setup_diagnostic_log();
    }

    /*
     * Setup Tcl stdout and stderr channels to point to C stdout and stderr 
     * streams
     */
    setup_tcl_std_channels();


    /* 
     * Initialize rendering context, create window
     */
    winsys_init( &argc, argv, WINDOW_TITLE, WINDOW_TITLE );


    /* Ingore key-repeat messages */
    winsys_enable_key_repeat(0);


    /* Set up a function to clean up when program exits */
    winsys_atexit( cleanup );

    /* 
     * Initial OpenGL settings 
     */
    glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

    init_opengl_extensions();

    /* Print OpenGL debugging information if requested */
    if ( debug_mode_is_active( DEBUG_GL_INFO ) ) {
	print_debug( DEBUG_GL_INFO, 
		     "OpenGL information:" );
	print_gl_info();
    }


    /* 
     * Load the game data and initialize game state
     */
    register_game_config_callbacks( g_game.tcl_interp );
    register_course_load_tcl_callbacks( g_game.tcl_interp );
    register_key_frame_callbacks( g_game.tcl_interp );
    register_fog_callbacks( g_game.tcl_interp );
    register_course_light_callbacks( g_game.tcl_interp );
    register_particle_callbacks( g_game.tcl_interp );
    register_texture_callbacks( g_game.tcl_interp );
    register_font_callbacks( g_game.tcl_interp );
    register_sound_tcl_callbacks( g_game.tcl_interp );
    register_sound_data_tcl_callbacks( g_game.tcl_interp );
    register_course_manager_callbacks( g_game.tcl_interp );


    init_saved_games();
    load_tux();
    init_textures();
    init_fonts();
    init_audio_data();
    init_audio();
    init_ui_manager();
    init_course_manager();
    init_joystick();

    /* Read the tuxracer_init.tcl file */
    read_game_init_script();

    /* Need to set up an initial view position for select_course 
       (quadtree simplification)
    */
    
    //Player 0 = classic mode player ; Player 1 = Speed Only Mode Player
    
    g_game.player[0].view.pos = make_point( 0., 0., 0. );
    g_game.player[1].view.pos = make_point( 0., 0., 0. );
    

    /* Placeholder name until we give players way to enter name */
    g_game.player[0].name = "noname";
    g_game.player[1].name = "nonameSpeedOnly";
   

    init_preview();

    splash_screen_register();
    intro_register();
    racing_register();
    game_over_register();
    paused_register();
    reset_register();
    game_type_select_register();
    racing_mode_select_register();
    event_select_register();
    race_select_register();
    credits_register();
    loading_register();

    g_game.mode = NO_MODE;
    set_game_mode( SPLASH );

    g_game.difficulty = DIFFICULTY_LEVEL_NORMAL;

    init_keyboard();
    

    winsys_show_cursor( False );

    /* We use this to "prime" the GLUT loop */
    winsys_set_idle_func( main_loop );

    
    /* 
     * ...and off we go!
     */
    winsys_process_events();

    return 0;
} 
Esempio n. 12
0
void real_main (int argc, char **argv)
{
#ifdef USE_SDL
    SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK 
#if !defined(NO_SOUND) && !defined(GP2X)
 			| SDL_INIT_AUDIO
#endif
	);
#endif
	getcwd(launchDir,250);
    /* PocketUAE prefs */
    default_prefs_uae (&currprefs);
    default_prefs();
#ifdef GP2X
    gp2x_init(argc, argv);
#endif
		// Set everthing to default and clear HD settings
		SetDefaultMenuSettings(1);
    loadconfig (1);

    if (! graphics_setup ()) {
		exit (1);
    }

    rtarea_init ();

	hardfile_install();

    if (! setup_sound ()) {
		write_log ("Sound driver unavailable: Sound output disabled\n");
		produce_sound = 0;
    }
    init_joystick ();

	int err = gui_init ();
	if (err == -1) {
	    write_log ("Failed to initialize the GUI\n");
	} else if (err == -2) {
	    exit (0);
	}
    if (sound_available && produce_sound > 1 && ! init_audio ()) {
		write_log ("Sound driver unavailable: Sound output disabled\n");
		produce_sound = 0;
    }

    /* Install resident module to get 8MB chipmem, if requested */
    rtarea_setup ();

    keybuf_init (); /* Must come after init_joystick */

#ifdef USE_AUTOCONFIG
    expansion_init ();
#endif

    memory_init ();

    filesys_install (); 
    native2amiga_install ();

    custom_init (); /* Must come after memory_init */
    DISK_init ();

    m68k_init(0);
    gui_update ();

#ifdef GP2X
    switch_to_hw_sdl(1);
#endif
	{
		start_program ();
	}
    leave_program ();
}
Esempio n. 13
0
void Sub::init_ardupilot()
{
    if (!hal.gpio->usb_connected()) {
        // USB is not connected, this means UART0 may be a Xbee, with
        // its darned bricking problem. We can't write to it for at
        // least one second after powering up. Simplest solution for
        // now is to delay for 1 second. Something more elegant may be
        // added later
        hal.scheduler->delay(1000);
    }

    // initialise serial port
    serial_manager.init_console();

    cliSerial->printf("\n\nInit " FIRMWARE_STRING
                      "\n\nFree RAM: %u\n",
                      (unsigned)hal.util->available_memory());

    //
    // Report firmware version code expect on console (check of actual EEPROM format version is done in load_parameters function)
    //
    report_version();

    // load parameters from EEPROM
    load_parameters();

    BoardConfig.init();

    // initialise serial port
    serial_manager.init();

    // init cargo gripper
#if GRIPPER_ENABLED == ENABLED
    g2.gripper.init();
#endif

    // initialise notify system
    notify.init(true);

    // initialise battery monitor
    battery.init();

    barometer.init();

    celsius.init();

    // Register the mavlink service callback. This will run
    // anytime there are more than 5ms remaining in a call to
    // hal.scheduler->delay.
    hal.scheduler->register_delay_callback(mavlink_delay_cb_static, 5);

    // we start by assuming USB connected, as we initialed the serial
    // port with SERIAL0_BAUD. check_usb_mux() fixes this if need be.
    ap.usb_connected = true;
    check_usb_mux();

    // setup telem slots with serial ports
    for (uint8_t i = 0; i < MAVLINK_COMM_NUM_BUFFERS; i++) {
        gcs_chan[i].setup_uart(serial_manager, AP_SerialManager::SerialProtocol_MAVLink, i);
    }

    // identify ourselves correctly with the ground station
    mavlink_system.sysid = g.sysid_this_mav;

#if LOGGING_ENABLED == ENABLED
    log_init();
#endif

    gcs().set_dataflash(&DataFlash);

    init_rc_in();               // sets up rc channels from radio
    init_rc_out();              // sets up motors and output to escs
    init_joystick();            // joystick initialization

    // initialise which outputs Servo and Relay events can use
    ServoRelayEvents.set_channel_mask(~motors.get_motor_mask());

    relay.init();

    /*
     *  setup the 'main loop is dead' check. Note that this relies on
     *  the RC library being initialised.
     */
    hal.scheduler->register_timer_failsafe(failsafe_check_static, 1000);

    // Do GPS init
    gps.init(&DataFlash, serial_manager);

    if (g.compass_enabled) {
        init_compass();
    }

#if OPTFLOW == ENABLED
    // make optflow available to AHRS
    ahrs.set_optflow(&optflow);
#endif

    // init Location class
    Location_Class::set_ahrs(&ahrs);
#if AP_TERRAIN_AVAILABLE && AC_TERRAIN
    Location_Class::set_terrain(&terrain);
    wp_nav.set_terrain(&terrain);
#endif

#if AVOIDANCE_ENABLED == ENABLED
    wp_nav.set_avoidance(&avoid);
#endif

    pos_control.set_dt(MAIN_LOOP_SECONDS);

    // init the optical flow sensor
    init_optflow();

#if MOUNT == ENABLED
    // initialise camera mount
    camera_mount.init(&DataFlash, serial_manager);
#endif

#ifdef USERHOOK_INIT
    USERHOOK_INIT
#endif

#if CLI_ENABLED == ENABLED
    if (g.cli_enabled) {
        const char *msg = "\nPress ENTER 3 times to start interactive setup\n";
        cliSerial->println(msg);
        if (gcs_chan[1].initialised && (gcs_chan[1].get_uart() != NULL)) {
            gcs_chan[1].get_uart()->println(msg);
        }
        if (num_gcs > 2 && gcs_chan[2].initialised && (gcs_chan[2].get_uart() != NULL)) {
            gcs_chan[2].get_uart()->println(msg);
        }
    }
#endif // CLI_ENABLED

#if HIL_MODE != HIL_MODE_DISABLED
    while (barometer.get_last_update() == 0) {
        // the barometer begins updating when we get the first
        // HIL_STATE message
        gcs_send_text(MAV_SEVERITY_WARNING, "Waiting for first HIL_STATE message");
        hal.scheduler->delay(1000);
    }

    // set INS to HIL mode
    ins.set_hil_mode();
#endif

    // read Baro pressure at ground
    //-----------------------------
    init_barometer(false);
    barometer.update();

    for (uint8_t i = 0; i < barometer.num_instances(); i++) {
        if (barometer.get_type(i) == AP_Baro::BARO_TYPE_WATER && barometer.healthy(i)) {
            barometer.set_primary_baro(i);
            ap.depth_sensor_present = true;
            break;
        }
    }

    if (!ap.depth_sensor_present) {
        // We only have onboard baro
        // No external underwater depth sensor detected
        barometer.set_primary_baro(0);
        EKF2.set_baro_alt_noise(10.0f); // Readings won't correspond with rest of INS
        EKF3.set_baro_alt_noise(10.0f);
    } else {
        EKF2.set_baro_alt_noise(0.1f);
        EKF3.set_baro_alt_noise(0.1f);
    }

    leak_detector.init();

    // backwards compatibility
    if (attitude_control.get_accel_yaw_max() < 110000.0f) {
        attitude_control.save_accel_yaw_max(110000.0f);
    }

    last_pilot_heading = ahrs.yaw_sensor;

    // initialise rangefinder
#if RANGEFINDER_ENABLED == ENABLED
    init_rangefinder();
#endif

    // initialise AP_RPM library
#if RPM_ENABLED == ENABLED
    rpm_sensor.init();
#endif

    // initialise mission library
    mission.init();

    startup_INS_ground();

    // we don't want writes to the serial port to cause us to pause
    // mid-flight, so set the serial ports non-blocking once we are
    // ready to fly
    serial_manager.set_blocking_writes_all(false);

    // enable CPU failsafe
    failsafe_enable();

    ins.set_raw_logging(should_log(MASK_LOG_IMU_RAW));
    ins.set_dataflash(&DataFlash);

    // init vehicle capabilties
    init_capabilities();

    cliSerial->print("\nReady to FLY ");

    // flag that initialisation has completed
    ap.initialised = true;
}
Esempio n. 14
0
/*
Self-explanatory.
*/
void init_at_startup(void)
{

   LOCK_FUNCTION (framecount);
   LOCK_FUNCTION (tickover);
   LOCK_VARIABLE (ticked);
   LOCK_VARIABLE (frames_per_second);
   LOCK_VARIABLE (framecounter);
   LOCK_VARIABLE (turns_per_second);
   LOCK_VARIABLE (turncounter);

   install_int (framecount, 1000);
   install_int (tickover, 20);

   set_color_depth(8);

   int randseed = get_config_int("Misc", "Seed", 0);
   srand(randseed);

   options.windowed = get_config_int("Misc", "Windowed", 0);


 int windowed;
 switch(options.windowed)
 {
    default:
     case 1: windowed = GFX_AUTODETECT_WINDOWED; break;
     case 0: windowed = GFX_AUTODETECT_FULLSCREEN; break;
 }

//   windowed  = GFX_AUTODETECT_WINDOWED;
//   windowed = GFX_AUTODETECT_FULLSCREEN;

//   if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) != 0)
   if (set_gfx_mode(windowed, 640, 480, 0, 0) != 0)
   {
      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
      allegro_message("Unable to set 640x480 display mode\n%s\n", allegro_error);
      exit(1);
   }

 init_trig();

 prepare_display();
 init_sound();
/*
 player[0].ckey [CKEY_UP] = KEY_UP;
 player[0].ckey [CKEY_DOWN] = KEY_DOWN;
 player[0].ckey [CKEY_LEFT] = KEY_LEFT;
 player[0].ckey [CKEY_RIGHT] = KEY_RIGHT;
 player[0].ckey [CKEY_FIRE1] = KEY_Z;
 player[0].ckey [CKEY_FIRE2] = KEY_X;
 player[0].ckey [CKEY_FIRE3] = KEY_C;
*/

 player[0].ckey [CKEY_UP] = get_config_int("Misc", "key_up", KEY_UP);
 player[0].ckey [CKEY_DOWN] = get_config_int("Misc", "key_down", KEY_DOWN);
 player[0].ckey [CKEY_LEFT] = get_config_int("Misc", "key_left", KEY_LEFT);
 player[0].ckey [CKEY_RIGHT] = get_config_int("Misc", "key_right", KEY_RIGHT);
 player[0].ckey [CKEY_FIRE1] = get_config_int("Misc", "key_fire1", KEY_Z);
 player[0].ckey [CKEY_FIRE2] = get_config_int("Misc", "key_fire2", KEY_X);

 options.joy_stick = get_config_int("Misc", "joy_stick", 0);

 options.joy_sensitivity = get_config_int("Misc", "joy_sensitivity", 70);
 options.init_joystick = get_config_int("Misc", "joy_init", 1);
 options.joystick = 0;
 options.key_or_joy = 0; // don't put in initfile!

 options.sfx_volume = get_config_int("Misc", "sfx_volume", 70);
 options.ambience_volume = get_config_int("Misc", "ambience_volume", 100);
 options.run_vsync = get_config_int("Misc", "run_vsync", 0);

// set_config_int("Misc", "Tourist", 3);
// set_config_int("Misc", "joy_stick", 0);

 if (options.init_joystick)
  init_joystick();

 if (options.joystick == 1) // set in init_joystick
 {
  options.joy_button [0] = get_config_int("Misc", "joy_button_1", 0);
  if (options.joy_button [0] > joy[0].num_buttons)
   options.joy_button [0] = joy[0].num_buttons - 1;
  options.joy_button [1] = get_config_int("Misc", "joy_button_2", 1);
  if (options.joy_button [1] > joy[0].num_buttons)
   options.joy_button [1] = joy[0].num_buttons - 1;
  options.joy_button [2] = get_config_int("Misc", "joy_button_engine", 3);
  if (options.joy_button [2] > joy[0].num_buttons)
   options.joy_button [2] = joy[0].num_buttons - 1;
  options.joy_button [3] = get_config_int("Misc", "joy_button_brake", 2);
  if (options.joy_button [3] > joy[0].num_buttons)
   options.joy_button [3] = joy[0].num_buttons - 1;
 }

 ticked = 0;


}
Esempio n. 15
0
void real_main (int argc, char **argv)
{
	int numb;
	char pattern[100];
	char txt[100];
#ifdef USE_SDL
    SDL_Init (SDL_INIT_VIDEO | SDL_INIT_JOYSTICK 
#if !defined(NO_SOUND) && !defined(GP2X)
 			| SDL_INIT_AUDIO
#endif
	);
#endif
  // Initialize timebase
  g_uae_epoch = read_processor_time();
  syncbase = 1000000; // Microseconds

	//------------------------------------------
	//just safe the game conf file for later use
	//------------------------------------------
	if (argc > 1)
	{
		if (strlen(argv[1]) < 255)
		{
			strcpy(uae4all_game_conf_file0, argv[1]);

			strcpy(uae4all_game_conf_file1, argv[1]);
			strcpy(uae4all_game_conf_file2, argv[1]);
			strcpy(uae4all_game_conf_file3, argv[1]);
			strcpy(uae4all_game_conf_file4, argv[1]);
			strcpy(uae4all_game_conf_file5, argv[1]);
			strcpy(uae4all_game_conf_file6, argv[1]);
			strcpy(uae4all_game_conf_file7, argv[1]);
			getNumber(uae4all_game_conf_file0, "disk 1 of %", &numb);

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file1, pattern, '2');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file2, pattern, '3');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file3, pattern, '4');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file4, pattern, '5');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file5, pattern, '6');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file6, pattern, '7');

			strcpy(pattern, "disk %");
			sprintf(txt, " of %d", numb);
			strcat(pattern, txt);
		    replaceNumber(uae4all_game_conf_file7, pattern, '8');

		}
	}

	getcwd(launchDir,250);
    /* PocketUAE prefs */
    default_prefs_uae (&currprefs);
    default_prefs();
#ifdef GP2X
    gp2x_init(argc, argv);
#endif
		// Set everthing to default and clear HD settings
		SetDefaultMenuSettings(1);
    loadconfig (1);

    if (! graphics_setup ()) {
		exit (1);
    }

    rtarea_init ();

	hardfile_install();

    if (! setup_sound ()) {
		write_log ("Sound driver unavailable: Sound output disabled\n");
		produce_sound = 0;
    }
    init_joystick ();

	int err = gui_init ();
	if (err == -1) {
	    write_log ("Failed to initialize the GUI\n");
	} else if (err == -2) {
	    exit (0);
	}
    if (sound_available && produce_sound > 1 && ! init_audio ()) {
		write_log ("Sound driver unavailable: Sound output disabled\n");
		produce_sound = 0;
    }

    /* Install resident module to get 8MB chipmem, if requested */
    rtarea_setup ();

    keybuf_init (); /* Must come after init_joystick */

#ifdef USE_AUTOCONFIG
    expansion_init ();
#endif

    memory_init ();

    filesys_install (); 
    native2amiga_install ();

    custom_init (); /* Must come after memory_init */
    DISK_init ();

    m68k_init(0);
    gui_update ();

#ifdef GP2X
    switch_to_hw_sdl(1);
#endif
	{
		start_program ();
	}
    leave_program ();
}