summaryrefslogtreecommitdiffstats
path: root/source/ct-Bot/pc/display_pc.c
blob: 60a7dab6d3397c724f85a7c09b05e5c7aa4a9a85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
/*
 * c't-Sim - Robotersimulator fuer den c't-Bot
 * 
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your
 * option) any later version. 
 * This program is distributed in the hope that it will be 
 * useful, but WITHOUT ANY WARRANTY; without even the implied
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
 * PURPOSE. See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public 
 * License along with this program; if not, write to the Free 
 * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307, USA.
 * 
 */

/*! @file 	display_pc.c 
 * @brief 	Routinen zur Displaysteuerung
 * @author 	Benjamin Benz (bbe@heise.de)
 * @date 	20.12.05
*/

#include "ct-Bot.h"

#ifdef PC

#include "display.h"
#include <stdarg.h>
#include <stdio.h>

/* definiere DISPLAY_REMOTE_AVAILABLE, wenn die Display-Daten per TCP an das 
 * Simulationsprogramm gesendet werden sollen.  Wenn es nicht gesetzt ist, 
 * dann erscheint die LCD Ausgabe auf der Startkonsole */


#ifdef DISPLAY_REMOTE_AVAILABLE
 #include "command.h"
 #include "bot-2-sim.h"  
#else
 #ifdef WIN32
  #include <windows.h>
 #endif	/* WIN32 */
#endif

#ifdef DISPLAY_AVAILABLE

/*! Puffergroesse fuer eine Zeile in bytes */
#define DISPLAY_BUFFER_SIZE	(DISPLAY_LENGTH + 1)

uint8 display_update=0;	/*!< Muss das Display aktualisiert werden? */
#ifdef DISPLAY_SCREENS_AVAILABLE
	uint8 display_screen=0;	/*!< Muss das Display aktualisiert werden? */
#endif

char display_buf[DISPLAY_BUFFER_SIZE];	/*!< Pufferstring fuer Displayausgaben */

#ifdef DISPLAY_REMOTE_AVAILABLE
    #define CLEAR              command_write(CMD_AKT_LCD, SUB_LCD_CLEAR, NULL, NULL,0)
    #define POSITION(Ze, Sp)   {Ze--; Sp--; command_write(CMD_AKT_LCD, SUB_LCD_CURSOR, (int16*)&(Sp),(int16*) &(Ze),0);}
    #define printf(data)       {command_write_data(CMD_AKT_LCD, SUB_LCD_DATA, NULL, NULL, (data));}
#else
 #ifdef WIN32
    static void clrscr(void);
    static void gotoxy(int x, int y);
	#define POSITION(Ze, Sp)   gotoxy(Sp, Ze)
	#define CLEAR              clrscr()
 #else 
	#define POSITION(Ze, Sp)   printf("\033[%d;%dH",Ze,Sp)		/*!< Befehl um eine Posion anzuspringen */
	#define CLEAR              printf("\033[2J")				/*!< Befehl um das display zu loeschen */
 #endif 
#endif


/*!
 * Loescht das ganze Display
 */
void display_clear(void){
	CLEAR;
}

/*!
** LCD_Cursor: Positioniert den LCD-Cursor bei "row", "column".
*/
void display_cursor (uint8 row, uint8 column) {
	int16 r=row, c=column;	// Cast auf int16
	POSITION(r, c);
}

/*! 
 * Init Display
 */
void display_init(void){
	CLEAR;
}

/*! 
 * Zeigt einen String an 
 * @return -1, falls String zu Ende; 0, falls Zeile (20 Zeichen) zu Ende
 */
int display_string(char data[DISPLAY_LENGTH]){
	printf(data);
	return -1;
}

/*!
 * Schreibt einen String auf das Display.
 * @param format Format, wie beim printf
 * @param ... Variable Argumentenliste, wie beim printf
 */
void display_printf(char *format, ...) {
	
	va_list	args;
	
	/* Sicher gehen, das der zur Verfuegung stehende Puffer nicht
	 * ueberschrieben wird.
	 */
	va_start(args, format);
	vsnprintf(display_buf, DISPLAY_BUFFER_SIZE, format, args);
	va_end(args);

	printf(display_buf);	
	
	return;
}

#ifndef DISPLAY_REMOTE_AVAILABLE
#ifdef WIN32

/*!
 * Loescht die Konsole.
 */
static void clrscr(void) {
	COORD coordScreen = { 0, 0 };
	DWORD cCharsWritten;
	CONSOLE_SCREEN_BUFFER_INFO csbi;
	DWORD dwConSize;
	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);

	GetConsoleScreenBufferInfo(hConsole, &csbi);
	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
	FillConsoleOutputCharacter(	hConsole, 
								TEXT(' '),
								dwConSize,
								coordScreen,
								&cCharsWritten);
	GetConsoleScreenBufferInfo(hConsole, &csbi);
	FillConsoleOutputAttribute(	hConsole,
                             	csbi.wAttributes,
                             	dwConSize,
                             	coordScreen,
                             	&cCharsWritten);
	SetConsoleCursorPosition(hConsole, coordScreen);
	return;
}

/*!
 * Springt an die angegebenen Koordinaten in der Konsole.
 * @param x Spalte
 * @param y Zeile
 */
static void gotoxy(int x, int y) {
	COORD point;
	point.X = x-1; point.Y = y-1;
	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
	return;
}

#endif	/* WIN32 */
#endif  /* !DISPLAY_REMOTE_AVAILABLE */

#endif
#endif