コード例 #1
0
ファイル: irtest.py プロジェクト: tomwoodhams/tripwire_driver
    def XtestMultipleTransmits(self):
        # tracking down a bug that shows itself when we transmit using the same object for more than one transmit.  Method
        # name starts with X to avoid running with other tests, this one is run manually since you need the IR Toy hardware
        # and the pySerial module which isn't necessarily installed by default.

        # IR code that causes an issue, any code would probably work for this purpose.
        irCode=[1, 159, 0, 212, 0, 26, 0, 25, 0, 26, 0, 78, 0, 26, 0, 25, 0, 26, 0, 25, 0, 26, 0, 78, 0, 26, 0, 
                25, 0, 27, 0, 77, 0, 26, 0, 77, 0, 26, 0, 78, 0, 26, 0, 26, 0, 26, 0, 78, 0, 26, 0, 78, 0, 26,
                0, 25, 0, 26, 0, 78, 0, 26, 0, 78, 0, 26, 0, 24, 0, 28, 0, 76, 0, 27, 0, 25, 0, 27, 0, 77, 0, 27, 
                0, 25, 0, 27, 0, 24, 0, 27, 0, 24, 0, 28, 0, 24, 0, 28, 0, 24, 0, 28, 0, 24, 0, 27, 0, 76, 0, 28, 
                0, 24, 0, 27, 0, 77, 0, 27, 0, 76, 0, 27, 0, 76, 0, 28, 0, 76, 0, 27, 0, 76, 0, 28, 7, 15, 1, 160, 
                0, 107, 0, 27, 255, 255] #Onkyo TX-SR508 mute
        
        import serial
        serialDevice = serial.Serial('/dev/ttyACM0')
        #serialDevice = self.serialMock

        # re-using a single object with multiple transmits
        toy = IrToy(serialDevice)
        for i in range(5):
            toy.transmit(irCode)
            
        # using a new object for each transmit
        for i in range(5):
            toy2 = IrToy(serialDevice)
            toy2.transmit(irCode)
コード例 #2
0
ファイル: test_irtoy.py プロジェクト: xbug/PyIrToy
    def XtestMultipleTransmits(self):
        # tracking down a bug that shows itself when we transmit using the same object for more than one transmit.  Method
        # name starts with X to avoid running with other tests, this one is run manually since you need the IR Toy hardware
        # and the pySerial module which isn't necessarily installed by default.

        # IR code that causes an issue, any code would probably work for this purpose.
        irCode = [
            1, 159, 0, 212, 0, 26, 0, 25, 0, 26, 0, 78, 0, 26, 0, 25, 0, 26, 0,
            25, 0, 26, 0, 78, 0, 26, 0, 25, 0, 27, 0, 77, 0, 26, 0, 77, 0, 26,
            0, 78, 0, 26, 0, 26, 0, 26, 0, 78, 0, 26, 0, 78, 0, 26, 0, 25, 0,
            26, 0, 78, 0, 26, 0, 78, 0, 26, 0, 24, 0, 28, 0, 76, 0, 27, 0, 25,
            0, 27, 0, 77, 0, 27, 0, 25, 0, 27, 0, 24, 0, 27, 0, 24, 0, 28, 0,
            24, 0, 28, 0, 24, 0, 28, 0, 24, 0, 27, 0, 76, 0, 28, 0, 24, 0, 27,
            0, 77, 0, 27, 0, 76, 0, 27, 0, 76, 0, 28, 0, 76, 0, 27, 0, 76, 0,
            28, 7, 15, 1, 160, 0, 107, 0, 27, 255, 255
        ]  #Onkyo TX-SR508 mute

        import serial
        serialDevice = serial.Serial('/dev/ttyACM0')
        #serialDevice = self.serialMock

        # re-using a single object with multiple transmits
        toy = IrToy(serialDevice)
        for i in range(5):
            toy.transmit(irCode)

        # using a new object for each transmit
        for i in range(5):
            toy2 = IrToy(serialDevice)
            toy2.transmit(irCode)
コード例 #3
0
ファイル: hack_pump.py プロジェクト: Br3nda/hackPump
def set_temp(deviceName, jsonFile, temp):
    
    with open(jsonFile, 'r') as inFile:
        codes = json.load(inFile)
        irCode = codes[temp]
        if irCode:
            with serial.Serial(deviceName) as serialDevice:
                toy = IrToy(serialDevice)
                toy.transmit(codes[temp])

                logging.debug('response from IR Toy: handshake: %d bytecount: %d complete: %s' % (toy.handshake, toy.byteCount, toy.complete))
コード例 #4
0
def set_temp(deviceName, jsonFile, temp):

    with open(jsonFile, 'r') as inFile:
        codes = json.load(inFile)
        irCode = codes[temp]
        if irCode:
            with serial.Serial(deviceName) as serialDevice:
                toy = IrToy(serialDevice)
                toy.transmit(codes[temp])

                logging.debug(
                    'response from IR Toy: handshake: %d bytecount: %d complete: %s'
                    % (toy.handshake, toy.byteCount, toy.complete))
コード例 #5
0
def main():

    args = getCommandLineArgs()

    device = serial.Serial(args.device)
    filename = args.file
    with open(filename, 'r') as inFile:
        codes = json.load(inFile)

        for codeKey in args.commands:
            toy = IrToy(device)
            toy.transmit(codes[codeKey])
            print('code:', codeKey, 'code length:', len(codes[codeKey]),
                  'handshake:', toy.handshake, 'bytecount:', toy.byteCount,
                  'complete:', toy.complete)

    device.close()
コード例 #6
0
ファイル: pywave.py プロジェクト: bbrodriguez/pywave
    def click(self, control):
        cherrypy.response.headers["Content-Type"] = "application/json"

        toy = IrToy(device)
        toy.transmit(codes[control])
        print (
            "code:",
            control,
            "code length:",
            len(codes[control]),
            "handshake:",
            toy.handshake,
            "bytecount:",
            toy.byteCount,
            "complete:",
            toy.complete,
        )
        return simplejson.dumps(dict(response="Recieved and transmitted, %s" % control))
コード例 #7
0
def send_ir_code(codename="power-on"):
    raw_packet = {}
    s = serial.Serial(port='/dev/tty.usbmodem00000001', timeout=1)
    ir = IrToy(s)
    raw_packet[
        'UN-JEON/JEONG-JI_18'] = """01 92 00 C6 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E  
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 4E 
	 00 1E 00 4E 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 4E 00 1E 00 4E 
	 00 1E 00 4E 00 1E FF FF                         """
    # on 18degree

    raw_packet[
        'UN-JEON/JEONG-JI_OFF'] = """01 92 00 C6 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E  
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 4E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E       
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 4E 00 1E 
	 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 4E 00 1E FF FF                   """
    # 끄기?

    raw_packet[
        'mode-dry'] = """ 01 92 00 C6 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E      
	 00 1E 00 1E 00 4E 00 1E 00 4E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 4E 00 1E FF FF                  """
    # 모드2

    raw_packet = raw_packet[codename].replace(" ",
                                              "").replace("\n", "").replace(
                                                  "\t", "").decode('hex')
    raw_packet_l = [ord(c) for c in raw_packet]

    #name  LGE_6711A20015N
    bits = 20
    #flags SPACE_ENC|CONST_LENGTH
    #eps            30
    # aeps          100

    # header 8576  4224 -> 8567us
    # one           640  1664
    # zero          640   640
    # ptrail        640
    # pre_data_bits = 8
    pre_data = 0x88
    #actually this remote does not send any repeat signals!
    # gap = 1000000
    # toggle_bit      0

    # data = '00347'.encode('hex')

    # padding_length = bits - len(data) - 1

    # raw_data = pre_data +  + data

    try:
        # ir.reset()
        print "ir tr"
        ir.transmit(raw_packet_l)
        print "ir irmode"
        ir.IRMode()
        pass
    except Exception, e:
        pass
コード例 #8
0
def send_ir_code(codename="power-on"):
	raw_packet = {}
	s = serial.Serial(port='/dev/tty.usbmodem00000001', timeout=1)
	ir = IrToy(s)
	raw_packet['UN-JEON/JEONG-JI_18'] = """01 92 00 C6 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E  
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 4E 
	 00 1E 00 4E 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 4E 00 1E 00 4E 
	 00 1E 00 4E 00 1E FF FF                         """
	# on 18degree




	raw_packet['UN-JEON/JEONG-JI_OFF'] = """01 92 00 C6 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E  
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 4E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E       
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 4E 00 1E 
	 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E 00 1E 
	 00 1E 00 1E 00 4E 00 1E FF FF                   """
	 # 끄기?

	raw_packet['mode-dry'] = """ 01 92 00 C6 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 4E 00 1E 00 1E 00 1E      
	 00 1E 00 1E 00 4E 00 1E 00 4E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E 00 1E
	 00 1E 00 1E 00 4E 00 1E FF FF                  """
	# 모드2


	raw_packet = raw_packet[codename].replace(" ", "").replace("\n", "").replace("\t", "").decode('hex')
	raw_packet_l = [ord(c) for c in raw_packet]

	#name  LGE_6711A20015N
	bits=20
	#flags SPACE_ENC|CONST_LENGTH
	#eps            30
	# aeps          100

	# header 8576  4224 -> 8567us 
	# one           640  1664
	# zero          640   640
	# ptrail        640
	# pre_data_bits = 8
	pre_data = 0x88
	#actually this remote does not send any repeat signals!
	# gap = 1000000
	# toggle_bit      0

	# data = '00347'.encode('hex')

	# padding_length = bits - len(data) - 1

	# raw_data = pre_data +  + data

	try:
		# ir.reset()
		print "ir tr"
		ir.transmit(raw_packet_l)
		print "ir irmode"
		ir.IRMode()
		pass
	except Exception, e:
		pass
コード例 #9
0
ファイル: irtest.py プロジェクト: tomwoodhams/tripwire_driver
class TestIrToy(unittest.TestCase):

    def setUp(self):

        self.serialMock = SerialMock()
        self.toy = IrToy(self.serialMock)
        self.toy.sleepTime = 0

    def testTransmit(self):

        # length of code sent must be even
        self.assertRaises(ValueError, self.toy.transmit, [10])
        
        # set the expected results from read(): protocol version, handshake ('>' converts to 62),
        # byte count transmitted, and completion code.
        self.serialMock.setReadCode([bytearray([62]), bytearray([62]), bytearray([0,0,0,1]), b'C', b'S01'])
        
        self.toy.transmit([10,10])
        
        # when transmitting, we expect a reset (five 0x00), 'S' to enter sampling mode, 0x26 for enable handshake,
        # 0x25 to enable notify on transmit, 0x24 to enable transmit byte count, and 0x03 to start the transmission,
        # then the list of codes to transmit (always ending with 0xff, 0xff), and another reset.  See DP link at top of this file for more info.
        expectedHistory = [[0x00, 0x00, 0x00, 0x00, 0x00],
                           'v',
                           [0x00, 0x00, 0x00, 0x00, 0x00],
                           'v',
                           [0x00, 0x00, 0x00, 0x00, 0x00],
                           b'S', [0x26], [0x25], [0x24], [0x03],
                           [10, 10, 0xff, 0xff],
                           [0x00, 0x00, 0x00, 0x00, 0x00],
                           b'S']

        self.assertEqual(self.serialMock.writeHistory, expectedHistory)

    def testReceive(self):

        # pretend to be receiving the following signals from the IR Toy, must end with 0xff,0xff (same as 255, means no signal) 
        # or the code will keep recording indefinitely.  First element is for the protocol version, since receive() resets the toy
        self.serialMock.setReadCode([bytearray([62]), bytearray([1]), bytearray([2]), bytearray([0xff]), bytearray([0xff])])
        readSignal = self.toy.receive()

        self.assertEqual(readSignal, [1, 2, 0xff, 0xff])

    def XtestMultipleTransmits(self):
        # tracking down a bug that shows itself when we transmit using the same object for more than one transmit.  Method
        # name starts with X to avoid running with other tests, this one is run manually since you need the IR Toy hardware
        # and the pySerial module which isn't necessarily installed by default.

        # IR code that causes an issue, any code would probably work for this purpose.
        irCode=[1, 159, 0, 212, 0, 26, 0, 25, 0, 26, 0, 78, 0, 26, 0, 25, 0, 26, 0, 25, 0, 26, 0, 78, 0, 26, 0, 
                25, 0, 27, 0, 77, 0, 26, 0, 77, 0, 26, 0, 78, 0, 26, 0, 26, 0, 26, 0, 78, 0, 26, 0, 78, 0, 26,
                0, 25, 0, 26, 0, 78, 0, 26, 0, 78, 0, 26, 0, 24, 0, 28, 0, 76, 0, 27, 0, 25, 0, 27, 0, 77, 0, 27, 
                0, 25, 0, 27, 0, 24, 0, 27, 0, 24, 0, 28, 0, 24, 0, 28, 0, 24, 0, 28, 0, 24, 0, 27, 0, 76, 0, 28, 
                0, 24, 0, 27, 0, 77, 0, 27, 0, 76, 0, 27, 0, 76, 0, 28, 0, 76, 0, 27, 0, 76, 0, 28, 7, 15, 1, 160, 
                0, 107, 0, 27, 255, 255] #Onkyo TX-SR508 mute
        
        import serial
        serialDevice = serial.Serial('/dev/ttyACM0')
        #serialDevice = self.serialMock

        # re-using a single object with multiple transmits
        toy = IrToy(serialDevice)
        for i in range(5):
            toy.transmit(irCode)
            
        # using a new object for each transmit
        for i in range(5):
            toy2 = IrToy(serialDevice)
            toy2.transmit(irCode)
コード例 #10
0
ファイル: test_irtoy.py プロジェクト: xbug/PyIrToy
class TestIrToy(unittest.TestCase):
    def setUp(self):

        self.serialMock = SerialMock()
        self.toy = IrToy(self.serialMock)
        self.toy.sleepTime = 0

    def testTransmit(self):

        # length of code sent must be even
        self.assertRaises(ValueError, self.toy.transmit, [10])

        # set the expected results from read(): protocol version, handshake ('>' converts to 62),
        # byte count transmitted, and completion code.
        self.serialMock.setReadCode([
            bytearray([62]),
            bytearray([62]),
            bytearray([0, 0, 0, 1]), b'C', b'S01'
        ])

        self.toy.transmit([10, 10])

        # when transmitting, we expect a reset (five 0x00), 'S' to enter sampling mode, 0x26 for enable handshake,
        # 0x25 to enable notify on transmit, 0x24 to enable transmit byte count, and 0x03 to start the transmission,
        # then the list of codes to transmit (always ending with 0xff, 0xff), and another reset.  See DP link at top of this file for more info.
        expectedHistory = [[0x00, 0x00, 0x00, 0x00, 0x00], 'v',
                           [0x00, 0x00, 0x00, 0x00, 0x00], 'v',
                           [0x00, 0x00, 0x00, 0x00, 0x00], b'S', [0x26],
                           [0x25], [0x24], [0x03], [10, 10, 0xff, 0xff],
                           [0x00, 0x00, 0x00, 0x00, 0x00], b'S']

        self.assertEqual(self.serialMock.writeHistory, expectedHistory)

    def testReceive(self):

        # pretend to be receiving the following signals from the IR Toy, must end with 0xff,0xff (same as 255, means no signal)
        # or the code will keep recording indefinitely.  First element is for the protocol version, since receive() resets the toy
        self.serialMock.setReadCode([
            bytearray([62]),
            bytearray([1]),
            bytearray([2]),
            bytearray([0xff]),
            bytearray([0xff])
        ])
        readSignal = self.toy.receive()

        self.assertEqual(readSignal, [1, 2, 0xff, 0xff])

    def XtestMultipleTransmits(self):
        # tracking down a bug that shows itself when we transmit using the same object for more than one transmit.  Method
        # name starts with X to avoid running with other tests, this one is run manually since you need the IR Toy hardware
        # and the pySerial module which isn't necessarily installed by default.

        # IR code that causes an issue, any code would probably work for this purpose.
        irCode = [
            1, 159, 0, 212, 0, 26, 0, 25, 0, 26, 0, 78, 0, 26, 0, 25, 0, 26, 0,
            25, 0, 26, 0, 78, 0, 26, 0, 25, 0, 27, 0, 77, 0, 26, 0, 77, 0, 26,
            0, 78, 0, 26, 0, 26, 0, 26, 0, 78, 0, 26, 0, 78, 0, 26, 0, 25, 0,
            26, 0, 78, 0, 26, 0, 78, 0, 26, 0, 24, 0, 28, 0, 76, 0, 27, 0, 25,
            0, 27, 0, 77, 0, 27, 0, 25, 0, 27, 0, 24, 0, 27, 0, 24, 0, 28, 0,
            24, 0, 28, 0, 24, 0, 28, 0, 24, 0, 27, 0, 76, 0, 28, 0, 24, 0, 27,
            0, 77, 0, 27, 0, 76, 0, 27, 0, 76, 0, 28, 0, 76, 0, 27, 0, 76, 0,
            28, 7, 15, 1, 160, 0, 107, 0, 27, 255, 255
        ]  #Onkyo TX-SR508 mute

        import serial
        serialDevice = serial.Serial('/dev/ttyACM0')
        #serialDevice = self.serialMock

        # re-using a single object with multiple transmits
        toy = IrToy(serialDevice)
        for i in range(5):
            toy.transmit(irCode)

        # using a new object for each transmit
        for i in range(5):
            toy2 = IrToy(serialDevice)
            toy2.transmit(irCode)