Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulse Distance Encoding #139

Open
echo-bravo-yahoo opened this issue Feb 20, 2021 · 0 comments
Open

Pulse Distance Encoding #139

echo-bravo-yahoo opened this issue Feb 20, 2021 · 0 comments

Comments

@echo-bravo-yahoo
Copy link

echo-bravo-yahoo commented Feb 20, 2021

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]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant