Beispiel #1
0
void menu_exec(struct MENU *menu)
{
	unsigned char csel, set, total;
	csel = 0;
again:
	lcd_fill(0);

	set_font(BOLDFONT);
	draw_string(0, 0, (char*)menu->name, 3, DRAW_PUT);
	draw_block(0,10,128,2,3,DRAW_PUT);
	draw_block(0,149,128,2,3,DRAW_PUT);
	set_font(SMALLFONT);

	total = menu->num_entries;
	for(set=0;set<total; set++)
	{
		draw_string(1, 15+(set*9), (char*)menu->entry[set].name, 3, DRAW_PUT);
	}

	draw_block(0, 14+(csel*9), 60, 9, 3, DRAW_XOR);
	draw_string(0, 152, (char*)menu->entry[csel].help, 3, DRAW_PUT);

	while(KEY_Exit) {};
	while(!KEY_Exit)
	{
		waitKeyUpDown();
		draw_block(0, 14+(csel*9), 60, 9, 3, DRAW_XOR);
		if(KEY_OK)
		{
			if(menu_execentry((MENU_ENTRY*)&menu->entry[csel]))
				goto again;
		}
		if(KEY_Up)
		{
			csel--;
			if(csel >= total)
				csel = total-1;
		}
		if(KEY_Down)
		{
			csel++;
			if(csel == total)
				csel = 0;
		}
		draw_block(0, 14+(csel*9), 60, 9, 3, DRAW_XOR);
		draw_block(0, 152, 128, 8, 3, DRAW_ERASE);
		draw_string(0, 152, (char*)menu->entry[csel].help, 3, DRAW_PUT);
	}
}
Beispiel #2
0
void RAW_learn(struct RAWset_* RAWset) {
	
	unsigned char cmd;
	unsigned char mode;
	
	lcd_fill(0);
	
	draw_block(0,10,128,2,3,DRAW_PUT);
		
	mode = 1;
	while(KEY_A) {};
	while(!KEY_A) {
		draw_block(0,0,100,9,3,DRAW_ERASE);
		set_font(BOLDFONT);
		if (mode)
			draw_string(0, 0, "Tasten anlernen", 3, DRAW_PUT);
		else
			draw_string(0, 0, "Tasten testen", 3, DRAW_PUT);
		set_font(SMALLFONT);
		draw_string(0, 20, "Gewuenschte Taste auf der\nBetty druecken.\nDie Tasten A, B, C und D\nkoennen nicht angelernt\nwerden", 3, DRAW_PUT);
		draw_string(0, 90, "A - Exit\nB - Anlernen/Testen\n", 3, DRAW_PUT);
		waitKeyUpDown();
		draw_block(0,20,128,45,3,DRAW_ERASE);
		draw_block(0,90,128,45,3,DRAW_ERASE);
		if(KEY_A || KEY_B || KEY_C || KEY_D) {
			if(KEY_B)
				mode = 1-mode;
		}
		else {
			cmd=getKeynum() -4;
			if(mode) {
				getIR(&(RAWset->RAWcmd[cmd]));
			}
			else {
				RAW_Send((unsigned long)&(RAWset->RAWcmd[cmd]));
				while(ANYKEY)
					RAW_Repeat();
				RAW_Stop();
			}
		}
	}
}
Beispiel #3
0
void getIR(struct RAWcmd_* cmd) {

	unsigned char x;
	struct ir_raw_ capture;
	
	x=1;
	while(x) {
		while(x) {
			draw_string(0,20,"Beide Fernbedienungen\neinander gegenueber\nlegen, so dass die Infra-\nrotschnittstellen direkt\nzueinander liegen.\nAbstand 2-10cm\nAnzulernene Taste druecken", 3, DRAW_PUT);
			x=captureIR(&capture);
			draw_block(0,20,128,9*7,3,DRAW_ERASE);
			if(x) {
				switch(x) {
					case 1:
						draw_string(0,20,"Befehl kann nicht eingelesen\nwerden.", 3, DRAW_PUT);
						break;
					case 2:
						return;
					case 3:
						draw_string(0,20,"Signal zu lange.\nBitte kuerzer druecken.", 3, DRAW_PUT);
						break;
					default:
						draw_string(0,20,"Fehler beim eingelesen.", 3, DRAW_PUT);
				}
				draw_string(0,56,"Exit zum abbrechen, andere\nTaste zum wiederholen", 3, DRAW_PUT);
				waitKeyUpDown();	
				if(KEY_Exit) {
					draw_block(0,20,128,54,3,DRAW_ERASE);
					return;
				}
				draw_block(0,20,128,45,3,DRAW_ERASE);
			}
		}
		clear_cmd(cmd);
		x = analyzeIR(&capture, cmd);
		if(x) {
			switch(x) {
				case 1:
					draw_string(0,20,"Signal zu lange.\nBitte kuerzer druecken.", 3, DRAW_PUT);
					break;
				case 2:
					draw_string(0,20,"Signal zu kurz.\nBitte laenger druecken.", 3, DRAW_PUT);
					break;
				case 3:
					draw_string(0,20,"Fehler beim Signalvergleich", 3, DRAW_PUT);
					break;
				case 4:
					draw_string(0,20,"Datenformat zu lange.", 3, DRAW_PUT);
					break;
				case 5:
					draw_string(0,20,"Unbekanntes Datenformat.", 3, DRAW_PUT);
					break;
				default:
					draw_string(0,20,"Fehler beim decodieren.", 3, DRAW_PUT);
			}
			draw_string(0,56,"Exit zum abbrechen, andere\nTaste zum wiederholen", 3, DRAW_PUT);
			waitKeyUpDown();	
			if(KEY_Exit) {
				draw_block(0,20,128,54,3,DRAW_ERASE);
				return;
			}
			draw_block(0,20,128,54,3,DRAW_ERASE);
			
		}
	}
		
}
Beispiel #4
0
void GameTicTacToe(void)
{
	BYTE Color;
	BYTE Mode;
	int i;
	int k;
	BOOL ComputerWon;
	BOOL PlayerWon;
	BYTE G[2][9];//GameArray [0=Computer / 1=Player][Game fields]
	BOOL GameIsRunning = false;
	BYTE Moves = 0;
	int Pos;

	Color = LCD_COLOR_B;
	Mode = DRAW_PUT;

again:
	//New game
	//Init the display
	lcd_fill(0);//Clr screen

	//Title
	set_font(SMALLFONT);
	draw_string(0, 0, "TicTacToe", Color, Mode);

	//Grid
	draw_block(16,		16+30,		96, 3, Color, Mode);
	draw_block(16,		16+30+3+30,	96, 3, Color, Mode);
	draw_block(16+30,	16,		3, 96, Color, Mode);
	draw_block(16+30+3+30,	16,		3, 96, Color, Mode);

	//Reset game field
	for(k=0; k<2; k++)
	{
		for(i=0; i<9; i++)
		{
			G[k][i] = 0;
		}
	}

	Moves = 0;

	GameIsRunning = true;

	while(1)
	{
		Pos = -1;
		if(KEY_1){Pos = 0;}
		if(KEY_2){Pos = 1;}
		if(KEY_3){Pos = 2;}
		if(KEY_4){Pos = 3;}
		if(KEY_5){Pos = 4;}
		if(KEY_6){Pos = 5;}
		if(KEY_7){Pos = 6;}
		if(KEY_8){Pos = 7;}
		if(KEY_9){Pos = 8;}

		if((Pos >= 0) && (Pos <= 8))
		{
			if(GameIsRunning)
			{
				if((G[0][Pos] + G[1][Pos]) == 0)
				{
					//field is empty
					G[1][Pos] = 1;
					Moves++;

					if(Moves < 9)
					{
						//Moves left
						if(!GameTicTacToe_IsSolved(G, &ComputerWon, &PlayerWon))
						{
							//Not solved -> computer move
							GameTicTacToe_ComputerMove(G);
							Moves++;
						}
					}					
					GameTicTacToe_DrawGameField(G);
				}
			}		
		}
	
		//Is solved?
		GameTicTacToe_IsSolved(G, &ComputerWon, &PlayerWon);
		if(ComputerWon)
		{
			draw_string(0, LCD_SIZE_Y - (8*4), "Computer hat gewonnen", Color, Mode);
			GameIsRunning = false;
		}
		else
		{
			if(PlayerWon)
			{
				draw_string(0, LCD_SIZE_Y - (8*4), "Spieler hat gewonnen", Color, Mode);
				GameIsRunning = false;
			}
			else
			{
				if(Moves == 9)
				{
					draw_string(0, LCD_SIZE_Y - (8*4), "Unentschieden", Color, Mode);
					GameIsRunning = false;
				}
			}
		}
	
		//Footer
		if(Moves > 0)
		{
			draw_string(0, LCD_SIZE_Y - (8*3), "0", Color, Mode);
			draw_string(32, LCD_SIZE_Y - (8*3), "Neues Spiel", Color, Mode);
			draw_string(0, LCD_SIZE_Y - (8*2), "Exit", Color, Mode);
			draw_string(32, LCD_SIZE_Y - (8*2), "Spiel beenden", Color, Mode);
		}
		else
		{
			draw_block(0, LCD_SIZE_Y - (8*2), LCD_SIZE_X, 8, Color, DRAW_ERASE);
		}
	
		if(GameIsRunning)
		{
			draw_string(0, LCD_SIZE_Y - 8, "1-9", Color, Mode);
			draw_string(32, LCD_SIZE_Y - 8, "Feld waehlen", Color, Mode);
		}
		else
		{
			draw_block(0, LCD_SIZE_Y - 8, LCD_SIZE_X, 8, Color, DRAW_ERASE);
		}
		waitKeyUpDown();
		if(KEY_0) goto again;
		if(KEY_Exit) return;
	}
}