node-rpio icon indicating copy to clipboard operation
node-rpio copied to clipboard

Pulse Distance Encoding

Open echo-bravo-yahoo opened this issue 3 years ago • 0 comments

Hey! I'm interested in driving an infra-red device that takes pulse distance encoded commands. If you aren't familiar, one example of a pulse-distance encoded command might be:

output high (██): just a separator output low, short duration (▁): logical 0 output low, long duration (▁▁▁): logical 1

So ██▁██▁▁▁██▁▁▁██▁██ might encode 0x0110.

I first started by trying to use other raspi libraries that use the filesystem API for IO, but that was way too slow; then I tried node-rpio, and it's able to get fast enough, but not consistent enough. It's not uncommon, for instance, for a 400 microsecond HIGH pulse to last 900 microseconds while all the other 400 microsecond pulses near it are just about perfectly 400 microseconds long.

Would you welcome a PR that adds PDE protocol support? I'm envisioning an API something like:

// single pin protocol
rpio.open(pin, rpio.PDE);

// specifying pin allows for multiple pins to do PDE at a time, but the API would be simpler
// if the config just assumed it was one-pde-at-a-time.
rpio.pdeSetSeparatorDuration(pin, 450);
rpio.pdeSetShortDuration(pin, 325);
rpio.pdeSetLongDuration(pin, 1200);
// should default to HIGH; I believe this is conventionally HIGH to make it easy to find the start of a pulse
rpio.pdeSetSeparator(pin, rpio.HIGH);

// provide the pre-computed pulse array; this operation blocks until the whole pulse has been sent
// unsure if byte-wise (Buffer) protocol or bit-wise protocol would be easier for consumers

// byte-wise:
var txbuf = new Buffer([0x3, 0x0, 0xff, 0xff]);
rpio.pdeWrite(pin, txbuf);

// bit-wise
rpio.pdeWrite(pin, [0, 1, 1, 0]);

echo-bravo-yahoo avatar Feb 20 '21 18:02 echo-bravo-yahoo