Go to the documentation of this file.00001 from Phidgets.Manager import Manager
00002 from Phidgets.Devices.IR import IR, IRCode, IRCodeInfo
00003 from Phidgets.Events.Events import AttachEventArgs, DetachEventArgs, ErrorEventArgs, IRCodeEventArgs, IRLearnEventArgs, IRRawDataEventArgs
00004 import time
00005
00006 class ROSIr(object):
00007 code_read = False
00008 def __init__(self):
00009 self.attach()
00010
00011 def attach(self):
00012 m = Manager()
00013 m.openManager()
00014 time.sleep(1)
00015
00016 d = m.getAttachedDevices()[0]
00017 self.ir = IR()
00018 self.ir.openPhidget(d.getSerialNum())
00019
00020
00021
00022 def recv_learn_handler(self, e):
00023 self.code_read = False
00024
00025 def learn(self):
00026 self.ir.setOnIRCodeHandler(self.recv_learn_handler)
00027 while not self.code_read:
00028 try:
00029 learned_code = self.ir.getLastLearnedCode()
00030 self.code_read = True
00031 return learned_code.Code, learned_code.CodeInfo
00032 except KeyboardInterrupt:
00033 return None, None
00034 break
00035 except:
00036 pass
00037 time.sleep(0.1)