17 #include "../include/tscope5/cedrusbox.h"
18 #include "../include/tscope5/cedrusbox_internal.h"
19 #include "../include/tscope5/system_internal.h"
44 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_cedrusbox_button(%d,%d)\n", device, button);
46 if (device<1 || device>_ts5_status.timer.num_cedrusboxes) {
47 ts5_fatal(
"%s: %s %d, %s %d\n",
"ts5_define_cedrusbox_button",
48 "device argument is", device,
"number of cedrusboxes is",
49 _ts5_status.timer.num_cedrusboxes);
53 ts5_fatal(
"%s: %s\n",
"ts5_define_cedrusbox_button",
54 "button argument is 0, response buttons are numbered from 1");
57 if (abs(button)>_ts5_status.timer.cedrusbox[device-1].num_buttons) {
58 ts5_fatal(
"%s: %s %d, %s %d is %d\n",
"ts5_define_cedrusbox_button",
59 "button argument is ", button,
60 "number of cedrusbox buttons for device", device,
61 _ts5_status.timer.cedrusbox[device-1].num_buttons);
64 if (button>0 && _ts5_status.timer.cedrusbox[device-1]
65 .button_press_defined[button-1] !=0) {
66 ts5_fatal(
"%s: %s %d %s\n",
"ts5_define_cedrusbox_button",
67 "button press", button,
"is already defined");
70 if (button<0 && _ts5_status.timer.cedrusbox[device-1]
71 .button_release_defined[-button-1]!=0) {
72 ts5_fatal(
"%s: %s %d %s\n",
"ts5_define_cedrusbox_button",
73 "button release", button,
"is already defined");
76 _ts5_status.timer.cedrusbox_is_response_device = 1;
77 _ts5_status.timer.num_defined_buttons++;
78 _ts5_status.timer.num_active_buttons++;
79 _ts5_status.timer.cedrusbox[device-1].num_defined_buttons++;
80 _ts5_status.timer.cedrusbox[device-1].num_active_buttons++;
83 _ts5_status.timer.cedrusbox[device-1]
84 .button_press_defined[button-1] =
85 _ts5_status.timer.num_defined_buttons;
87 _ts5_status.timer.cedrusbox[device-1]
88 .button_press_active[button-1] =
89 _ts5_status.timer.num_defined_buttons;
93 _ts5_status.timer.cedrusbox[device-1]
94 .button_release_defined[-button-1] =
95 _ts5_status.timer.num_defined_buttons;
97 _ts5_status.timer.cedrusbox[device-1]
98 .button_release_active[-button-1] =
99 _ts5_status.timer.num_defined_buttons;
102 return _ts5_status.timer.num_defined_buttons;
114 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_num_cedrusboxes()\n");
116 return _ts5_status.timer.num_cedrusboxes;
130 ts5_log(TS5_LOGLEVEL_4,
"ts5_get_num_cedrusbox_buttons(%d)\n", device);
132 return _ts5_status.timer.cedrusbox[device-1].num_buttons;
173 ts5_log(TS5_LOGLEVEL_4,
"ts5_cedrusbox_set_parameter(%d,%d,%d)\n",
174 device, parameter, value);
176 if (_ts5_status.timer.cedrusbox[device-1].type!=TS5_CEDRUSBOX_SV1) {
177 ts5_fatal(
"%s: %s %d %s\n",
"ts5_cedrusbox_set_parameter",
178 "device", device,
"is not a voice key");
182 int pause_cedrusbox = _ts5_data.timer.cedrusbox_thread &&
183 !_ts5_data.timer.cedrusbox_thread_is_paused;
185 if (pause_cedrusbox) {
186 al_join_thread(_ts5_data.timer.cedrusbox_thread, NULL);
187 _ts5_data.timer.cedrusbox_thread_is_paused = 1;
190 int port_num = _ts5_status.timer.cedrusbox[device-1].port_num;
198 case TS5_CEDRUSBOX_LOCKINGLEVEL:
200 if (value != TS5_CEDRUSBOX_LOCK && value != TS5_CEDRUSBOX_UNLOCK) {
201 ts5_fatal(
"%s: %s %s\n",
"ts5_cedrusbox_set_parameter",
202 "TS5_CEDRUSBOX_LOCKINGLEVEL should be",
203 "TS5_CEDRUSBOX_LOCK or TS5_CEDRUSBOX_UNLOCK");
206 sprintf(command,
"f2%d", value);
209 case TS5_CEDRUSBOX_TRESHOLD:
214 if (value < min || value > max) {
215 ts5_fatal(
"%s: %s min (%d) and max(%d)\n",
216 "ts5_cedrusbox_set_parameter",
217 "treshold should be between", min, max);
220 sprintf(command,
"b1%d", value);
223 case TS5_CEDRUSBOX_MIN_TRESHOLD:
226 if (value < 0 || value > max) {
227 ts5_fatal(
"%s: %s (%d)\n",
"ts5_cedrusbox_set_parameter",
228 "minimum treshold should be between 0 and max", max);
231 sprintf(command,
"b6%d", value);
234 case TS5_CEDRUSBOX_MAX_TRESHOLD:
238 if (value < min || value > 255) {
240 "ts5_cedrusbox_set_parameter",
241 "maximum treshold should be between", min);
244 sprintf(command,
"b7%d", value);
247 case TS5_CEDRUSBOX_RISE_DELAY:
252 if (value < min || value > max) {
253 ts5_fatal(
"%s: %s min (%d) and max (%d)",
254 "ts5_cedrusbox_set_parameter",
255 "rise delay should be between", min, max);
258 sprintf(command,
"b2%d", value);
261 case TS5_CEDRUSBOX_MIN_RISE_DELAY:
265 if (value < 0 || value > max) {
266 ts5_fatal(
"%s: %s (%d)\n",
"ts5_cedrusbox_set_parameter",
267 "minimum rise delay should be between 0 and max", max);
270 sprintf(command,
"b4%d", value);
273 case TS5_CEDRUSBOX_MAX_RISE_DELAY:
277 if (value < min || value > 100) {
279 "ts5_cedrusbox_set_parameter",
280 "maximum rise delay should be between", min);
283 sprintf(command,
"b5%d", value);
286 case TS5_CEDRUSBOX_DROP_DELAY:
288 if (value < 0 || value > 255) {
289 ts5_fatal(
"%s: %s\n",
"ts5_cedrusbox_set_parameter",
290 "drop delay should be between 0 and 255\n");
293 sprintf(command,
"b3%d", value);
297 ts5_fatal(
"ts5_cedrusbox_set_parameter: unknown parameter value (%d)\n",
305 if (newval != value) {
306 ts5_fatal(
"%s: %s %d\n",
"ts5_cedrusbox_set_parameter",
307 "could not change parameter", parameter);
310 if (pause_cedrusbox) {
311 al_start_thread(_ts5_data.timer.cedrusbox_thread);
312 _ts5_data.timer.cedrusbox_thread_is_paused = 0;
332 ts5_log(TS5_LOGLEVEL_4,
"ts5_cedrusbox_get_parameter(%d,%d)\n",
335 if (_ts5_status.timer.cedrusbox[device-1].type!=TS5_CEDRUSBOX_SV1) {
336 ts5_fatal(
"ts5_cedrusbox_get_parameter: device %d is not a voice key\n",
340 int port_num = _ts5_status.timer.cedrusbox[device-1].port_num;
346 case TS5_CEDRUSBOX_LOCKINGLEVEL:
347 sprintf(command,
"_f2");
350 case TS5_CEDRUSBOX_TRESHOLD:
351 sprintf(command,
"_b1");
354 case TS5_CEDRUSBOX_MIN_TRESHOLD:
355 sprintf(command,
"_b6");
358 case TS5_CEDRUSBOX_MAX_TRESHOLD:
359 sprintf(command,
"_b7");
362 case TS5_CEDRUSBOX_RISE_DELAY:
363 sprintf(command,
"_b2");
366 case TS5_CEDRUSBOX_MIN_RISE_DELAY:
367 sprintf(command,
"_b4");
370 case TS5_CEDRUSBOX_MAX_RISE_DELAY:
371 sprintf(command,
"_b5");
374 case TS5_CEDRUSBOX_DROP_DELAY:
375 sprintf(command,
"_b3");
379 ts5_fatal(
"%s: %s (%d)\n",
"ts5_cedrusbox_get_parameter",
380 "unknown parameter value", parameter);
384 int pause_cedrusbox = _ts5_data.timer.cedrusbox_thread &&
385 !_ts5_data.timer.cedrusbox_thread_is_paused;
387 if (pause_cedrusbox) {
388 al_join_thread(_ts5_data.timer.cedrusbox_thread, NULL);
389 _ts5_data.timer.cedrusbox_thread_is_paused = 1;
396 char serial_buff[TS5_MAX_CHAR];
397 serial_buff[0] =
'\0';
401 value = serial_buff[3];
404 if (pause_cedrusbox) {
405 al_start_thread(_ts5_data.timer.cedrusbox_thread);
406 _ts5_data.timer.cedrusbox_thread_is_paused = 0;