16 #include "../include/tscope5/system.h"
17 #include "../include/tscope5/display.h"
18 #include "../include/tscope5/system_internal.h"
45 void ts5_log(
const unsigned int level,
const char *format, ...)
51 if (level <= _ts5_status.loglevel) {
54 _ts5_data.textlog = fopen(
"tscope5.log",
"w+");
55 if (!_ts5_data.textlog) {
56 ts5_fatal(
"ts5_log: could not open log file\n");
61 char outbuf[TS5_MAX_CHAR];
63 va_start(args, format);
64 vsnprintf(outbuf, TS5_MAX_CHAR*
sizeof(
char), format, args);
67 double logtime = al_get_time();
68 fprintf(stdout,
"%8.3f: %s", logtime, outbuf);
70 fprintf(_ts5_data.textlog,
"%8.3f: %s", logtime, outbuf);
104 ts5_log(TS5_LOGLEVEL_4,
"ts5_set_log_level(%d)\n", loglevel);
107 retval = _ts5_status.loglevel;
109 if (loglevel <= TS5_LOGLEVEL_6) {
110 _ts5_status.loglevel = loglevel;
112 ts5_log(TS5_LOGLEVEL_4,
"%s: %s %d to %d\n",
"ts5_set_log_level",
113 "changed loglevel from", retval, loglevel);
116 ts5_fatal(
"ts5_log: requested loglevel not supported.");
134 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_log_level\n");
136 return _ts5_status.loglevel;
150 char line[]=
"==================================================\n";
157 ts5_log(TS5_LOGLEVEL_0,
"tscope5 status:\n");
160 ts5_log(TS5_LOGLEVEL_0,
"Loglevel: %d\n", _ts5_status.loglevel);
161 ts5_log(TS5_LOGLEVEL_0,
"Number of display adapters: %d\n",
162 _ts5_status.num_display_adapters);
164 for (i = 0; i < _ts5_status.num_display_adapters; i++) {
166 ts5_log(TS5_LOGLEVEL_0,
"%s %d: w: %d (%d:%d), h: %d (%d:%d)\n",
167 "Display adapter", i+1,
168 _ts5_status.display_adapter[i].w,
169 _ts5_status.display_adapter[i].x1,
170 _ts5_status.display_adapter[i].x2,
171 _ts5_status.display_adapter[i].h,
172 _ts5_status.display_adapter[i].y1,
173 _ts5_status.display_adapter[i].y2);
179 ALLEGRO_DISPLAY_MODE *mode;
180 mode = (ALLEGRO_DISPLAY_MODE *)al_malloc(
sizeof(ALLEGRO_DISPLAY_MODE));
182 for (i = 0; i < _ts5_status.num_display_adapters; i++) {
184 al_set_new_display_adapter(i);
185 int oldrate = al_get_new_display_refresh_rate();
186 int oldflags = al_get_new_display_flags();
187 al_set_new_display_refresh_rate(0);
188 al_set_new_display_flags(0);
190 int nmodes = al_get_num_display_modes();
193 for (j=0; j<nmodes; j++) {
195 mode = al_get_display_mode(j, mode);
197 "adapter %d mode %2d: w=%4d, h=%4d, format=%d, rate=%d\n",
198 i+1, j+1, mode->width, mode->height,
199 mode->format, mode->refresh_rate);
202 al_set_new_display_refresh_rate(oldrate);
203 al_set_new_display_flags(oldflags);
207 al_set_new_display_adapter(oldadapter);
212 ts5_log(TS5_LOGLEVEL_0,
"Parameters for next display:\n");
214 ts5_log(TS5_LOGLEVEL_0,
"\tAdapter %d\n",
217 ts5_log(TS5_LOGLEVEL_0,
"\tw=%d, h=%d\n",
220 ts5_log(TS5_LOGLEVEL_0,
"\tx=%d, y=%d\n",
223 ts5_log(TS5_LOGLEVEL_0,
"\tRefreshrate=%d\n",
226 ts5_log(TS5_LOGLEVEL_0,
"\tDisplay mode=%d\n",
229 ts5_log(TS5_LOGLEVEL_0,
"\tVsync mode=%d\n",
234 ts5_log(TS5_LOGLEVEL_0,
"Number of displays: %d\n",
235 _ts5_status.num_displays);
237 ts5_log(TS5_LOGLEVEL_0,
"Active display: %d\n",
238 _ts5_status.active_display);
240 for (i = 0; i < _ts5_status.num_displays; i++) {
243 "%s %d: %s %d, w=%d, h=%d, x=%d, y=%d, %s=%d, %s=%d, %s=%d\n",
245 "Adapter", _ts5_status.display[i].adapter+1,
246 _ts5_status.display[i].w, _ts5_status.display[i].h,
247 _ts5_status.display[i].x, _ts5_status.display[i].y,
248 "Refreshrate", _ts5_status.display[i].refreshrate,
249 "Dispay mode", _ts5_status.display[i].display_mode,
250 "Vsync mode", _ts5_status.display[i].vsync_mode);
259 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
260 "Coordinate system", _ts5_status.graphics.coordinate_system);
262 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
263 "Coordinate scale", _ts5_status.graphics.coordinate_scale);
265 ts5_log(TS5_LOGLEVEL_0,
"%s: %d x %d\n",
266 "Target bitmap size",
267 _ts5_status.graphics.target_width,
268 _ts5_status.graphics.target_height);
270 al_unmap_rgba_f(_ts5_status.graphics.foreground_color, &r, &g, &b, &a);
271 ts5_log(TS5_LOGLEVEL_0,
"%s: r: %f g: %f b: %f alpha: %f\n",
272 "Foreground color", r, g, b, a);
274 al_unmap_rgba_f(_ts5_status.graphics.background_color, &r, &g, &b, &a);
275 ts5_log(TS5_LOGLEVEL_0,
"%s: r: %f g: %f b: %f alpha: %f\n",
276 "Background color", r, g, b, a);
278 ts5_log(TS5_LOGLEVEL_0,
"%s: %f\n",
279 "Line drawing thickness", _ts5_status.graphics.drawing_thickness);
281 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
282 "Fill mode", _ts5_status.graphics.fill_mode);
284 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
285 "Font type", _ts5_status.graphics.font_type);
287 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
288 "Font style", _ts5_status.graphics.font_style);
290 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
291 "Font size", _ts5_status.graphics.font_size);
293 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
294 "Font number", _ts5_status.graphics.font_index);
296 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
297 "Text alignment", _ts5_status.graphics.text_alignment);
305 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
306 "Number of audio channels", _ts5_status.audio.channels);
308 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
309 "Sample rate", _ts5_status.audio.samplerate);
311 ts5_log(TS5_LOGLEVEL_0,
"%s: %d\n",
312 "Sample format", _ts5_status.audio.depth);
314 ts5_log(TS5_LOGLEVEL_0,
"%s: %f\n",
315 "Audio Gain", _ts5_status.audio.gain);
319 TS5_TIMER_STATUS *timer = &_ts5_status.timer;
323 ts5_log(TS5_LOGLEVEL_0,
"Program priority: %+d\n",
326 ts5_log(TS5_LOGLEVEL_0,
"Number of defined response buttons: %d\n",
327 timer->num_defined_buttons);
329 ts5_log(TS5_LOGLEVEL_0,
"Number of active response buttons: %d\n",
330 timer->num_active_buttons);
332 ts5_log(TS5_LOGLEVEL_0,
"Voicekey is response device: %d\n",
333 timer->voicekey_is_response_device);
335 if (timer->voicekey_is_response_device) {
337 for (i=0; i<timer->voicekey.num_buttons; i++) {
339 if (timer->voicekey.button_press_active[i]!=0) {
340 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d\n",
341 "Voice key button press", i+1,
"has response value",
342 timer->voicekey.button_press_defined[i]);
345 if (timer->voicekey.button_release_active[i]!=0) {
346 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d\n",
347 "Voice key button release", i+1,
"has response value",
348 timer->voicekey.button_release_defined[i]);
353 ts5_log(TS5_LOGLEVEL_0,
"Mouse is response device: %d\n",
354 timer->mouse_is_response_device);
356 if (timer->mouse_is_response_device) {
358 for (i=0; i<timer->mouse.num_buttons; i++) {
360 if (timer->mouse.button_press_active[i]!=0) {
361 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d\n",
362 "Mouse button press", i+1,
"has response value",
363 timer->mouse.button_press_defined[i]);
366 if (timer->mouse.button_release_active[i]!=0) {
367 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d\n",
368 "Mouse button release", i+1,
"has response value",
369 timer->mouse.button_release_defined[i]);
374 ts5_log(TS5_LOGLEVEL_0,
"Keyboard is response device: %d\n",
375 timer->keyboard_is_response_device);
377 if (timer->keyboard_is_response_device) {
379 for (i=0; i<timer->keyboard.num_buttons; i++) {
381 if (timer->keyboard.button_press_active[i]!=0) {
382 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d\n",
383 "Keyboard button press", i+1,
"has response value",
384 timer->keyboard.button_press_defined[i]);
387 if (timer->keyboard.button_release_active[i]!=0) {
388 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d\n",
389 "Keyboard button release", i+1,
"has response value",
390 timer->keyboard.button_release_defined[i]);
395 ts5_log(TS5_LOGLEVEL_0,
"Number of joysticks: %d\n",
396 timer->num_joysticks);
398 ts5_log(TS5_LOGLEVEL_0,
"Joystick is response device: %d\n",
399 timer->joystick_is_response_device);
401 if (timer->joystick_is_response_device) {
403 for (i=0; i<timer->num_joysticks; i++) {
406 for (j=0; j<timer->joystick[i].num_buttons; j++) {
408 if (timer->joystick[i].button_press_active[j]!=0) {
409 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d %s %d\n",
410 "Joystick", i+1,
"button press", j+1,
411 "has response value",
412 timer->joystick[i].button_press_defined[j]);
415 if (timer->joystick[i].button_release_active[j]!=0) {
416 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d %s %d\n",
417 "Joystick", i+1,
"button release", j+1,
418 "has response value",
419 timer->joystick[i].button_release_defined[j]);
425 ts5_log(TS5_LOGLEVEL_0,
"Number of cedrusboxes: %d\n",
426 timer->num_cedrusboxes);
428 ts5_log(TS5_LOGLEVEL_0,
"Cedrusbox is response device: %d\n",
429 timer->cedrusbox_is_response_device);
431 if (timer->cedrusbox_is_response_device) {
433 for (i=0; i<timer->num_cedrusboxes; i++) {
435 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d\n",
437 "is mapped to serial device",
438 timer->cedrusbox[i].port_num+1);
440 ts5_log(TS5_LOGLEVEL_0,
"Cedrusbox %d is type %d\n",
441 i+1, timer->cedrusbox[i].type);
444 for (j=0; j<timer->cedrusbox[i].num_buttons; j++) {
446 if (timer->cedrusbox[i].button_press_active[j]!=0) {
447 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d %s %d\n",
448 "Cedrusbox", i+1,
"button press", j+1,
449 "has response value",
450 timer->cedrusbox[i].button_press_defined[j]);
453 if (timer->cedrusbox[i].button_release_active[j]!=0) {
454 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d %s %d\n",
455 "Cedrusbox", i+1,
"button release", j+1,
456 "has response value",
457 timer->cedrusbox[i].button_release_defined[j]);
463 ts5_log(TS5_LOGLEVEL_0,
"Number of parallel ports: %d\n",
464 timer->num_parports);
466 ts5_log(TS5_LOGLEVEL_0,
"Parallel port is response device: %d\n",
467 timer->parport_is_response_device);
469 if (timer->parport_is_response_device) {
471 for (i=0; i<timer->num_parports; i++) {
474 for (j=0; j<timer->parport[i].num_buttons; j++) {
476 if (timer->parport[i].button_press_active[j]!=0) {
477 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d %s %d\n",
478 "Parallel box", i+1,
"button press", j+1,
479 "has response value",
480 timer->parport[i].button_press_defined[j]);
483 if (timer->cedrusbox[i].button_release_active[j]!=0) {
484 ts5_log(TS5_LOGLEVEL_0,
"%s %d %s %d %s %d\n",
485 "Parallel box", i+1,
"button release", j+1,
486 "has response value",
487 timer->parport[i].button_release_defined[j]);
531 ts5_log(TS5_LOGLEVEL_1,
"ts5_fatal\n");
533 char outbuf[TS5_MAX_CHAR];
535 va_start(args, format);
536 vsnprintf(outbuf, TS5_MAX_CHAR*
sizeof(
char), format, args);
539 fprintf(stdout,
"Tscope5 error: %s", outbuf);
541 #ifndef TS5_RASPBERRYPI
542 if (_ts5_status.num_displays>0) {
544 if (_ts5_status.display[_ts5_status.active_display].display_mode
545 == TS5_FULLSCREEN_WINDOW) {
547 al_toggle_display_flag(
548 _ts5_data.display[_ts5_status.active_display],
549 ALLEGRO_FULLSCREEN_WINDOW, 0);
551 _ts5_status.display[_ts5_status.active_display].display_mode
555 al_show_native_message_box(
556 _ts5_data.display[_ts5_status.active_display],
557 "Tscope5 error",
"Tscope5 error", outbuf, NULL,
558 ALLEGRO_MESSAGEBOX_ERROR);
561 al_show_native_message_box(NULL,
"Tscope5 error",
"Tscope5 error",
562 outbuf, NULL, ALLEGRO_MESSAGEBOX_ERROR);
int _ts5_is_tscope5_installed
Is Tscope5 installed?
int ts5_get_log_level()
Get log level.
TS5_DISPLAY_STATUS ts5_nextdisplay
Settings for the next display that will be opened.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
int ts5_set_log_level(const unsigned int loglevel)
Set log level.
void ts5_install_tscope5(char *calling_function)
Install Tscope5.
void ts5_print_status()
Write the status of all Tscope5 subsystem to the log window.
int _ts5_is_textlog_installed
Is text log installed?
void ts5_fatal(const char *format,...)
Exit safely with an error message.