Update of /cvsroot/pure-data/abstractions/tb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22294
Modified Files: find_hid-help.pd find_hid.py le3dp.pd Log Message: improved find_hid searching capabilities
Index: find_hid.py =================================================================== RCS file: /cvsroot/pure-data/abstractions/tb/find_hid.py,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** find_hid.py 4 Dec 2005 18:11:08 -0000 1.1 --- find_hid.py 9 Dec 2005 12:50:06 -0000 1.2 *************** *** 22,43 **** from os import popen, listdir
def find (*args): name = "" for token in args: name+=" " + str(token) name = name.strip()
! events = filter(lambda x: "event" in x, listdir('/sys/class/input/')) ! ! for event in events: ! pipe = popen('udevinfo -a -p /sys/class/input/%s' % event)
! line = pipe.readline() ! while line: ! if name in line: ! print event ! return float(event.strip("event"))
! line = pipe.readline() ! pipe.close() return -1 --- 22,75 ---- from os import popen, listdir
+ def parse_device(event, rules): + pipe = popen('udevinfo -a -p /sys/class/input/%s' % event) + + line = pipe.readline() + while line: + line.strip() + if '==' in line: + setting, value = line.split('==') + setting = setting.strip() + if '{' in setting: + setting = setting.split('{')[1].split('}')[0] + value = value.strip().strip('"') + + if setting in rules: + if rules [setting] == value: + # we matched one rule, so we remove it from the pending rules + del rules[setting] + + line = pipe.readline() + + if len(rules) == 0: + pipe.close() + print event + return float(event.strip("event")) + + pipe.close() + return -1 + def find (*args): name = "" for token in args: name+=" " + str(token) + name = name.strip() + rules = name.split('" "') + rules = map (lambda x: x.strip('"'), rules)
! ruledict = dict()
! for rule in rules: ! setting, value = rule.split('=',1) ! ruledict[setting] = value ! rules = ruledict
! events = filter(lambda x: "event" in x, listdir('/sys/class/input/')) ! ! for event in events: ! ret = parse_device(event, dict(rules)) ! if ret != -1: ! return int(ret) ! return -1
Index: le3dp.pd =================================================================== RCS file: /cvsroot/pure-data/abstractions/tb/le3dp.pd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** le3dp.pd 20 Nov 2005 00:31:44 -0000 1.1 --- le3dp.pd 9 Dec 2005 12:50:06 -0000 1.2 *************** *** 110,114 **** #X connect 1 12 14 0; #X restore 51 266 pd buttons; - #X msg 38 60 find Logitech Extreme 3D; #X obj 38 172 prepend open; #X obj 38 84 py find_hid; --- 110,113 ---- *************** *** 121,135 **** #X text 116 220 abstraction to use a Logitech Extreme 3D Joystick with hid under linux; ! #X connect 0 0 7 0; #X connect 2 0 1 0; #X connect 2 1 3 0; ! #X connect 4 0 6 1; #X connect 5 0 8 0; ! #X connect 6 0 9 0; ! #X connect 7 0 11 0; ! #X connect 7 1 4 0; ! #X connect 8 0 2 0; ! #X connect 9 0 10 0; ! #X connect 9 1 5 0; ! #X connect 10 0 11 1; ! #X connect 11 0 8 0; --- 120,135 ---- #X text 116 220 abstraction to use a Logitech Extreme 3D Joystick with hid under linux; ! #X msg 38 60 find "product=Logitech Extreme 3D"; ! #X connect 0 0 6 0; #X connect 2 0 1 0; #X connect 2 1 3 0; ! #X connect 4 0 7 0; #X connect 5 0 8 0; ! #X connect 6 0 10 0; ! #X connect 6 1 13 0; ! #X connect 7 0 2 0; ! #X connect 8 0 9 0; ! #X connect 8 1 4 0; ! #X connect 9 0 10 1; ! #X connect 10 0 7 0; ! #X connect 13 0 5 1;
Index: find_hid-help.pd =================================================================== RCS file: /cvsroot/pure-data/abstractions/tb/find_hid-help.pd,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** find_hid-help.pd 4 Dec 2005 18:11:08 -0000 1.1 --- find_hid-help.pd 9 Dec 2005 12:50:06 -0000 1.2 *************** *** 3,10 **** #X obj 51 122 print; #X msg 51 65 reload; ! #X msg 158 69 find USB-PS/2 Optical Mouse; ! #X text 53 239 $Id$; #X text 49 153 find device in linux udevfs; #X connect 0 0 1 0; #X connect 2 0 0 0; ! #X connect 3 0 0 1; --- 3,12 ---- #X obj 51 122 print; #X msg 51 65 reload; ! #X text 53 239 $Id$ ! ; #X text 49 153 find device in linux udevfs; + #X msg 158 69 "manufacturer=Logitech" "product=USB-PS/2 Optical Mouse" + ; #X connect 0 0 1 0; #X connect 2 0 0 0; ! #X connect 5 0 0 1;