コード例 #1
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)
コード例 #2
0
ファイル: record_codes.py プロジェクト: techsol/hackPump
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 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()
コード例 #5
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
コード例 #6
0
ファイル: test_irtoy.py プロジェクト: xbug/PyIrToy
    def setUp(self):

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