Tscope5
joystick.c
Go to the documentation of this file.
1 
2 
3 
4 
5 
6 
7 #include "../include/tscope5/joystick.h"
8 #include "../include/tscope5/timer.h"
9 #include "../include/tscope5/joystick_internal.h"
10 #include "../include/tscope5/system_internal.h"
11 
12 
17 
18 
19 
20 
32 int ts5_define_joystick_key(int device, int key)
33 {
34  ts5_check_joystick("ts5_define_joystick_key");
35  ts5_log(TS5_LOGLEVEL_3, "ts5_define_joystick_key(%d,%d)\n", device, key);
36 
37  if (device<1 || device>_ts5_status.timer_status.num_joystick) {
38  ts5_fatal("ts5_define_joystick_key: device argument is %d, number of joysticks is %d\n",
39  device, _ts5_status.timer_status.num_joystick);
40  }
41 
42  if (key==0) {
43  ts5_fatal("ts5_define_joystick_key: key argument is 0, response keys are numbered from 1\n");
44  }
45 
46  if (abs(key)>_ts5_status.timer_status.joystick[device-1].num_buttons) {
47  ts5_fatal("ts5_define_joystick_key: key argument is %d, number of joystick buttons for device",
48  " %d is %d\n", key, device, _ts5_status.timer_status.joystick[device-1].num_buttons);
49  }
50 
51  if (key>0 && _ts5_status.timer_status.joystick[device-1].button_press_defined[key-1]!=0) {
52  ts5_fatal("ts5_define_joystick_key: key press %d is already defined\n", key);
53  }
54 
55  if (key<0 && _ts5_status.timer_status.joystick[device-1].button_release_defined[-key-1]!=0) {
56  ts5_fatal("ts5_define_joystick_key: key release %d is already defined\n", key);
57  }
58 
59  _ts5_status.timer_status.joystick_is_response_device = 1;
60  _ts5_status.timer_status.num_defined_buttons++;
61  _ts5_status.timer_status.num_active_buttons++;
62  _ts5_status.timer_status.joystick[device-1].num_defined_buttons++;
63  _ts5_status.timer_status.joystick[device-1].num_active_buttons++;
64 
65  if (key>0) {
66  _ts5_status.timer_status.joystick[device-1].button_press_defined[key-1] =
67  _ts5_status.timer_status.num_defined_buttons;
68 
69  _ts5_status.timer_status.joystick[device-1].button_press_active[key-1] =
70  _ts5_status.timer_status.num_defined_buttons;
71  }
72  else {
73  _ts5_status.timer_status.joystick[device-1].button_release_defined[-key-1] =
74  _ts5_status.timer_status.num_defined_buttons;
75 
76  _ts5_status.timer_status.joystick[device-1].button_release_active[-key-1] =
77  _ts5_status.timer_status.num_defined_buttons;
78  }
79 
80  return _ts5_status.timer_status.num_defined_buttons;
81 }
82 
83 
85 
86