Tscope5
cedrusbox.c
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // __ ______
4 // / /_______________ ____ ___ / ____/
5 // / __/ ___/ ___/ __ \/ __ \/ _ \ /___ )
6 // / /_(__ ) /__/ /_/ / /_/ / __/ ____/ /
7 // \__/____/\___/\____/ .___/\___/ /_____/
8 // /_/
9 //
10 /// \file cedrusbox.c
11 /// Definitions of cedrusbox functions.
12 /// \example cedrusbox01.c
13 /// \example cedrusbox02.c
14 /// \todo SV1 testen
15 ////////////////////////////////////////////////////////////////////////////////
16 
17 
18 #include "../include/tscope5/cedrusbox.h"
19 #include "../include/tscope5/cedrusbox_internal.h"
20 #include "../include/tscope5/system_internal.h"
21 
22 
23 ////////////////////////////////////////////////////////////////////////////////
24 /// @name Response registration
25 /// Cedrusboxes can be used as response devices.
26 /// See timer.c for more information about response registration.
27 //@{
28 ////////////////////////////////////////////////////////////////////////////////
29 
30 
31 ////////////////////////////////////////////////////////////////////////////////
32 /// Define a cedrusbox button as a response button.
33 ///
34 /// \param device Number of the cedrusbox (devices are numbered from 1).
35 /// \param button Number of the button (buttons are counted from 1).
36 ///
37 /// \return The reponse number associated with the button.
38 ///
39 /// Give a positive number if you want to monitor button press events,
40 /// a negative number if you want to monitor button release events.
41 ////////////////////////////////////////////////////////////////////////////////
42 int ts5_define_cedrusbox_button(int device, int button)
43 {
44  ts5_check_cedrusbox("ts5_define_cedrusbox_button");
45  ts5_log(TS5_LOGLEVEL_3, "ts5_define_cedrusbox_button(%d,%d)\n", device, button);
46 
47  if (device<1 || device>_ts5_status.timer.num_cedrusboxes) {
48  ts5_fatal("%s: %s %d, %s %d\n", "ts5_define_cedrusbox_button",
49  "device argument is", device, "number of cedrusboxes is",
50  _ts5_status.timer.num_cedrusboxes);
51  }
52 
53  if (button==0) {
54  ts5_fatal("%s: %s\n", "ts5_define_cedrusbox_button",
55  "button argument is 0, response buttons are numbered from 1");
56  }
57 
58  if (abs(button)>_ts5_status.timer.cedrusbox[device-1].num_buttons) {
59  ts5_fatal("%s: %s %d, %s %d is %d\n", "ts5_define_cedrusbox_button",
60  "button argument is ", button,
61  "number of cedrusbox buttons for device", device,
62  _ts5_status.timer.cedrusbox[device-1].num_buttons);
63  }
64 
65  if (button>0 && _ts5_status.timer.cedrusbox[device-1]
66  .button_press_defined[button-1] !=0) {
67  ts5_fatal("%s: %s %d %s\n", "ts5_define_cedrusbox_button",
68  "button press", button, "is already defined");
69  }
70 
71  if (button<0 && _ts5_status.timer.cedrusbox[device-1]
72  .button_release_defined[-button-1]!=0) {
73  ts5_fatal("%s: %s %d %s\n", "ts5_define_cedrusbox_button",
74  "button release", button, "is already defined");
75  }
76 
77  _ts5_status.timer.cedrusbox_is_response_device = 1;
78  _ts5_status.timer.num_defined_buttons++;
79  _ts5_status.timer.num_active_buttons++;
80  _ts5_status.timer.cedrusbox[device-1].num_defined_buttons++;
81  _ts5_status.timer.cedrusbox[device-1].num_active_buttons++;
82 
83  if (button>0) {
84  _ts5_status.timer.cedrusbox[device-1]
85  .button_press_defined[button-1] =
86  _ts5_status.timer.num_defined_buttons;
87 
88  _ts5_status.timer.cedrusbox[device-1]
89  .button_press_active[button-1] =
90  _ts5_status.timer.num_defined_buttons;
91 
92  }
93  else {
94  _ts5_status.timer.cedrusbox[device-1]
95  .button_release_defined[-button-1] =
96  _ts5_status.timer.num_defined_buttons;
97 
98  _ts5_status.timer.cedrusbox[device-1]
99  .button_release_active[-button-1] =
100  _ts5_status.timer.num_defined_buttons;
101  }
102 
103  return _ts5_status.timer.num_defined_buttons;
104 }
105 
106 
107 ////////////////////////////////////////////////////////////////////////////////
108 /// Get the number of cedrusboxes that are connected to the system.
109 ///
110 /// \return The number of cedrusboxes that are connected to the system.
111 ////////////////////////////////////////////////////////////////////////////////
113 {
114  ts5_check_cedrusbox("ts5_get_num_cedrusboxes");
115  ts5_log(TS5_LOGLEVEL_4, "ts5_get_num_cedrusboxes()\n");
116 
117  return _ts5_status.timer.num_cedrusboxes;
118 }
119 
120 
121 ////////////////////////////////////////////////////////////////////////////////
122 /// Get the number of buttons available on a cedrusbox.
123 ///
124 /// \param device Number of the cedrusbox (devices are numbered from 1).
125 ///
126 /// \return The number of buttons on the cedrusbox.
127 ////////////////////////////////////////////////////////////////////////////////
129 {
130  ts5_check_cedrusbox("ts5_get_num_cedrusbox_buttons");
131  ts5_log(TS5_LOGLEVEL_4, "ts5_get_num_cedrusbox_buttons(%d)\n", device);
132 
133  if (device<1 || device>_ts5_status.timer.num_cedrusboxes) {
134  ts5_fatal("%s: %s %d, %s %d\n", "ts5_get_num_cedrusbox_buttons",
135  "device argument is", device, "number of cedrusboxes is",
136  _ts5_status.timer.num_cedrusboxes);
137  }
138 
139  return _ts5_status.timer.cedrusbox[device-1].num_buttons;
140 }
141 
142 
143 ////////////////////////////////////////////////////////////////////////////////
144 //@}
145 ////////////////////////////////////////////////////////////////////////////////
146 
147 
148 ////////////////////////////////////////////////////////////////////////////////
149 /// @name Trigger input
150 /// Cedrusboxes can be used as trigger input devices.
151 /// See timer.c for more information about trigger input.
152 //@{
153 ////////////////////////////////////////////////////////////////////////////////
154 
155 
156 ////////////////////////////////////////////////////////////////////////////////
157 /// Define a cedrusbox as a trigger input device
158 ///
159 /// \param device Number of the cedrusbox (devices are numbered from 1).
160 ////////////////////////////////////////////////////////////////////////////////
162 {
163  ts5_check_cedrusbox("ts5_define_cedrusbox_trigger_input");
164  ts5_log(TS5_LOGLEVEL_3, "ts5_define_cedrusbox_trigger_input(%d)\n", device);
165 
166  if (device<1 || device>_ts5_status.timer.num_cedrusboxes) {
167  ts5_fatal("%s: %s %d, %s %d\n", "ts5_define_cedrusbox_trigger_input",
168  "device argument is", device, "number of cedrusboxes is",
169  _ts5_status.timer.num_cedrusboxes);
170  }
171 
172  _ts5_status.timer.cedrusbox_is_trigger_device = 1;
173  _ts5_status.timer.cedrusbox[device-1].is_trigger_input_device = 1;
174 }
175 
176 
177 ////////////////////////////////////////////////////////////////////////////////
178 /// Turn on cedrusbox trigger input simulation.
179 ///
180 /// \param device Number of the cedrusbox (devices are numbered from 1).
181 /// \param interval Interval in seconds between two triggers.
182 ////////////////////////////////////////////////////////////////////////////////
183 void ts5_simulate_cedrusbox_trigger_input(int device, double interval)
184 {
185  ts5_check_cedrusbox("ts5_simulate_cedrusbox_trigger_input");
186  ts5_log(TS5_LOGLEVEL_3, "ts5_simulate_cedrusbox_trigger_input(%d,%f)\n",
187  device, interval);
188 
189  if (device<1 || device>_ts5_status.timer.num_cedrusboxes) {
190  ts5_fatal("%s: %s %d, %s %d\n", "ts5_simulate_cedrusbox_trigger_input",
191  "device argument is", device, "number of cedrusboxes is",
192  _ts5_status.timer.num_cedrusboxes);
193  }
194 
195  _ts5_status.timer.cedrusbox[device-1].simulate_trigger_input = 1;
196 
197  _ts5_status.timer.cedrusbox[device-1].trigger_simulation_interval =
198  interval;
199 }
200 
201 ////////////////////////////////////////////////////////////////////////////////
202 //@}
203 ////////////////////////////////////////////////////////////////////////////////
204 
void ts5_simulate_cedrusbox_trigger_input(int device, double interval)
Turn on cedrusbox trigger input simulation.
Definition: cedrusbox.c:183
void ts5_log(const unsigned int level, const char *format,...)
Send info to a logging window.
Definition: system.c:45
int ts5_define_cedrusbox_button(int device, int button)
Define a cedrusbox button as a response button.
Definition: cedrusbox.c:42
int ts5_get_num_cedrusboxes()
Get the number of cedrusboxes that are connected to the system.
Definition: cedrusbox.c:112
int ts5_get_num_cedrusbox_buttons(int device)
Get the number of buttons available on a cedrusbox.
Definition: cedrusbox.c:128
void ts5_define_cedrusbox_trigger_input(int device)
Define a cedrusbox as a trigger input device.
Definition: cedrusbox.c:161
void ts5_check_cedrusbox(char *calling_function)
Do some checks at the start of each cedrusbox function.
void ts5_fatal(const char *format,...)
Exit safely with an error message.
Definition: system.c:533