13 roslib.load_manifest(
"jsk_teleop_joy")
17 if hasattr(__builtins__,
'raw_input'):
30 devices = pygame.midi.get_count()
31 print(
"===========================================")
32 print(
"First, we choose device name:")
33 for d
in range(devices):
34 info = pygame.midi.get_device_info(d)
36 print(
" [%d] %s (%s)" % (d, info[1],
"input"))
38 print(
" [%d] %s (%s)" % (d, info[1],
"output"))
39 val =
input(
"Please select the device by number[%d-%d]:" % (0, d))
41 parsed_number = int(val)
42 if parsed_number >= 0
and parsed_number <= d:
43 name = pygame.midi.get_device_info(parsed_number)[1]
44 G_DEVICE_INFO[
"device_name"] = name
46 print(
"device_name: %s" % (name))
49 raise ParseException(
"please input number bewtween %d to %d" % (0, d))
51 raise ParseException(
"please input number")
55 print(
"===========================================")
56 print(
"Please move ALL the inputs")
57 print(
"===========================================")
58 print(
"The order you move them will be mapped into Joy/axes.")
59 print(
"If you want to finish analog mapping, please type 'q'")
62 ready = select.select([sys.stdin], [], [], 0.1)[0]
64 line = sys.stdin.readline()
65 if line.startswith(
"q"):
66 print(
"We installed %d analog inputs" % (len(analog_configs)))
67 G_DEVICE_INFO[
"analogs"] = analog_configs
69 while controller.poll():
70 data = controller.read(1)
73 (command, index, val) =
MIDIParse(elem_set)
74 if (command, index)
not in analog_configs:
75 print(
"(%d, %d) installing into %d" % (command, index, len(analog_configs)))
76 analog_configs.append((command, index))
77 except MIDIException
as e:
78 print(
"(%d, %d, %d) is not supported" % (elem_set[0][0], elem_set[0][1], elem_set[0][2]))
86 except ParseException
as e:
90 controller = pygame.midi.Input(device_num)
92 f = open(
'/tmp/midi.yaml',
'w')
93 f.write(yaml.dump(G_DEVICE_INFO))
95 print(
"writing the configuration to /tmp/midi.yaml")
97 if __name__ ==
"__main__":
def configAnalogInputs(controller)