Tscope5
parport.c
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 #include "../include/tscope5/parport.h"
8 #include "../include/tscope5/timer.h"
9 #include "../include/tscope5/parport_internal.h"
10 #include "../include/tscope5/system_internal.h"
11 
12 #ifdef ALLEGRO_WINDOWS
13  #include <windows.h>
14  HINSTANCE hLib;
15  typedef short (_stdcall *inbptr)(short portaddr);
16  typedef short (_stdcall *outbptr)(short portaddr, short value);
17  inbptr inb;
18  outbptr outb;
19 
20 #elif defined ALLEGRO_UNIX
21  #include <unistd.h>
22  #include <sys/io.h>
23 
24 #endif
25 
26 
31 
32 
33 
34 
46 int ts5_define_parport_key(int device, int key)
47 {
48  ts5_check_parport("ts5_define_parport_key");
49  ts5_log(TS5_LOGLEVEL_3, "ts5_define_parport_key(%d,%d)\n", device, key);
50 
51  if (device<1 || device>_ts5_status.timer_status.num_parport) {
52  ts5_fatal("ts5_define_parport_key: device argument is %d, number of parallel ports is %d\n",
53  device, _ts5_status.timer_status.num_parport);
54  }
55 
56  if (_ts5_status.timer_status.parport[device-1].is_trigger_input_device) {
57  ts5_fatal("ts5_define_parport_key: parallel port %d is already defined as a trigger input device\n",
58  device);
59  }
60 
61  if (_ts5_status.timer_status.parport[device-1].is_trigger_output_device) {
62  ts5_fatal("ts5_define_parport_key: parallel port %d is already defined as a trigger output device\n",
63  device);
64  }
65 
66  if (key==0) {
67  ts5_fatal("ts5_define_parport_key: key argument is 0, response keys are numbered from 1\n");
68  }
69 
70  if (abs(key)>_ts5_status.timer_status.parport[device-1].num_buttons) {
71  ts5_fatal("ts5_define_parport_key: key argument is %d",
72  ", number of parport buttons for device %d is %d\n",
73  key, device, _ts5_status.timer_status.parport[device-1].num_buttons);
74  }
75 
76  if (key>0 && _ts5_status.timer_status.parport[device-1].button_press_defined[key-1]!=0) {
77  ts5_fatal("ts5_define_parport_key: key press %d is already defined\n", key);
78  }
79 
80  if (key<0 && _ts5_status.timer_status.parport[device-1].button_release_defined[-key-1]!=0) {
81  ts5_fatal("ts5_define_parport_key: key release %d is already defined\n", key);
82  }
83 
84  _ts5_status.timer_status.parport_is_response_device = 1;
85  _ts5_status.timer_status.num_defined_buttons++;
86  _ts5_status.timer_status.num_active_buttons++;
87  _ts5_status.timer_status.parport[device-1].num_defined_buttons++;
88  _ts5_status.timer_status.parport[device-1].num_active_buttons++;
89 
90  if (key>0) {
91  _ts5_status.timer_status.parport[device-1].button_press_defined[key-1] =
92  _ts5_status.timer_status.num_defined_buttons;
93 
94  _ts5_status.timer_status.parport[device-1].button_press_active[key-1] =
95  _ts5_status.timer_status.num_defined_buttons;
96  }
97  else {
98  _ts5_status.timer_status.parport[device-1].button_release_defined[-key-1] =
99  _ts5_status.timer_status.num_defined_buttons;
100 
101  _ts5_status.timer_status.parport[device-1].button_release_active[-key-1] =
102  _ts5_status.timer_status.num_defined_buttons;
103  }
104 
105  return _ts5_status.timer_status.num_defined_buttons;
106 }
107 
108 
131 double ts5_set_parport_button_debounce_time(int device, double button_debounce_time)
132 {
133  ts5_check_parport("ts5_set_parport_button_debounce_time");
134  ts5_log(TS5_LOGLEVEL_4, "ts5_set_parport_button_debounce_time(%d,%f)\n", device, button_debounce_time);
135 
136  if (device<1 || device>_ts5_status.timer_status.num_parport) {
137  ts5_fatal("ts5_set_parport_button_debounce_time: device argument is %d, number of parallel ports is %d\n",
138  device, _ts5_status.timer_status.num_parport);
139  }
140 
141  if (button_debounce_time < 0.0) {
142  ts5_fatal("ts5_set_parport_button_debounce_time: debounce time should be positive (is %f)\n", button_debounce_time);
143  }
144 
145  double retval = _ts5_status.timer_status.parport[device-1].button_debounce_time;
146 
147  _ts5_status.timer_status.parport[device-1].button_debounce_time = button_debounce_time;
148 
149  ts5_log(TS5_LOGLEVEL_4, "ts5_set_parport_button_debounce_time: set debounce time of device %d to %f (was %f)\n",
150  device, _ts5_status.timer_status.parport[device-1].button_debounce_time, retval);
151 
152  return retval;
153 }
154 
155 
164 {
165  ts5_check_parport("ts5_get_parport_button_debounce_time");
166  ts5_log(TS5_LOGLEVEL_4, "ts5_get_parport_button_debounce_time(%d)\n", device);
167 
168  if (device<1 || device>_ts5_status.timer_status.num_parport) {
169  ts5_fatal("ts5_get_parport_button_debounce_time: device argument is %d, number of parallel ports is %d\n",
170  device, _ts5_status.timer_status.num_parport);
171  }
172 
173  return _ts5_status.timer_status.parport[device-1].button_debounce_time;
174 }
175 
176 
178 
179 
180 
181 
186 
187 
188 
189 
196 {
197  ts5_check_parport("ts5_define_parport_trigger_input");
198  ts5_log(TS5_LOGLEVEL_3, "ts5_define_parport_trigger_input(%d)\n", device);
199 
200  if (device<1 || device>_ts5_status.timer_status.num_parport) {
201  ts5_fatal("ts5_define_parport_trigger_input: device argument is %d, number of parallel ports is %d\n",
202  device, _ts5_status.timer_status.num_parport);
203  }
204 
205  ts5_set_parport_trigger_input("ts5_define_parport_trigger_input", device);
206 }
207 
208 
216 void ts5_simulate_parport_trigger_input(int device, unsigned char value, double interval)
217 {
218  ts5_check_parport("ts5_simulate_parport_trigger_input");
219  ts5_log(TS5_LOGLEVEL_3, "ts5_simulate_parport_trigger_input(%d,%d,%f)\n", device, value, interval);
220 
221  if (device<1 || device>_ts5_status.timer_status.num_parport) {
222  ts5_fatal("ts5_simulate_parport_trigger_input: device argument is %d, number of parallel ports is %d\n",
223  device, _ts5_status.timer_status.num_parport);
224  }
225 
226  _ts5_status.timer_status.parport[device-1].simulate_trigger_input = value;
227  _ts5_status.timer_status.parport[device-1].trigger_simulation_interval = interval;
228 }
229 
230 
239 double ts5_set_parport_trigger_debounce_time(int device, double trigger_debounce_time)
240 {
241  ts5_check_parport("ts5_set_parport_trigger_debounce_time");
242  ts5_log(TS5_LOGLEVEL_4, "ts5_set_parport_trigger_debounce_time(%d,%f)\n", device, trigger_debounce_time);
243 
244  if (device<1 || device>_ts5_status.timer_status.num_parport) {
245  ts5_fatal("ts5_set_parport_trigger_debounce_time: device argument is %d, number of parallel ports is %d\n",
246  device, _ts5_status.timer_status.num_parport);
247  }
248 
249  if (trigger_debounce_time < 0.0) {
250  ts5_fatal("ts5_set_parport_trigger_debounce_time: debounce time should be positive (is %f)\n", trigger_debounce_time);
251  }
252 
253  double retval = _ts5_status.timer_status.parport[device-1].trigger_debounce_time;
254 
255  _ts5_status.timer_status.parport[device-1].trigger_debounce_time = trigger_debounce_time;
256 
257  ts5_log(TS5_LOGLEVEL_4, "ts5_set_parport_trigger_debounce_time: set debounce time of device %d to %f (was %f)\n",
258  device, _ts5_status.timer_status.parport[device-1].trigger_debounce_time, retval);
259 
260  return retval;
261 }
262 
263 
272 {
273  ts5_check_parport("ts5_get_parport_trigger_debounce_time");
274  ts5_log(TS5_LOGLEVEL_4, "ts5_get_parport_trigger_debounce_time(%d)\n", device);
275 
276  if (device<1 || device>_ts5_status.timer_status.num_parport) {
277  ts5_fatal("ts5_get_parport_trigger_debounce_time: device argument is %d, number of parallel ports is %d\n",
278  device, _ts5_status.timer_status.num_parport);
279  }
280 
281  return _ts5_status.timer_status.parport[device-1].trigger_debounce_time;
282 }
283 
284 
291 void ts5_send_parport_trigger(int device, unsigned char value)
292 {
293  ts5_check_parport("ts5_send_parport_trigger");
294  ts5_log(TS5_LOGLEVEL_3, "ts5_send_parport_trigger(%d,%d)\n", device, value);
295 
296  if (device<1 || device>_ts5_status.timer_status.num_parport) {
297  ts5_fatal("ts5_send_parport_trigger: device argument is %d, number of parallel ports is %d\n",
298  device, _ts5_status.timer_status.num_parport);
299  }
300 
301  ts5_set_parport_trigger_output("ts5_send_parport_trigger", device);
302 
303  #ifndef ALLEGRO_MACOSX
304  short data_register[] = {TS5_PARPORT_1_DATA, TS5_PARPORT_2_DATA, TS5_PARPORT_3_DATA};
305 
306  #endif
307 
308  #ifdef ALLEGRO_WINDOWS
309  outb((short)data_register[device-1], value);
310  ts5_wait(_ts5_status.timer_status.parport[device-1].trigger_output_time);
311  outb((short)data_register[device-1], 0);
312 
313  #elif defined ALLEGRO_UNIX
314  outb(value, (short)data_register[device-1]);
315  ts5_wait(_ts5_status.timer_status.parport[device-1].trigger_output_time);
316  outb(0, (short)data_register[device-1]);
317 
318  #endif
319 }
320 
321 
332 double ts5_set_parport_trigger_output_time(int device, double trigger_output_time)
333 {
334  ts5_check_parport("ts5_set_parport_trigger_output_time");
335  ts5_log(TS5_LOGLEVEL_4, "ts5_set_parport_trigger_output_time(%d,%f)\n", device, trigger_output_time);
336 
337  if (device<1 || device>_ts5_status.timer_status.num_parport) {
338  ts5_fatal("ts5_set_parport_trigger_output_time: device argument is %d, number of parallel ports is %d\n",
339  device, _ts5_status.timer_status.num_parport);
340  }
341 
342  if (trigger_output_time < 0.0) {
343  ts5_fatal("ts5_set_parport_trigger_output_time: output time should be positive (is %f)\n", trigger_output_time);
344  }
345 
346  double retval = _ts5_status.timer_status.parport[device-1].trigger_output_time;
347 
348  _ts5_status.timer_status.parport[device-1].trigger_output_time = trigger_output_time;
349 
350  ts5_log(TS5_LOGLEVEL_4, "ts5_set_parport_trigger_output_time: set output time of device %d to %f (was %f)\n",
351  device, _ts5_status.timer_status.parport[device-1].trigger_output_time, retval);
352 
353  return retval;
354 }
355 
356 
365 {
366  ts5_check_parport("ts5_get_parport_trigger_output_time");
367  ts5_log(TS5_LOGLEVEL_4, "ts5_get_parport_trigger_output_time(%d)\n", device);
368 
369  if (device<1 || device>_ts5_status.timer_status.num_parport) {
370  ts5_fatal("ts5_get_parport_trigger_output_time: device argument is %d, number of parallel ports is %d\n",
371  device, _ts5_status.timer_status.num_parport);
372  }
373 
374  return _ts5_status.timer_status.parport[device-1].trigger_output_time;
375 }
376 
377 
379 
380