Esempio n. 1
0
/* Display Read/Write status to the LCD that is changed based on a
 signal from the Switch task */
void taskLCD(void* pdata) {
	alt_up_character_lcd_dev * char_lcd_dev;

	// open the Character LCD port
	char_lcd_dev = alt_up_character_lcd_open_dev("/dev/character_lcd_0");
	if (char_lcd_dev == NULL)
		alt_printf("Error: could not open character LCD device\n");
	else
		alt_printf("Opened character LCD device\n");

	while (1) {
		if (OSQPend(SWQ, 0, &err) == SW_WRITE) {
			/* Initialize the character display */
			alt_up_character_lcd_init(char_lcd_dev);
			/* Write "WRITE" in the second row */
			char second_row[] = "WRITE\0";
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, second_row);
		} else {
			alt_up_character_lcd_init(char_lcd_dev);
			/* Write "READ" in the first row */
			alt_up_character_lcd_string(char_lcd_dev, "READ");
		}
		OSTimeDlyHMSM(0, 0, 0, 50);
	}
}
Esempio n. 2
0
File: main.c Progetto: gongal/ARCap
/* Initialize the LCD. */
void lcd_init() {
	lcd = alt_up_character_lcd_open_dev(CHARACTER_LCD_0_NAME);
	if (lcd == NULL) {
		printf("Error: cannot open device %s\n", CHARACTER_LCD_0_NAME);
	} else {
		printf("Opened device %s\n", CHARACTER_LCD_0_NAME);
		alt_up_character_lcd_init(lcd);
	}
}
Esempio n. 3
0
int char_display_init () {
	if (!LCD_initialized) {
		LCD_port = alt_up_character_lcd_open_dev("/dev/character_lcd_0");
		if (LCD_port != NULL) {
			LCD_initialized = 1;
			// clear it
			alt_up_character_lcd_init(LCD_port);
		}
	}
	return LCD_initialized;
}
Esempio n. 4
0
int main(void)
{
	alt_up_character_lcd_dev * char_lcd_dev;
	// open the Character LCD port
	char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0");
	if ( char_lcd_dev == NULL)
		alt_printf ("Error: could not open character LCD device\n");
	else
		alt_printf ("Opened character LCD device\n");

	while(1) {

		while (*key1 == 0) {
			/* Initialize the character display */
			alt_up_character_lcd_init (char_lcd_dev);
			/* Write "Welcome to" in the first row */
			alt_up_character_lcd_string(char_lcd_dev, "EECE 381");
			/* Write "the DE2 board" in the second row */
			char second_row[] = "L2C-17\0";
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, second_row);
			while (*key1 == 0) {}
		}

		while (*key2 == 0) {
			/* Initialize the character display */
			alt_up_character_lcd_init (char_lcd_dev);
			/* Write "Welcome to" in the first row */
			alt_up_character_lcd_string(char_lcd_dev, "TO INFINITY");
			/* Write "the DE2 board" in the second row */
			char second_row[] = "AND BEYOND\0";
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, second_row);
			while (*key2 == 0){}
		}

		while (*key3 == 0) {
			/* Initialize the character display */
			alt_up_character_lcd_init (char_lcd_dev);
			/* Write "Welcome to" in the first row */
			alt_up_character_lcd_string(char_lcd_dev, "FLY");
			/* Write "the DE2 board" in the second row */
			char second_row[] = "YOU FOOLS\0";
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, second_row);
			while (*key3 == 0) {}
		}
	}
}
Esempio n. 5
0
int main(void)
{
alt_up_character_lcd_dev * char_lcd_dev;
// open the Character LCD port
char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0");
if ( char_lcd_dev == NULL)
alt_printf ("Error: could not open character LCD device\n");
else
alt_printf ("Opened character LCD device\n");
/* Initialize the character display */
alt_up_character_lcd_init (char_lcd_dev);
/* Write "Welcome to" in the first row */
alt_up_character_lcd_string(char_lcd_dev, "Welcome to");
/* Write "the DE2 board" in the second row */
char second_row[] = "the DE2 board\0";
alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
alt_up_character_lcd_string(char_lcd_dev, second_row);
}
Esempio n. 6
0
int main(void)
{
	// open the Character LCD port
	char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/LCD");
	/* Initialize the character display */
	alt_up_character_lcd_init(char_lcd_dev);


	// Initially writes the start time of timer to lcd
	write_time_to_buffer(top_row, seconds, minutes, hours, am_pm_mode);
	hex_write_date(month, day, year);
	
	// Initialize the switches
	int * sw_ptr = (int *) SW_BASE;
	int sw_values;
	int oldvalue = 0x00000000;
	
	// Masks for individual switches
	int MASK_17 = 0x00020000;
	int MASK_16 = 0x00010000;
	int MASK_1 = 0x00000002;
	int MASK_0 = 0x00000001;
	
	int is_fast = 0; //use to tell other function if sped up, 0 = slow, 1 = fast
	int clk_modify = 0; //if 0, clock isn't being changed, if 1 clock is being changed
	int alarm_modify = 0; //if 0 alarm isn't being changed, if 1, alarm is being changed
	
	// Initialize the Timers
	init_timer_0(&tenths);
	
	// Tracker to see when the time changes
	int old_tenths = 0;
	
	// Initialize the KEY port
	init_button_pio();
	
	// continually 
	while(1)  {
		// check the state of the context integer updated by various ISR functions	
		// Act accordingly, which means
		
		// Update the switch_values
		sw_values = *(sw_ptr);
		
		//check if sw17 is up and if it is, then speed up the timer
		if((sw_values & MASK_17) == 0x00020000 && oldvalue == 0x00000000){
			speed_up();
			oldvalue = sw_values & MASK_17;
			is_fast = 1;
		}
		//check if sw17 is down and if it is then slow down the timer
		else if ((sw_values & MASK_17) == 0x00000000 && oldvalue == 0x00020000) { 
			slow_down(); 
			oldvalue = sw_values & MASK_17;
			is_fast = 0;
		}
		
		// Allow user to change the time if SW0 is up
		if((sw_values & MASK_0) == 0x00000001){ 
			clk_modify = 1;
		}
		else{ 
			clk_modify = 0;
		}
		
		// Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1
		if(clk_modify == 1 && alarm_modify == 0 && alarm == 0){
			// Handle if a key was pressed
			if (edge_capture) {
				handle_key_press_time();
			}
		}
		
		// Allow user to change the alarm if SW1 is up
		if((sw_values & MASK_1) == 0x00000002){
			alarm_modify = 1;
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, bot_row);
		}
		else{ 
			alarm_modify = 0;
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
			alt_up_character_lcd_string(char_lcd_dev, "                ");
		}
		
		// Buttons increment the hours, minutes, and seconds, respectively to Key3, Key2, and Key1
 		if(alarm_modify == 1 && clk_modify == 0 && alarm == 0){
			// Handle if a key was pressed
			if (edge_capture) {
				handle_key_press_alarm_set();
			}
		}
		
		// Check if alarm should go off yet
		if(hours == alarm_hours && minutes == alarm_minutes && seconds == 0){ 
			alarm = 1; 
			init_timer_1(&half_second);
		}
		
		// While alarm is going off
		if( alarm == 1 ){
			if (half_second % 2) {
				// Turn hex on
				hex_on();
			}
			else {
				// Turn hex off
				hex_off();
			}
			if( edge_capture) {
				handle_key_press_alarm();
			}
		} 
		else { stop_timer_1(); }

		// Check SW16 for "AM_PM" enable or "24" mode enable
		//		If the switch is enabled, then we turn on 24 hour mode
		//		Else we turn on AM / PM Mode
		// TODO: Optimize so that it doesn't assign something every loop cycle. Maybe we could slim it down
		if((sw_values & MASK_16) == MASK_16 ) {
			am_pm_mode = 0;
		}
		else {
			am_pm_mode = 1;
		}
		
		// Update the clock
		if (tenths != old_tenths) {
			// Call the util.h function to update the time
			update_time(top_row, &old_tenths, &tenths, &seconds, &minutes, &hours, &day, &month, &year, am_pm_mode, 0);

			// Write the updated time to the display
			alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0);
			alt_up_character_lcd_string(char_lcd_dev, top_row);
		}
		
	}
	
	return 0;
}
Esempio n. 7
0
/*
 * Main Game Loop
 */
int main()
{
	// Use the name of your pixel buffer DMA core
	pixel_buffer =alt_up_pixel_buffer_dma_open_dev("/dev/pixel_buffer_dma_0");

	initVGA();
	usleep(5000000);
	ps2 = alt_up_ps2_open_dev("/dev/ps2_0");
	ps2->timeout = 2000000;
		alt_up_ps2_clear_fifo(ps2);
		alt_up_ps2_init(ps2);

		unsigned char byte1;
		while(alt_up_ps2_read_data_byte(ps2, &byte1)!=0);

	char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/character_lcd_0");
	alt_up_character_lcd_init (char_lcd_dev);

	char_buffer  = alt_up_char_buffer_open_dev("/dev/char_drawer");
	alt_up_char_buffer_init(char_buffer);

	alt_up_sd_card_dev *device_reference = NULL;
	struct Env* p = initEnv();
	initGameInfo();

	struct Collidable* collisionChecker = initCollidable();
	addCollisionToEnv(p, collisionChecker);

	promptSDcard(p, device_reference);

	usleep(1000);
	alt_up_char_buffer_string(char_buffer, "Loading ", 40, 30);

	  unsigned end_time, start_time;
	  int count = 0; lock = 0;

	struct animation* starAnimation = loadSDImageSeq("ST0.BMP", 2, 8);
	struct animation* star2Animation = loadSDImageSeq("ST00.BMP", 3, 7);
	struct animation* alien0 = loadSDImageSeq("A100.BMP", 2, 2); //2 images where first 2 characters are prefix
	struct animation* alien1 = loadSDImageSeq("A000.BMP", 2, 15);
	struct animation* ship0 = loadSDImageSeq("S00.BMP", 2, 16);
	struct animation* ship1 = loadSDImageSeq("S10.BMP", 2, 27);
	struct animation* bossAnimate = loadSDImageSeq("BO00.BMP", 2, 28);
	struct animation* ship2 = loadSDImageSeq("S20.BMP", 2, 35);
	struct animation* ship3 = loadSDImageSeq("S30.BMP", 2, 30);
	struct animation* ship4 = loadSDImageSeq("S40.BMP", 2, 10);

	struct animation* explode1 = initAnimation((int*)explode01, 1);
	addImage(explode1, initAnimation((int*)explode02, 0));
	addImage(explode1, initAnimation((int*)explode03, 0));
	addImage(explode1, initAnimation((int*)explode04, 0));
	addImage(explode1, initAnimation((int*)explode05, 0));

	struct animation** shipAnimationCollection = (struct animation**)malloc(sizeof(struct animation*)*5);
	shipAnimationCollection[0] = ship0;
	shipAnimationCollection[1] = ship1;
	shipAnimationCollection[2] = ship2;
	shipAnimationCollection[3] = ship3;
	shipAnimationCollection[4] = ship4;

	initWeapon(collisionChecker, p);

	struct Cursor* mouse = initCursor(p, collisionChecker);
	addToEnv(p, mouse->super);
	addObjToCollide(collisionChecker, mouse->super);
	setCursor(p, mouse);

	struct KeyController* keyController = initKeyController();
	struct SwitchController* switchController = initSwitchController();
	struct CursorController* ctrl = initCursorController(mouse->super, switchController, keyController);

	alt_up_char_buffer_string(char_buffer, "Loading Sounds            ", 30, 30);
	audioController = initAudioController();
	loadSound( audioController, LOOP_ONE );
	loadSound( audioController, LASER_SOUND );
	alt_irq_register(AUDIO_IRQ, audioController, (void*) audio_ISR);
	alt_irq_enable(AUDIO_IRQ);
	play_background_loop( audioController, LOOP_ONE );
	enableAudioController( audioController );

	printhex(info.score);

	mainMenu(mouse, ctrl, p);

	disableAudioController(audioController);
	stop_background_loop(audioController);
	unloadSoundById(audioController, LASER_SOUND);
	unloadSoundById(audioController, LOOP_ONE);
	alt_up_char_buffer_string(char_buffer, "Loading Sounds           ", 30, 30);
	//loadSound(audioController, WIN_SOUND);
	//loadSound(audioController, LOSE_SOUND);
	loadSound( audioController, TOWER_UPGRADE_SOUND );
	loadSound( audioController, LOOP_TWO );
	play_background_loop(audioController, LOOP_TWO);
	enableAudioController( audioController );
	alt_up_char_buffer_clear(char_buffer);
	//usleep(1000);
	struct Alien* testAlienCollection[60];
	gameSetup(p, shipAnimationCollection, mouse, starAnimation, star2Animation);

	usleep(500000); //time delay for panel to be drawn
//
	char LPS[50]; float lps_;

	int n = 0;

	for(n = 0; n < 20; n++) {
		testAlienCollection[n] =initAlien(n, 10*n, 10, alien0, explode1, "IdontKnow", 1.4, 150, 500, collisionChecker);
		addToEnvNR(p, testAlienCollection[n]->super);
	}
	for(n = 0; n < 20; n++) {
		testAlienCollection[n+20] =initAlien(10*n, n, 10, alien1, explode1, "whatName", 1.4, 190, 850, collisionChecker);
		addToEnvNR(p, testAlienCollection[n+20]->super);
	}
	for(n = 0; n < 20; n++) {
		testAlienCollection[n+40] =initAlien(10*n, n, 20, bossAnimate, explode1, "IamBoss", 1.6, 800, 1500, collisionChecker);
		testAlienCollection[n+40]->score = 300;
		addToEnvNR(p, testAlienCollection[n+40]->super);
	}
	int stage = 0;
	/*
	 * Game Starts!!!!!!
	 */
	alt_alarm_start (&alarm,alt_ticks_per_second(),my_alarm_callback,(void*)p);

	int startTimer = 0;
	char second_row1[15];
	alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
	  sprintf(second_row1, "wave# %d  ", stage);
	  alt_up_character_lcd_string(char_lcd_dev, second_row1);

  while(1) {
	  alt_timestamp_start();
	  start_time = (unsigned)alt_timestamp();

/*-----------------------------------------------------------------------------------------------*/

	  checkCollision(collisionChecker); //a major function that check each collision happen between each object

	  updateCursorController(ctrl, 1);

	  count++;

	  if (startTimer > count)
		  info.startButton = false;
	  else {
		  if(stage == 7)
			info.isWin = true;
		  else if(startTimer == count){
			//play_background_loop(audioController, LOOP_TWO);
			enableAudioController( audioController );
		  }
	  }
	  if (info.startButton){
			disableAudioController(audioController);
			//stop_background_loop(audioController);
		    startTimer = count + 15000;
	  		checkStages(testAlienCollection, stage%7, collisionChecker);
			stage++;
			//if(stage > 6) stage = 0;
			info.startButton = false;
		  	  alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
		  	  sprintf(second_row1, "wave# %d  ", stage);
		  	  alt_up_character_lcd_string(char_lcd_dev, second_row1);
	  }

	  if(info.isEnd || info.isWin) {

			disableAudioController(audioController);
			stop_background_loop(audioController);
		  endGame(testAlienCollection, collisionChecker, p, mouse, ctrl, keyController);
	  }
/*-----------------------------------------------------------------------------------------------*/



	  end_time = (unsigned)alt_timestamp();
	  lps_ = (float)alt_timestamp_freq()/(float)(end_time - start_time);

	  sprintf(LPS, "The current LPS is %.2f", lps_);
	  alt_up_char_buffer_string(char_buffer, LPS, 3, 2);
  }
  return 0;
}
Esempio n. 8
0
int main() {
	/* For pushbuttons, 1 means unpressed */
	char last_key_value[4] = { 1 };
	char key_value;
	alt_up_character_lcd_dev * char_lcd_dev;

	/* Console preamble */
	printf("Exercise 1.1\n"
			"Team 21\n"
			"Derek Chan, Jay Dahiya, Johnson Huang, Logan Gilmore\n");

	/* Initialize and open the LCD Driver */
	char_lcd_dev = alt_up_character_lcd_open_dev(LCD_DEV);
	if (char_lcd_dev == NULL)
		printf("Error: Could not open character LCD device %s\n", LCD_DEV);

	alt_up_character_lcd_init(char_lcd_dev);
	alt_up_character_lcd_string(char_lcd_dev, "Key:  ");

	/* Main loop */
	while (1) {
		/* Toggle LEDG with the SW */
		*leds = *switches;

		/* Read KEY0 */
		key_value = *pushbuttons & KEY_MASKS[0];
		if (key_value != last_key_value[0]) {
			last_key_value[0] = key_value;
			if (key_value == 0) {
				printf("KEY0\n");
				lcd_replace_last_char(char_lcd_dev, '0');
			}
		}

		/* Read KEY1 */
		key_value = *pushbuttons & KEY_MASKS[1];
		if (key_value != last_key_value[1]) {
			last_key_value[1] = key_value;
			if (key_value == 0) {
				printf("KEY1\n");
				lcd_replace_last_char(char_lcd_dev, '1');
			}
		}

		/* Read KEY2 */
		key_value = *pushbuttons & KEY_MASKS[2];
		if (key_value != last_key_value[2]) {
			last_key_value[2] = key_value;
			if (key_value == 0) {
				printf("KEY2\n");
				lcd_replace_last_char(char_lcd_dev, '2');
			}
		}

		/* Read KEY3 */
		key_value = *pushbuttons & KEY_MASKS[3];
		if (key_value != last_key_value[3]) {
			last_key_value[3] = key_value;
			if (key_value == 0) {
				printf("KEY3\n");
				lcd_replace_last_char(char_lcd_dev, '3');
			}
		}
	}

	return 0;
}