示例#1
0
def recordCodes(deviceName):
    """Ask the user what the button press should be called and return as a dict of 
    name:code key/value pairs.  Similar to the Lirc irrecord tool"""

    serialDevice = serial.Serial(deviceName)
    toy = IrToy(serialDevice)
    codes = {}
    while True:

        try:
            input = raw_input
        except NameError:
            pass

        label = input("Please enter a name for the button you will press, or Enter to finish:\n")

        if label == "":
            break
        else:
            toy.reset()
            print("press the remote control button once for the %s button:" % label)
            codes[label] = toy.receive()

    serialDevice.close()

    return codes
示例#2
0
def recordCodes(deviceName):
    '''Ask the user what the button press should be called and return as a dict of 
    name:code key/value pairs.  Similar to the Lirc irrecord tool'''

    serialDevice = serial.Serial(deviceName)
    toy = IrToy(serialDevice)
    codes = {}
    while True:
        
        try:
            input = raw_input
        except NameError:
            pass

        label = input('Please enter a name for the button you will press, or Enter to finish:\n')
        
        if label == '':
            break
        else:
            toy.reset()
            print('press the remote control button once for the %s button:' % label)
            codes[label] = toy.receive()

    serialDevice.close()

    return codes
示例#3
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))
示例#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 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)
示例#6
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()
示例#7
0
    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))
示例#8
0
    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)
示例#9
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
示例#10
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
示例#11
0
    def setUp(self):

        self.serialMock = SerialMock()
        self.toy = IrToy(self.serialMock)
        self.toy.sleepTime = 0
示例#12
0
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)
示例#13
0
    def setUp(self):

        self.serialMock = SerialMock()
        self.toy = IrToy(self.serialMock)
        self.toy.sleepTime = 0
示例#14
0
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)