10 from sensor_msgs.msg
import Joy
12 import roslib; roslib.load_manifest(
"joy_mouse")
13 from sensor_msgs.msg
import Joy
19 lookup device by name attribute. You can check name by 20 udevadmin info -a -n /dev/input/mouse0 22 context = pyudev.Context()
23 for device
in context.list_devices(subsystem=
"input"):
24 for a
in device.attributes:
25 if a ==
"name" and device.attributes[a] == name:
26 for child
in device.children:
27 if child.sys_name.startswith(prefix):
28 return os.path.join(
"/dev",
"input", child.sys_name)
30 def main(device_name, autorepeat_rate, frame_id):
31 rospy.loginfo(
"reading %s" % (device_name))
32 joy_pub = rospy.Publisher(
'joy', Joy)
33 with open(device_name,
"rb" )
as tp_file:
37 while not rospy.is_shutdown():
38 if autorepeat_rate == 0:
41 r,w,e = select.select([tp_file], [], [], 1.0 / autorepeat_rate)
43 buf = os.read(tp_file.fileno(), 3)
49 bMiddle = prev_bMiddle
52 button = ord( buf[0] )
54 bMiddle = ( button & 0x4 ) > 0
55 bRight = ( button & 0x2 ) > 0
56 x,y = struct.unpack(
"bb", buf[1:] )
58 joy_msg.header.stamp = rospy.Time.now()
59 joy_msg.header.frame_id = frame_id
61 joy_msg.buttons = [bLeft, bMiddle, bRight]
62 joy_pub.publish(joy_msg)
64 prev_bMiddle = bMiddle
def lookupDeviceFileByNameAttribute(name, prefix="mouse")
def main(device_name, autorepeat_rate, frame_id)