8 #include "../include/tscope5/cedrusbox.h"
9 #include "../include/tscope5/cedrusbox_internal.h"
10 #include "../include/tscope5/system_internal.h"
34 ts5_check_cedrusbox(
"ts5_define_cedrusbox_key");
35 ts5_log(TS5_LOGLEVEL_3,
"ts5_define_cedrusbox_key(%d,%d)\n", device, key);
37 if (device<1 || device>_ts5_status.timer_status.num_cedrusbox) {
38 ts5_fatal(
"ts5_define_cedrusbox_key: device argument is %d,",
39 " number of cedrusboxes is %d\n", device, _ts5_status.timer_status.num_cedrusbox);
43 ts5_fatal(
"ts5_define_cedrusbox_key: key argument is 0, response keys are numbered from 1\n");
46 if (abs(key)>_ts5_status.timer_status.cedrusbox[device-1].num_buttons) {
47 ts5_fatal(
"ts5_define_cedrusbox_key: key argument is %d,",
48 " number of cedrusbox buttons for device %d is %d\n",
49 key, device, _ts5_status.timer_status.cedrusbox[device-1].num_buttons);
52 if (key>0 && _ts5_status.timer_status.cedrusbox[device-1].button_press_defined[key-1]!=0) {
53 ts5_fatal(
"ts5_define_cedrusbox_key: key press %d is already defined\n", key);
56 if (key<0 && _ts5_status.timer_status.cedrusbox[device-1].button_release_defined[-key-1]!=0) {
57 ts5_fatal(
"ts5_define_cedrusbox_key: key release %d is already defined\n", key);
60 _ts5_status.timer_status.cedrusbox_is_response_device = 1;
61 _ts5_status.timer_status.num_defined_buttons++;
62 _ts5_status.timer_status.num_active_buttons++;
63 _ts5_status.timer_status.cedrusbox[device-1].num_defined_buttons++;
64 _ts5_status.timer_status.cedrusbox[device-1].num_active_buttons++;
67 _ts5_status.timer_status.cedrusbox[device-1].button_press_defined[key-1] =
68 _ts5_status.timer_status.num_defined_buttons;
70 _ts5_status.timer_status.cedrusbox[device-1].button_press_active[key-1] =
71 _ts5_status.timer_status.num_defined_buttons;
75 _ts5_status.timer_status.cedrusbox[device-1].button_release_defined[-key-1] =
76 _ts5_status.timer_status.num_defined_buttons;
78 _ts5_status.timer_status.cedrusbox[device-1].button_release_active[-key-1] =
79 _ts5_status.timer_status.num_defined_buttons;
82 return _ts5_status.timer_status.num_defined_buttons;
114 ts5_check_cedrusbox(
"ts5_cedrusbox_set_parameter");
115 ts5_log(TS5_LOGLEVEL_4,
"ts5_cedrusbox_set_parameter(%d,%d,%d)\n", device, parameter, value);
117 if (_ts5_status.timer_status.cedrusbox[device-1].type!=TS5_CEDRUSBOX_SV1) {
118 ts5_fatal(
"ts5_cedrusbox_set_parameter: device %d is not a voice key\n", device);
121 int port_num = _ts5_status.timer_status.cedrusbox[device-1].port_num;
129 case TS5_CEDRUSBOX_LOCKINGLEVEL:
131 if (value != TS5_CEDRUSBOX_LOCK && value != TS5_CEDRUSBOX_UNLOCK) {
132 ts5_fatal(
"ts5_cedrusbox_set_parameter: TS5_CEDRUSBOX_LOCKINGLEVEL should be",
133 " TS5_CEDRUSBOX_LOCK or TS5_CEDRUSBOX_UNLOCK\n");
136 sprintf(command,
"f2%d", value);
139 case TS5_CEDRUSBOX_TRESHOLD:
144 if (value < min || value > max) {
145 ts5_fatal(
"ts5_cedrusbox_set_parameter: treshold should be",
146 " between min (%d) and max (%d)\n", min, max);
149 sprintf(command,
"b1%d", value);
152 case TS5_CEDRUSBOX_MIN_TRESHOLD:
156 if (value < 0 || value > max) {
157 ts5_fatal(
"ts5_cedrusbox_set_parameter: minimum treshold should be",
158 " between 0 and max (%d)\n", max);
161 sprintf(command,
"b6%d", value);
164 case TS5_CEDRUSBOX_MAX_TRESHOLD:
168 if (value < min || value > 255) {
169 ts5_fatal(
"ts5_cedrusbox_set_parameter: maximum treshold should be",
170 " between min (%d) and 255\n", min);
173 sprintf(command,
"b7%d", value);
176 case TS5_CEDRUSBOX_RISE_DELAY:
181 if (value < min || value > max) {
182 ts5_fatal(
"ts5_cedrusbox_set_parameter: rise delay should be",
183 " between min (%d) and max (%d)\n", min, max);
186 sprintf(command,
"b2%d", value);
189 case TS5_CEDRUSBOX_MIN_RISE_DELAY:
193 if (value < 0 || value > max) {
194 ts5_fatal(
"ts5_cedrusbox_set_parameter: minimum rise delay should be",
195 " between 0 and max (%d)\n", max);
198 sprintf(command,
"b4%d", value);
201 case TS5_CEDRUSBOX_MAX_RISE_DELAY:
205 if (value < min || value > 100) {
206 ts5_fatal(
"ts5_cedrusbox_set_parameter: maximum rise delay should be",
207 " between min (%d) and 100\n", min);
210 sprintf(command,
"b5%d", value);
213 case TS5_CEDRUSBOX_DROP_DELAY:
215 if (value < 0 || value > 255) {
216 ts5_fatal(
"ts5_cedrusbox_set_parameter: drop delay 0 and 255\n");
219 sprintf(command,
"b3%d", value);
223 ts5_fatal(
"ts5_cedrusbox_set_parameter: unknown parameter value (%d)\n", parameter);
226 ts5_write_cedrusbox(port_num, command, 4);
230 if (newval != value) {
231 ts5_fatal(
"ts5_cedrusbox_set_parameter: could not change parameter %d\n", parameter);
250 ts5_check_cedrusbox(
"ts5_cedrusbox_get_parameter");
251 ts5_log(TS5_LOGLEVEL_4,
"ts5_cedrusbox_get_parameter(%d,%d)\n", device, parameter);
253 if (_ts5_status.timer_status.cedrusbox[device-1].type!=TS5_CEDRUSBOX_SV1) {
254 ts5_fatal(
"ts5_cedrusbox_get_parameter: device %d is not a voice key\n", device);
257 int port_num = _ts5_status.timer_status.cedrusbox[device-1].port_num;
263 case TS5_CEDRUSBOX_LOCKINGLEVEL:
264 sprintf(command,
"_f2");
267 case TS5_CEDRUSBOX_TRESHOLD:
268 sprintf(command,
"_b1");
271 case TS5_CEDRUSBOX_MIN_TRESHOLD:
272 sprintf(command,
"_b6");
275 case TS5_CEDRUSBOX_MAX_TRESHOLD:
276 sprintf(command,
"_b7");
279 case TS5_CEDRUSBOX_RISE_DELAY:
280 sprintf(command,
"_b2");
283 case TS5_CEDRUSBOX_MIN_RISE_DELAY:
284 sprintf(command,
"_b4");
287 case TS5_CEDRUSBOX_MAX_RISE_DELAY:
288 sprintf(command,
"_b5");
291 case TS5_CEDRUSBOX_DROP_DELAY:
292 sprintf(command,
"_b3");
296 ts5_fatal(
"ts5_cedrusbox_get_parameter: unknown parameter value (%d)\n", parameter);
299 ts5_write_cedrusbox(port_num, command, 3);
301 char serial_buff[TS5_MAX_CHAR];
302 serial_buff[0] =
'\0';
303 ts5_read_cedrusbox(port_num, serial_buff, 4);
306 value = serial_buff[3];