Пример #1
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) {}
		}
	}
}
Пример #2
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);
	}
}
Пример #3
0
// For the Key 1 press
void reset_display() {
	// Clear the top row
	strcpy(top_row, "    12:00:00    ");
	alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0);
	alt_up_character_lcd_string(char_lcd_dev, top_row);
	
	// Clear the bottom row
	strcpy(bot_row, "                ");
	alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
	alt_up_character_lcd_string(char_lcd_dev, bot_row);
	
	// Reset our counters
	minutes = 0;
	seconds = 0;
	tenths = 0;
}
Пример #4
0
// handles key presses for setting the alarm time
void handle_key_press_alarm_set() {
	// Key 2 increments minutes
	if (edge_capture == 4) {
		increment_minutes(bot_row, &alarm_minutes);
		alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
		alt_up_character_lcd_string(char_lcd_dev, bot_row);
	}
	// Key 3 increments hours
	else if (edge_capture == 8) {
		increment_hours(bot_row, &alarm_hours, am_pm_mode);
		alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 1);
		alt_up_character_lcd_string(char_lcd_dev, bot_row);
	}
	// Reset our edge capture back to 0
	edge_capture = 0;
}
Пример #5
0
void char_display_write (int row, int start_pos, const char *ptr) {
	if (!char_display_init()) return;
	if (row != LCD_ROW_ONE && row != LCD_ROW_TWO) return;
	if (start_pos < 0 || start_pos > 15) return;

	alt_up_character_lcd_set_cursor_pos(LCD_port, start_pos, row);
	alt_up_character_lcd_string(LCD_port, ptr);
}
Пример #6
0
void updateScoreMoney(int addScore, int income) {
	info.score += addScore;
	info.currency += income;
	updateScoreFrame();

	printhex(info.score);

	  char second_row2[15];
	  alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0);
	  sprintf(second_row2, "$$ %d  ", info.currency);
	  alt_up_character_lcd_string(char_lcd_dev, second_row2);
}
Пример #7
0
/* Our function that handles the key presses for time setting*/
void handle_key_press_time() {
	// Key 1 increments the seconds
	if (edge_capture == 2) {
		increment_seconds(top_row, &seconds);
		alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0);
		alt_up_character_lcd_string(char_lcd_dev, top_row);
	}
	// Key 2 increments the minutes
	else if (edge_capture == 4) {
		increment_minutes(top_row, &minutes);
		alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0);
		alt_up_character_lcd_string(char_lcd_dev, top_row);
	}
	// Key 3 increments the hours
	else if (edge_capture == 8) {
		increment_hours(top_row, &hours, am_pm_mode);
		alt_up_character_lcd_set_cursor_pos(char_lcd_dev, 0, 0);
		alt_up_character_lcd_string(char_lcd_dev, top_row);
	}
	
	// Reset our edge capture back to 0
	edge_capture = 0;
}
Пример #8
0
/* Writes to the LCD based on the value of the switch. */
void lcd_task(void* pdata)
{
	INT8U err;
	while (1)
	{
		char message[LCD_MESSAGE_SIZE];
		int status = (int)OSQPend(queue, WAIT_FOREVER, &err);
		if (err == OS_NO_ERR) {
			lcd_clear();
			getMessageFromStatus(status, message);
			alt_up_character_lcd_set_cursor_pos(lcd, LCD_LEFT, LCD_UPPER);
			alt_up_character_lcd_string(lcd, message);
		}
	}
}
Пример #9
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);
}
Пример #10
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;
}
Пример #11
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;
}