Exemplo n.º 1
0
Arquivo: life.c Projeto: rellify/CS
//------------------------------------------------------------------------------
// main ------------------------------------------------------------------------
void main(void)
{
	RBX430_init(_16MHZ);				// init board
	ERROR2(lcd_init());					// init LCD

	// configure Watchdog
	WDTCTL = WDT_CTL;					// Set Watchdog interval
	WDT_Sec_Cnt = WDT_1SEC_CNT;			// set WD 1 second counter
	IE1 |= WDTIE;						// enable WDT interrupt

	lcd_clear();						// clear LCD
	lcd_backlight(ON);					// turn on LCD backlight
	lcd_rectangle(0, 0, NUM_COLS*2, NUM_ROWS*2, 1);	// draw border

	__bis_SR_register(GIE);				// enable interrupts

	// output splash screen & wait for switch
	lcd_wordImage(life_image, (159-126)/2, 50, 1);
	lcd_mode(LCD_PROPORTIONAL | LCD_2X_FONT);
	lcd_cursor(10, 20);
	printf("Press Any Key");
	lcd_mode(0);
	while (1) if ((P1IN & 0x0f) ^ 0x0f) break;

	while (1)
	{
		uint16 row, col;
		// for each live row (78 down to 1)
		for (row = NUM_ROWS-2; row; --row)
		{
			// for each live column (78 down to 1)
			for (col = NUM_COLS-2; col; --col)
			{

					cell_death(row, col);
			}
		}

		char str[] = "x = 2, y = 2, rule = B3/S23\n2o$2o!";
		char* ptr;
		int x_number = 0;
		int y_number = 0;
		const uint8 pttrn;
		for (ptr = str; *ptr; ptr++);
		{
				if (*ptr != 'x') continue;
				if ((*ptr < '0') && (*ptr > '9')) continue;
				while ((*ptr >= '0') && (*ptr <= '9'))
				{
					x_number = x_number * 10 + (*ptr++ - '0');
				}

				if (*ptr != 'y') continue;
				if ((*ptr < '0') && (*ptr > '9')) continue;
				while ((*ptr >= '0') && (*ptr <= '9'))
				{
					y_number = y_number * 10 + (*ptr++ - '0');
				}

				if (*ptr != 'n') continue;

		}




	}

	while (1)							// new pattern seed
	{
		// load initial seed patterns
		uint16 generation = 0;			// generation counter
		uint8 pen  = BIRTH;				// temp variable
		WDT_Sec_Cnt = WDT_1SEC_CNT;		// set WD 1 second counter
		seconds = 0;					// clear second counter


		while (1)
		{
			uint16 row, col;
			// for each live row (78 down to 1)
			for (row = NUM_ROWS-2; row; --row)
			{
				// for each live column (78 down to 1)
				for (col = NUM_COLS-2; col; --col)
				{
					if (pen == BIRTH)
					{
						cell_birth(row, col);
					}
					else
					{
						cell_death(row, col);
					}
				}
			}
			lcd_wordImage(life_image, (159-126)/2, 50, (BIRTH == pen) ? 3 : 1);
			lcd_cursor(4, 1);			// output life generation
			printf("%d/%d", ++generation, seconds);
			if (seconds == 100) while (1);
			pen = (pen == BIRTH) ? DEATH : BIRTH;
		}
	}
} // end main()
Exemplo n.º 2
0
//------------------------------------------------------------------------------
//	Initialize Life pattern seed -----------------------------------------------
void init_life(enum SEED seed)
{
	int i;
	lcd_clear();						// clear LCD
	memset(life, 0, sizeof(life));		// clear life array
	lcd_backlight(ON);					// turn on LCD backlight
	lcd_rectangle(0, 0, NUM_COLS*2, NUM_ROWS*2, 1);
	switch(seed)
	{
		case LIFE:
		{
			draw_rle_pattern(65, 30, gosper_glider_gun);
			draw_rle_pattern(60, 5, pulsar);
			draw_rle_pattern(4, 7, beacon_maker);
			draw_rle_pattern(4, 30, hexapole);
			draw_rle_pattern(4, 40, hexapole);
			draw_rle_pattern(4, 50, hexapole);
			draw_rle_pattern(4, 60, hexapole);
			draw_rle_pattern(15, 65, loafer);
			break;
		}

		case BIRD:
		{
			draw_rle_pattern(60, 5, pulsar);		// sun
			draw_rle_pattern(31, 2, bird);			// bird
			draw_rle_pattern(40, 20, hwss);			// bigger bird
			draw_rle_pattern(11, 29, glider);		// blows bird apart
			draw_rle_pattern(65, 65, loafer);

			for (i = 2; i <= 78; i += 3)			// draw ground
			{
				draw_rle_pattern(7, i, block);		// block
			}
			break;
		}

		case BOMB:
		{
			draw_rle_pattern(65, 10, gosper_glider_gun);
			draw_rle_pattern(40, 10, lwss);			// LWSS
			draw_rle_pattern(20, 10, pulsar);		// pulsar
			draw_rle_pattern(20, 35, pulsar);		// pulsar
			draw_rle_pattern(20, 60, pulsar);		// pulsar
			draw_rle_pattern(10, 10, block);		// block
			draw_rle_pattern(10, 18, beehive);		// beehive
			draw_rle_pattern(10, 26, loaf);			// loaf
			draw_rle_pattern(10, 34, boat);			// boat
			draw_rle_pattern(10, 42, toad);			// toad
			draw_rle_pattern(10, 50, beacon);		// beacon
			draw_rle_pattern(10, 58, blinker);		// blinker
			draw_rle_pattern(10, 66, by_flop);		// by_flop
			break;
		}

		default:
		{
			draw_rle_pattern(4, 2, jon_arbuckle);	// pattern of choice
			break;
		}
	}
	return;
} // end init_life
void four_bar(){
  //for debugging
  float boost = 0;
  float oilT = 0;
  float T1 = 0; 
  float T2 = 0;
  bmp_draw("fourbar",0,0);
  while (!(touch_get_cursor(&m_point))){
    //get Boost, OilT, T1, and T2
    boost++;
    oilT++;
    T1++;
    T2++;
    if (boost >= maxBoost){boost = 0;}
    if (oilT >= maxOilT){oilT = 0;}
    if (T1 >= maxT1){T1 = 0;}
    if (T2 >= maxT1){T2 = 0;}
    COLOR conditionColor = mwhite;
    //draw rectangles inside rectangles 
    //only 86 ticks on a bar
      //lcd_clear (x, y, x1, y2, fill); //draws a solid rect fill with no border
      //bst rect = (39, 13) to (125, 33)
      if (boost >= severeBoost){conditionColor = fadedRed;}
      else if (boost >= warnBoost){conditionColor = fadedYellow;}
      else {conditionColor = fadedGreen;}
      lcd_rectangle(39,13,(int(39.0+(boost * 86.0/maxBoost))),33,conditionColor,conditionColor);
      lcd_rectangle(int((39.0+(boost * 86.0/(float)maxBoost))),13,125,33,mblack,mblack); //blacken the rest 
      //oilt rect = (39, 38) to (125, 58)
      if (oilT >= severeOilT){conditionColor = fadedRed;}
      else if (oilT >= warnOilT){conditionColor = fadedYellow;}
      else {conditionColor = fadedGreen;}
      lcd_rectangle(39,38,(39+(oilT * 86/maxOilT)),58,conditionColor,conditionColor);
      lcd_rectangle((39+(oilT * 86/maxOilT)),38,125,58,mblack,mblack);
      //t1 rect = (39, 64) to (125, 84)
      if (T1 >= severeT1){conditionColor = fadedRed;}
      else if (T1 >= warnT1){conditionColor = fadedYellow;}
      else {conditionColor = fadedGreen;}
      lcd_rectangle(39,64,(39+(T1 * 86/maxT1)),84,conditionColor,conditionColor);
      lcd_rectangle((39+(T1 * 86/maxT1)),64,125,84,mblack,mblack);      
      //T2 rect = (39, 90) to (125, 110)
      if (T2 >= severeT2){conditionColor = fadedRed;}
      else if (T2 >= warnT2){conditionColor = fadedYellow;}
      else {conditionColor = fadedGreen;}
      lcd_rectangle(39,90,(39+(T2 * 86/maxT2)),110,conditionColor,conditionColor);
      lcd_rectangle((39+(T2 * 86/maxT2)),90,125,110,mblack,mblack);
    //print values on top of bars in white
    char out[7];
    fmtDouble(boost, 2, out, 7);
    lcd_puts(out, 95, 18, lightBlue, mblack);
    fmtDouble(oilT, 2, out, 7);
    lcd_puts(out, 95, 43, lightBlue, mblack);
    fmtDouble(T1, 2, out, 7);
    lcd_puts(out, 95, 69, lightBlue, mblack);     
    fmtDouble(T2, 2, out, 7);
    lcd_puts(out, 95, 93, lightBlue, mblack);
    
    delay (100);
    //bmp_draw("fourbar",0,0);
  }
  
  //when a touch is detected get coords
  //go to mode of what is touched if it is boost or oilT
  //otherwise go to next display
  while (touch_get_cursor(&m_point)){ //debounce hold
  LCD_RECT boostRect; boostRect.left = 0; boostRect.right = 128; boostRect.top = 11; boostRect.bottom = 34;
  LCD_RECT oilRect; oilRect.left = 0; oilRect.right = 128; oilRect.top = 36; oilRect.bottom = 59;
  if (pointInRect(m_point,boostRect)){boost_gauge();}
  if (pointInRect(m_point,oilRect)){oil_temp_gauge();}
  }
  xygraph(); //click anywhere else and it goes to xygraph
  
}