Tscope5
keyboard_internal.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // __ ______
4 // / /_______________ ____ ___ / ____/
5 // / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
6 // / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
7 // \__/____/\___/\____/ .___/\___/ /_____/
8 // /_/
9 //
10 /// \file keyboard_internal.c
11 /// Definitions of internal keyboard functions.
12 ////////////////////////////////////////////////////////////////////////////////
13 
14 #include "../include/tscope5/keyboard_internal.h"
15 #include "../include/tscope5/system_internal.h"
16 #include "../include/tscope5/timer_internal.h"
17 
18 /// Is the keyboard subsystem installed?
20 
21 
22 ////////////////////////////////////////////////////////////////////////////////
23 /// Do some checks at the start of each keyboard function.
24 ///
25 /// \param calling_function Name the function that calls for
26 /// this check or installation.
27 ///
28 /// Checks whether the keyboard subsystem is installed. If not, the keyboard subsystem is installed.
29 ////////////////////////////////////////////////////////////////////////////////
30 void ts5_check_keyboard(char *calling_function)
31 {
32  ts5_log(TS5_LOGLEVEL_6, "%s: ts5_check_keyboard\n", calling_function);
33 
35  ts5_fatal("%s: tscope5 not installed\n", calling_function);
36  }
37 
38  if (_ts5_status.active_display == -1) {
39  ts5_fatal("%s: no active display available\n", calling_function);
40  }
41 
43  ts5_install_keyboard(calling_function);
44  }
45 }
46 
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Install the keyboard subsystem.
50 ///
51 /// \param calling_function Name the function that calls for this check or installation.
52 ///
53 /// This function is called automatically if necessary.
54 ////////////////////////////////////////////////////////////////////////////////
55 void ts5_install_keyboard(char *calling_function)
56 {
58  ts5_install_timer(calling_function);
59  }
60 
62 
64  ts5_log(TS5_LOGLEVEL_1, "%s: Installing Tscope5 keyboard\n",
65  calling_function);
66 
67  if (!al_install_keyboard()) {
68  ts5_fatal("%s: could not install tscope5 keyboard\n",
69  calling_function);
70  }
71 
72  al_register_event_source(_ts5_data.timer.response_queue,
73  al_get_keyboard_event_source());
74 
75  _ts5_status.timer.keyboard.num_buttons = TS5_KEY_MAX-1;
76  _ts5_status.timer.keyboard.num_defined_buttons = 0;
77  _ts5_status.timer.keyboard.num_active_buttons = 0;
78 
79  _ts5_status.timer.keyboard.button_press_defined =
80  (int *)al_malloc(sizeof(int)
81  * _ts5_status.timer.keyboard.num_buttons);
82 
83  _ts5_status.timer.keyboard.button_press_active =
84  (int *)al_malloc(sizeof(int)
85  * _ts5_status.timer.keyboard.num_buttons);
86 
87  _ts5_status.timer.keyboard.button_release_defined =
88  (int *)al_malloc(sizeof(int)
89  * _ts5_status.timer.keyboard.num_buttons);
90 
91  _ts5_status.timer.keyboard.button_release_active =
92  (int *)al_malloc(sizeof(int)
93  * _ts5_status.timer.keyboard.num_buttons);
94 
95  int i;
96  for (i=0; i<_ts5_status.timer.keyboard.num_buttons; i++) {
97  _ts5_status.timer.keyboard.button_press_defined[i] = 0;
98  _ts5_status.timer.keyboard.button_press_active[i] = 0;
99  _ts5_status.timer.keyboard.button_release_defined[i] = 0;
100  _ts5_status.timer.keyboard.button_release_active[i] = 0;
101  }
102 
103  atexit(ts5_uninstall_keyboard);
104  }
105 }
106 
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// Uninstall the keyboard subsystem.
110 ///
111 /// This function is called automatically at the end of the program.
112 ////////////////////////////////////////////////////////////////////////////////
114 {
116 
117  ts5_log(TS5_LOGLEVEL_1, "Uninstalling Tscope5 keyboard\n");
118 
119  _ts5_status.timer.keyboard.num_buttons = 0;
120  _ts5_status.timer.keyboard.num_defined_buttons = 0;
121  _ts5_status.timer.keyboard.num_active_buttons = 0;
122 
123  al_free(_ts5_status.timer.keyboard.button_press_defined);
124  _ts5_status.timer.keyboard.button_press_defined = NULL;
125 
126  al_free(_ts5_status.timer.keyboard.button_press_active);
127  _ts5_status.timer.keyboard.button_press_active = NULL;
128 
129  al_free(_ts5_status.timer.keyboard.button_release_defined);
130  _ts5_status.timer.keyboard.button_release_defined = NULL;
131 
132  al_free(_ts5_status.timer.keyboard.button_release_active);
133  _ts5_status.timer.keyboard.button_release_active = NULL;
134 
135  _ts5_status.timer.keyboard_is_response_device = 0;
136 
137  al_unregister_event_source(_ts5_data.timer.response_queue,
138  al_get_keyboard_event_source());
139 
140  al_uninstall_keyboard();
141 
143  }
144 }
145 
int _ts5_is_tscope5_installed
Is Tscope5 installed?
int _ts5_is_timer_installed
Is the timer subsystem installed?
void ts5_install_timer(char *calling_function)
Install the timer subsystem.
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
Definition: system.c:45
void ts5_check_keyboard(char *calling_function)
Do some checks at the start of each keyboard function.
void ts5_install_keyboard(char *calling_function)
Install the keyboard subsystem.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
Definition: system.c:533
int _ts5_is_keyboard_installed
Is the keyboard subsystem installed?
void ts5_uninstall_keyboard()
Uninstall the keyboard subsystem.