Пример #1
0
int XNextEvent(Display *d, XEvent *e)
{
	static int (*real_XNextEvent)(Display *, XEvent *);
	if (!real_XNextEvent)
		real_XNextEvent = dlsym(RTLD_NEXT, "XNextEvent");
	int r = real_XNextEvent(d, e);
	if (!e)
		return r;
	switch (e->type) {
		case ButtonPress:
			button_press(e->xbutton.window, e->xbutton.x, e->xbutton.y);
			break;
		case ConfigureNotify:
			resize_window(e->xconfigure.window, e->xconfigure.width, e->xconfigure.height);
			break;
		case CreateNotify:
			resize_window(e->xcreatewindow.window, e->xcreatewindow.width, e->xcreatewindow.height);
			break;
		case ConfigureRequest:
			resize_window(e->xconfigure.window, e->xconfigure.width, e->xconfigure.height);
			break;
		case ResizeRequest:
			resize_window(e->xresizerequest.window, e->xresizerequest.width, e->xresizerequest.height);
			break;
	}
	return r;
}
Пример #2
0
void main()
{
    //initialize button pins
    ADCON1=0x07;
    TRISB=0xFC;
    TRISC=0x7F;
    SPI_init();               //initialize MSSP for SPI comm
    while(1)
    {
        button_press();
        SPI_transmit(tx_data);
    }
}
Пример #3
0
static void * avr_run_thread(void * oaram)
{
	int b_press = do_button_press;
	
	while (1) {
		avr_run(avr);
		if (do_button_press != b_press) {
			b_press = do_button_press;
			printf("Button pressed\n");
			button_press(&button, 1000000);
		}
	}
}
Пример #4
0
void* viewport_loop(void *ptr)
{
	viewport_t *viewport = (viewport_t *)ptr;
	SDL_Event event;

//printf("viewport_loop 1\n");
	while(!viewport->done)
	{
		int result = !SDL_WaitEvent(&event);
//printf("viewport_loop 2\n");

		if(result) viewport->done = 1;

		switch(event.type)
		{
			case SDL_KEYDOWN:
			{
				stop_status();
				viewport_set_done(viewport);
				break;
			}

       		case SDL_MOUSEMOTION:
			{
				SDL_MouseMotionEvent *mouse_event = (SDL_MouseMotionEvent*)&event;
				viewport->cursor_x = mouse_event->x;
				viewport->cursor_y = mouse_event->y;
				cursor_motion(viewport);
				break;
			}

       		case SDL_MOUSEBUTTONDOWN:
			{
				SDL_MouseButtonEvent *mouse_event = (SDL_MouseButtonEvent*)&event;
				viewport->which_button = mouse_event->button - 1;
				viewport->button_down = 1;
				button_press(viewport);
				break;
			}

       		case SDL_MOUSEBUTTONUP:
				viewport->button_down = 0;
				break;

			case SDL_QUIT:
				viewport->done = 1;
				break;
		}
	}
}
Пример #5
0
void got_packet(u_char *args, const struct pcap_pkthdr *header,
	    const u_char *packet)
{
	uintmax_t nts = NULL;
	if (ts == NULL) {
		ts = (uintmax_t)time(NULL);
	}
	else {
		nts = (uintmax_t)time(NULL);
	}
	if (nts == NULL) {
		button_press();
		printf("Jacked a packet with length of [%d]\n", header->len);
		printf("Button pressed\n");
		return;
	}
	if ( nts > ts + 5) {
		button_press();
		printf("Jacked a packet with length of [%d]\n", header->len);
		printf("Button pressed\n");
		ts = nts;
	}
}
Пример #6
0
static void * avr_run_thread(void * ignore)
{
	int b_press[3] = {0};
	
	while (1) {
		avr_run(avr);

		for (int i = 0; i < 3; i++) {
			if (do_button_press[i] != b_press[i]) {
				b_press[i] = do_button_press[i];
				printf("Button pressed %d\n", i);
				button_press(&button[i], 100000);
			}
		}
	}
	return NULL;
}
Пример #7
0
void poll_sdl_events(void) {
	SDL_Event event;

	while (SDL_PollEvent(&event)) {
		switch (event.type) {
			case SDL_MOUSEMOTION:
				break;
			case SDL_MOUSEBUTTONDOWN:
				break;
			case SDL_MOUSEBUTTONUP:
				button_press(&(event.button));
				break;
			case SDL_QUIT:
				should_quit = 1;
				break;
		}
	}
}
Пример #8
0
void SWNUI::mode_gesture()
{
    switch(state)
    {
        default:
            state = INIT;
        break;
        
        case INIT:
                button_enableInterrupt();
                sleep();
                delay(CHANGE_MODE_TIME);
                changeMode_management();
                if(mode == M_GESTURE)
                {
                    state = SAMPLE;
                    button_disableInterrupt();
                }
        break;

        case SAMPLE:
            refreshGestureArrays();
            while(button_press())
            {
                samples = adxl_sampling();
                gestures();
                delay(T_SAMPLE);
            }
            state = SEND;
        break;

        case SEND:
            gestureRecognition();
            gestureSend();
            state = INIT;
        break;
    }
}
Пример #9
0
void* viewport_loop(void *ptr)
{
	viewport_t *viewport = (viewport_t *)ptr;
	SDL_Event event;

//printf("viewport_loop 1\n");
	while(!viewport->done)
	{
		int result = !SDL_WaitEvent(&event);
//printf("viewport_loop 2\n");

		if(result) viewport->done = 1;

		switch(event.type)
		{
			case SDL_KEYDOWN:
			{
				viewport->key_pressed = event.key.keysym;
				keypress_event(viewport);
				break;
			}

       		case SDL_MOUSEMOTION:
			{
				SDL_Event compress_event;
				while(SDL_PollEvent(&compress_event))
				{
					if(compress_event.type != SDL_MOUSEMOTION)
					{
						SDL_PushEvent(&compress_event);
						break;
					}
					event = compress_event;
				}

				SDL_MouseMotionEvent *mouse_event = (SDL_MouseMotionEvent*)&event;
				viewport->cursor_x = mouse_event->x;
				viewport->cursor_y = mouse_event->y;
				cursor_motion(viewport);
				break;
			}

       		case SDL_MOUSEBUTTONDOWN:
			{
				SDL_MouseButtonEvent *mouse_event = (SDL_MouseButtonEvent*)&event;
				viewport->which_button = mouse_event->button - 1;
				viewport->button_down = 1;
				button_press(viewport);
				break;
			}

       		case SDL_MOUSEBUTTONUP:
				viewport->button_down = 0;
				break;

			case SDL_QUIT:
				viewport->done = 1;
				break;
		}
	}
}
Пример #10
0
void showlogo()
{
	struct bitfileheader
	{
		int  bfType;
		long bfSize;
		int  bfReserved1;
		int  bfReserved2;
		long bfOffBits;
		long biSize;
		long biWidth;
		long biHeight;
		int  biPlanes;
		int  biBitCount;
		long biCompression;
		long biSizeImage;
		long biXPelsPerMeter;
		long biYPelsPerMeter;
		long biClrUsed;
		long byClrImportant;
	};

	int xmax = getmaxx();
	int ymax = getmaxy();
	bitfileheader testing;
	palettetype pal;
	getpalette(&pal);
	int i, j;
	char blue, green, red, pix1, pix2, pixel, alpha;
	mouse_data mouse;

	cleardevice();

	if(!init_mouse())
	{
		closegraph();
		cout << "Mouse couldn't be initialised";
	}

	hide_mouse();

	fstream bitmap("logo.saq", ios::in);

	bitmap.read((char*)&testing, sizeof testing);

	for (i = 0; i< pal.size; i++)
	{
		bitmap.read(&blue,1);
		bitmap.read(&green,1);
		bitmap.read(&red,1);
		bitmap.read(&alpha,1);
//		setrgbpalette(pal.colors[i],(int)red,(int)green,(int)blue);
	}

	for (i = 1; i<= testing.biHeight; i++)
		for (j = 1; j <= testing.biWidth; j+=2)
		{
			bitmap.read(&pixel, 1);
			pix1 = pixel & 0xF0;
			pix1 >>= 4;
			pix2 = pixel & 0x0F;
			putpixel(j,   testing.biHeight - i,pix1);
			putpixel(j+1, testing.biHeight - i,pix2);
		}

	show_mouse();
	do
	{
		read_mouse(&mouse);
	}while(!kbhit() || !button_press(LEFT_BUTTON, &mouse));
		
}
Пример #11
0
/* Function Definitions */
int mainoptions()
{

	//Will draw five buttons each having the following fucntions
	//1. New Game
	//2. Load Game
	//3. Rules
	//4. About
	//5. Quit
	button button[5];

	int xmax = getmaxx();
	int ymax = getmaxy();
	char *text;
	int i;
	unsigned size;
	mouse_data mouse;
	
	cleardevice();
	hide_mouse();
	setfillstyle(SOLID_FILL, LIGHTGRAY);
	bar(0,0,xmax,ymax);

	//Draw the five buttons and store their info
	for(i = 0; i <= 4; i++)
	{
		//Mention the coordinates of the buttons
		button[i].coords[0][0] = xmax / 2 - 100;       // Left
		button[i].coords[0][1] = (i * 30) + 100;      // Top
		button[i].coords[1][0] = xmax / 2 + 100;       // Right
		button[i].coords[1][1] = ((i + 1) * 30) + 99; // Bottom
		
		//Dynamically allocate memory for images of up and down buttons
		size = imagesize(button[i].coords[0][0], button[i].coords[0][1], button[i].coords[1][0], button[i].coords[1][1]);

		button[i].up = (int *)malloc(size);
		if(!button[i].up){
			cout << "Error..";
			getch();
			exit(0);
		}

		button[i].down = (int *)malloc(size);
		if(!button[i].down){
			cout << "Error..";
			getch();
			exit(0);
		}

		//Put the text on button's face
		switch (i)
		{
			case 0:
				text = "Start New Game";
				break;
			case 1:
				text = "Load Game";
				break;
			case 2:
				text = "The Rules";
				break;
			case 3:
				text = "About Ludo Master 2002";
				break;
			case 4:
				text = "Quit";
				break;
		}
		//Draw button and store info
		draw_button(button[i].coords[0][0], button[i].coords[0][1], button[i].coords[1][0], button[i].coords[1][1], LIGHTBLUE, LIGHTCYAN, BLUE, WHITE, text, button[i].up,button[i].down);
	}
	show_mouse();

	//Wait for user's response through mouse
	do
	{
		//When mouse button is pressed see if it is pressed on a button, if yes then suprress that button
		read_mouse(&mouse);

		if (button_press(LEFT_BUTTON, &mouse))
		{
			// See which button user has pressed
			for(int i = 0; i <= 4; i++)
			{

				if ( mouse.x >= button[i].coords[0][0] && mouse.x <= button[i].coords[1][0] && mouse.y >= button[i].coords[0][1] && mouse.y <= button[i].coords[1][1])
				{
					hide_mouse();
					putimage(button[i].coords[0][0], button[i].coords[0][1], button[i].down, 0);
					show_mouse();
					delay(100);
                    hide_mouse();
					putimage(button[i].coords[0][0], button[i].coords[0][1], button[i].up  , 0);
					show_mouse();

					//Delete the memory allocated to buttons' images
                    for(int j = 0; j <= 4; j++)
					{
						free( (void*) button[j].up);
						free( (void*) button[j].down);
					}
 
					//Actions for each button user may click on
					switch (i)
					{
						case 0:
							// Start new game
							new_game_vars();
							return gameoptions();
							break;
						case 1:
							// Load game
							new_game_vars();
							return loadgame();
							break;
						case 2:
							// Rules of Ludo
							return 0;
							break;
						case 3:
							// About the author
							showlogo();
							return 0;
							break;
						case 4:                   	
							// Quit
                            exit(1);
							break;
					}
			   }

			}
		}
	}	while(1); //Infinite loop
}
Пример #12
0
int gameoptions()
{
	int i, j, size;
	int xmax = getmaxx();
	int ymax = getmaxy();
	mouse_data mouse;
	
	button blue[3];
	button green[3];
	button red[3];
	button yellow[3];
	button ok;
	button cancel;

	// Clear previous elements and draw background
	cleardevice();
	hide_mouse();
	setfillstyle(SOLID_FILL, LIGHTGRAY);

	bar(0,0,xmax,ymax);

	settextjustify(CENTER_TEXT, BOTTOM_TEXT);
	setcolor(BLACK);
	outtextxy(xmax/2,20, "Please specify number and types of players");
	

	settextjustify(LEFT_TEXT, TOP_TEXT);
	setcolor(BLACK);
	//Draw block and buttons of green player
	setfillstyle(SOLID_FILL, GREEN);
	bar(xmax/2, 50, xmax/2 + 150, 200);
	outtextxy(xmax/2 + 5, 55, "Green Player:");

	//Draw block and buttons of red player
	setfillstyle(SOLID_FILL, RED);
	bar(xmax/2, 200, xmax/2 + 150, 350);
	outtextxy(xmax/2 + 5, 205, "Red Player");
	
	//Draw block and buttons of blue player
	setfillstyle(SOLID_FILL, BLUE);
	bar(xmax/2 - 150, 50, xmax/2, 200);
	outtextxy(xmax/2 - 145, 55, "Blue Player");
	
	//Draw block and buttons of yellow player
	setfillstyle(SOLID_FILL, YELLOW);
	bar(xmax/2 - 150, 200, xmax/2, 350);
	outtextxy(xmax/2 - 145, 205, "Yellow Player");

	//Assign coordinates and stores images of option buttons
	size = imagesize(0,0,100,30);
	for( i = 0; i <= 2; i++)
	{
		char *text;
		switch (i)
		{
			case 0:
				text = "None";
				break;
			case 1:
				text = "Human";
				break;
			case 2:
				text = "Computer";
				break;
		}
		
		//Set coordinaates for blue player's option buttons and store it as image
		blue[i].coords[0][0] = xmax/2 - 125;
		blue[i].coords[0][1] = 80 + i * 30;
		blue[i].coords[1][0] = xmax/2 - 25;
		blue[i].coords[1][1] = 80 + (i+1)*30;
		
		blue[i].up = (int *)malloc(size) ;
		blue[i].down = (int *)malloc(size) ;
		if(!blue[i].up || !blue[i].down)
		{
			cleardevice();
			closegraph();
			cout << endl << "Either u've run out of memory or memory can't be allocated. Ludo Master 2002 will quit now";
			getch();
			exit(0);
		}

		draw_button(blue[i].coords[0][0], blue[i].coords[0][1], blue[i].coords[1][0], blue[i].coords[1][1], DARKGRAY, LIGHTGRAY, BLACK, WHITE, text, blue[i].up,blue[i].down);
						
		//Set coordinaates for green player's option buttons and store it as image
		green[i].coords[0][0] = xmax/2 + 25;
		green[i].coords[0][1] = 80 + i * 30;
		green[i].coords[1][0] = xmax/2 + 125;
		green[i].coords[1][1] = 80 + (i+1)*30;
		
		green[i].up = blue[i].up;      // Images of buttons are same
		green[i].down = blue[i].down;  // Images of buttons are same
		putimage(green[i].coords[0][0], green[i].coords[0][1], green[i].up,0);
				
		//Set coordinaates for red player's option buttons and store it as image
		red[i].coords[0][0] = xmax/2 + 25;
		red[i].coords[0][1] = 230 + i * 30;
		red[i].coords[1][0] = xmax/2 + 125;
		red[i].coords[1][1] = 230 + (i+1)*30;
		
		red[i].up = blue[i].up;      // Images of buttons are same
		red[i].down = blue[i].down;  // Images of buttons are same
		putimage(red[i].coords[0][0], red[i].coords[0][1], red[i].up, 0);
		
		//Set coordinaates for yellow player's option buttons and store it as image
		yellow[i].coords[0][0] = xmax/2 - 125;
		yellow[i].coords[0][1] = 230 + i * 30;
		yellow[i].coords[1][0] = xmax/2 - 25;
		yellow[i].coords[1][1] = 230 + (i+1)*30;
		
		yellow[i].up = blue[i].up;      // Images of buttons are same
		yellow[i].down = blue[i].down;  // Images of buttons are same
		putimage(yellow[i].coords[0][0], yellow[i].coords[0][1], yellow[i].up,0);
	}
	
	//Draw Ok button
	size = imagesize(0,0,80,20);

	ok.coords[0][0] = xmax/2 - 105;
	ok.coords[0][1] = ymax - 70;
	ok.coords[1][0] = xmax/2 - 25;
	ok.coords[1][1] = ymax - 50;
	ok.up = (int *)malloc(size);
	ok.down = (int *)malloc(size);
	
	if(!ok.up || !ok.down) // Check if memory has been allocated
	{
		cleardevice();
		closegraph();
		cout << endl << "Either u've run out of memory or memory can't be allocated. Ludo Master 2002 will quit now";
		getch();
		exit(0);
	}
	
	draw_button(ok.coords[0][0], ok.coords[0][1], ok.coords[1][0], ok.coords[1][1], LIGHTBLUE, LIGHTCYAN, BLUE, WHITE, "Start", ok.up,ok.down);

	//Draw cancel button
	cancel.coords[0][0] = xmax/2 + 25;
	cancel.coords[0][1] = ymax - 70;
	cancel.coords[1][0] = xmax/2 + 105;
	cancel.coords[1][1] = ymax - 50;
	cancel.up = (int *)malloc(size);
	cancel.down = (int *)malloc(size);
	
	if(!cancel.up || !cancel.down)
	{
		cleardevice();
		closegraph();
		cout << endl << "Either u've run out of memory or memory can't be allocated. Ludo Master 2002 will quit now";
		getch();
		exit(0);
	}
	draw_button(cancel.coords[0][0], cancel.coords[0][1], cancel.coords[1][0], cancel.coords[1][1], LIGHTBLUE, LIGHTCYAN, BLUE, WHITE, "Cancel", cancel.up, cancel.down);

	/* Set default as None option to all players */
	putimage(blue[0].coords[0][0], blue[0].coords[0][1], blue[0].down,0);
	putimage(green[0].coords[0][0], green[0].coords[0][1], green[0].down, 0);
	putimage(red[0].coords[0][0], red[0].coords[0][1], red[0].down,0);
	putimage(yellow[0].coords[0][0], yellow[0].coords[0][1], yellow[0].down,0);
	player[PLR_BLUE].type = TYPE_NONE;
	player[PLR_GREEN].type = TYPE_NONE;
	player[PLR_RED].type = TYPE_NONE;
	player[PLR_YELLOW].type = TYPE_NONE;
	
	show_mouse();

	/* Get user's input through mouse */
	do
	{
		read_mouse(&mouse);
		
		if (button_press(LEFT_BUTTON, &mouse))
		{
			// If blue player's option is pressed:
			if (mouse.x >= blue[0].coords[0][0] && mouse.x <= blue[2].coords[1][0] && mouse.y >= blue[0].coords[0][1] && mouse.y <= blue[2].coords[1][1])
			{
				hide_mouse();
				for (i = 0; i <= 2; i++)
				{
					putimage(blue[i].coords[0][0], blue[i].coords[0][1], blue[i].up, 0);
					if (mouse.x >= blue[i].coords[0][0] && mouse.x <= blue[i].coords[1][0] && mouse.y >= blue[i].coords[0][1] && mouse.y <= blue[i].coords[1][1])
					{
						putimage(blue[i].coords[0][0], blue[i].coords[0][1], blue[i].down, 0);
						player[PLR_BLUE].type = i;						
					}
				}
				show_mouse();
			}

			// If green player's option is pressed:
			if (mouse.x >= green[0].coords[0][0] && mouse.x <= green[2].coords[1][0] && mouse.y >= green[0].coords[0][1] && mouse.y <= green[2].coords[1][1])
			{
				hide_mouse();
				for (i = 0; i <= 2; i++)
				{
					putimage(green[i].coords[0][0], green[i].coords[0][1], green[i].up, 0);
					if (mouse.x >= green[i].coords[0][0] && mouse.x <= green[i].coords[1][0] && mouse.y >= green[i].coords[0][1] && mouse.y <= green[i].coords[1][1])
					{
						putimage(green[i].coords[0][0], green[i].coords[0][1], green[i].down, 0);
						player[PLR_GREEN].type = i;						
					}
				}
				show_mouse();
			}

			// If red player's option is pressed:
			if (mouse.x >= red[0].coords[0][0] && mouse.x <= red[2].coords[1][0] && mouse.y >= red[0].coords[0][1] && mouse.y <= red[2].coords[1][1])
			{
				hide_mouse();
				for (i = 0; i <= 2; i++)
				{
					putimage(red[i].coords[0][0], red[i].coords[0][1], red[i].up, 0);
					if (mouse.x >= red[i].coords[0][0] && mouse.x <= red[i].coords[1][0] && mouse.y >= red[i].coords[0][1] && mouse.y <= red[i].coords[1][1])
					{
						putimage(red[i].coords[0][0], red[i].coords[0][1], red[i].down, 0);
						player[PLR_RED].type = i;						
					}
				}
				show_mouse();
			}

			// If yellow player's option is pressed:
			if (mouse.x >= yellow[0].coords[0][0] && mouse.x <= yellow[2].coords[1][0] && mouse.y >= yellow[0].coords[0][1] && mouse.y <= yellow[2].coords[1][1])
			{
				hide_mouse();
				for (i = 0; i <= 2; i++)
				{
					putimage(yellow[i].coords[0][0], yellow[i].coords[0][1], yellow[i].up, 0);
					if (mouse.x >= yellow[i].coords[0][0] && mouse.x <= yellow[i].coords[1][0] && mouse.y >= yellow[i].coords[0][1] && mouse.y <= yellow[i].coords[1][1])
					{
						putimage(yellow[i].coords[0][0], yellow[i].coords[0][1], yellow[i].down, 0);
						player[PLR_YELLOW].type = i;						
					}
				}
				show_mouse();
			}

			// If Start/OK button is pressed:
			if (mouse.x >= ok.coords[0][0] && mouse.x <= ok.coords[1][0] && mouse.y >= ok.coords[0][1] && mouse.y <= ok.coords[1][1])
			{
				hide_mouse();
				putimage(ok.coords[0][0], ok.coords[0][1], ok.down, 0);
				show_mouse();
				delay(100);
				hide_mouse();
				putimage(ok.coords[0][0], ok.coords[0][1], ok.up, 0);
				show_mouse();
				delay(100);
				
				//Check how many players are playing
				int count = 0;
				for (i = 0; i <= 3; i++)
				{
					if (player[i].type != TYPE_NONE)
						count++;
				}
					
				//If number of players playing is less than 2 then give msg and do nothing
				
				if (count >= 2)
				{		
					// Free the memory allocated to images
					free ((void*) ok.up);
					free ((void*) ok.down);
					free ((void*) cancel.up);
					free ((void*) cancel.down);
					for(i = 0; i <= 3; i++)
					{
						free ((void*) blue[i].up);
						free ((void*) blue[i].down);
						free ((void*) green[i].up);
						free ((void*) green[i].down);
						free ((void*) red[i].up);
						free ((void*) red[i].down);
						free ((void*) yellow[i].up);
						free ((void*) yellow[i].down);
						return 1;
					}
				}
				else
				{
					settextjustify(CENTER_TEXT, CENTER_TEXT);
					setcolor(DARKGRAY);
					outtextxy(xmax/2, ymax - 90, "There should be atleast two players playing to start the game");
				}
			}
			
			// If Cancel button is pressed:	
			if (mouse.x >= cancel.coords[0][0] && mouse.x <= cancel.coords[1][0] && mouse.y >= cancel.coords[0][1] && mouse.y <= cancel.coords[1][1])
			{
				hide_mouse();
				putimage(cancel.coords[0][0], cancel.coords[0][1], cancel.down, 0);
				show_mouse();
				delay(100);
				hide_mouse();
				putimage(cancel.coords[0][0], cancel.coords[0][1], cancel.up, 0);
				show_mouse();
				delay(100);
				
				// Free the memory allocated to images
				free ((void*) ok.up);
				free ((void*) ok.down);
				free ((void*) cancel.up);
				free ((void*) cancel.down);
				for(i = 0; i <= 3; i++)
				{
					free ((void*) blue[i].up);
					free ((void*) blue[i].down);
					free ((void*) green[i].up);
					free ((void*) green[i].down);
					free ((void*) red[i].up);
					free ((void*) red[i].down);
					free ((void*) yellow[i].up);
					free ((void*) yellow[i].down);
				}
				
				return 0;
			}
		}
	}while(1);  //Infinite loop
}
int main(int argc, char *argv[]){
    unsigned char stop, temp;
    unsigned char cmd;
    unsigned char arg1, arg2;
    char arg1buf[4], arg2buf[4];
    packet recievepkt;
    packet sendpkt;


    int fd_joy;			// File Descriptor for joystick
	int temp1;
	struct js_event e;
	temp1 = 0;               // Set first time stamp to zero
	fd_joy = open_joystick();   // /Initalize the joystick
   // printf("fd_joy: %d\n", fd_joy);


    strncpy(device, argv[1], DEVICE_MAX_SIZE);

    //set up serial port
    if((fd = configDevice()) < 2){
        perror("Error opening/configuring device\n");
        return -1;
        }

    menu();

    //set handler for close command
    signal(SIGUSR2, catchClose);
    signal(SIGTERM, catchClose);

    //create timer for ping
    pid = fork();
    if (pid < 0) printf("Error creating ping timer process\n");
    else if(pid == 0){
        //die if parent dies
        prctl(PR_SET_PDEATHSIG, SIGHUP);
        //set alarm for ping timeout
        signal(SIGALRM, sendPing);
        //prime Timeout reset handler
        signal(SIGUSR1, catchTimeoutReset);

        alarm(PING_INTERVAL);

        for(timeouts = 0; timeouts < PING_RETRIES;){
            //spin wheels. exit if ping timeout occurs
        }
        //kill parent process if ping timeout
        printf("Ping timeout. %d unanswered pings\n", timeouts);
        //tell parent to exit
        kill(getppid(), SIGKILL);
        return 1;
    }

    int readcount;
    char zeroflag;


    //main control loop
    for(stop = 0; stop <= 0;){

        //cmd = 'V';
        //arg1 = 0;
        //arg2 = 0;
        /*scanf("%c %s %s%c", &cmd, arg1buf, arg2buf, NULL);        //get command
        //strcpy(arg1buf, "Z");
        arg1 = (unsigned char)atoi(arg1buf);
        arg2 = (unsigned char)atoi(arg2buf);

        if(arg1 == 0){
            arg1 = 1;
        }
        if(arg2 == 0){
            arg2 = 1;
        }*/

        readcount = read (fd_joy, &e, sizeof(e));
		//printf("servo: %d\r", e.time);
        //printf("bytes read from joystick: %d\n", readcount);
		//if(e.time > temp1)
		{
            //printf("Bryan\n");
			if(e.type == 1 && e.value == 1){
                if(e.time > temp1){
                    button_press(e.number);
                    temp1 = e.time;
                    }
				}
			if(e.type == 2 /*&& e.value != 0*/){
			if(!zeroflag){
				axis_press(e.number, e.value);
				}
			//set zeroflag if event input zero
			//necessary to not keep resending packages
			//when in the zero (stopped) position
            zeroflag = (e.value == 0) ? 1 : 0;
            //printf("zeroflag %c\n", zeroflag);
            }
		}

        //while((temp = getchar()) != '\n' && temp != EOF);  //clear buffer
        //printf("CMD: %c ARG1: %c ARG2: %c\n", cmd, arg1, arg2);
        //stop = parseCommand(cmd, arg1, arg2);
    }
    close(fd);
    //tell child to exit
    kill(pid, SIGUSR2);
    t1.join();
    scanf("", NULL);
    return 0;
}