Skip to content
crleblanc edited this page Nov 11, 2012 · 5 revisions

Here's a quick example snippet that records an IR code and plays it back to the IR Toy. Replace '/dev/ttyACM0' with whatever serial device your IR Toy is located at on your system. This requires the pySerial module.

import serial
import irtoy

with serial.Serial('/dev/ttyACM0') as serialDevice:

    # create a new instance of the IrToy class
    toy = irtoy.IrToy(serialDevice)
    
    # receive an IR signal from the IR Toy, stored in a list.
    # Note: this call will block (hang) until an IR code has been received.
    irCode = toy.receive()

    # transmit the recorded signal back to the IR Toy
    toy.transmit(irCode)

The IR code we get from the receive() method is just a Python list of integer values with an even length, and the last two elements being 255. You can create whatever list you like, with normal Python tools, NumPy, etc. The format of the samples in the list is documented here: IR Toy sampling mode. The only difference is we're saving them as integer values instead of hex. It would be easy to extend this class to output a different type of list, eg: on/off timings but I haven't needed this so haven't implemented it. The C code tools that come with the IR Toy use a binary format, it should be easy enough to write out a file compatible with these tools if required.

See the hackPump project for some real-world utilities (once they're committed): hackPump. It has an app that records named signals to a JSON file and another one that transmits these codes to the IR Toy.

Clone this wiki locally