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

Replacing quick2wire’s gpio-admin with Wiring Pi’s gpio utility #25

Open
tjanson opened this issue Oct 19, 2014 · 6 comments
Open
Assignees

Comments

@tjanson
Copy link
Collaborator

tjanson commented Oct 19, 2014

Hi,

I’ve been using pi-gpio for a while (in the form of Heimcontrol), so first off thank you for your work.

There’s been only one issue: As described in #24, exporting pins is finicky and complicates things – which is a shame, because simplicity is really what I like about pi-gpio.

My vision of pi-gpio: A simple, beginner-friendly library providing basic read/write functions that can be used without worrying about exports at all, e.g.:

var gpio = require('pi-gpio');
gpio.write(15, 1); // auto-exported as output
console.log(gpio.read(11)); // auto-exported as input
console.log(gpio.read(15)); // auto-switch to input

The problem really lies in the underlying tool: quick2wire’s gpio-admin, which as far as I can tell has in practice been superseeded by Wiring Pi’s gpio utility. In order to make the switch,

I understand that you may want something very different from pi-gpio. That’s why I’m asking for your feedback!
As it stands, it’s a pretty massive change, with an entirely incompatible API, but I’d be willing to make it backwards-compatible, or modify it in any other way, if desired.

tjanson added a commit to tjanson/heimcontrol.js that referenced this issue Oct 19, 2014
@rakeshpai
Copy link
Owner

Thanks, @tjanson! This is entirely in sync with what I've wanted to do. It's awesome that you coded it up! :)

How do you want to proceed? How hard do you think it will be to support backwards compatibility? Would you say it's worth sacrificing backwards compatibility (if, say, we do that with a significant version bump)?

I'm also open to hand over control over this repo to you, if you could help with on-going maintenance.

@tjanson
Copy link
Collaborator Author

tjanson commented Oct 21, 2014

How hard do you think it will be to support backwards compatibility? Would you say it's worth sacrificing backwards compatibility (if, say, we do that with a significant version bump)?

Not hard at all. Keeping in line with the old API, read/write could be extended as follows:

.read(pinNumber, [callback [, exportMode = 'auto']])

Reads the current value of the pin. Most useful if the pin is in the input direction.

  • pinNumber: As usual.
  • callback: Will receive a possible error object as the first argument, and the value of the pin as the second argument. The value will be either 0 or 1 (numeric).
  • exportMode:
    • 'auto' (new default): Export pin before reading, unless it was previously exported.
    • 'force': Export pin before reading.
    • 'off' (old behaviour): Do not export pin, just read – even if we think it’s not ready for read.

Everything else could stay the same. Some methods would be rather pointless (e.g., export absorbs setDirection’s functionality), but we could point that out with a deprecation note.

I'm also open to hand over control over this repo to you, if you could help with on-going maintenance.

Thanks – I’d like that, I’m willing to put some effort into maintaining it. :)

@rakeshpai
Copy link
Owner

Sorry for the late reply. I've added you as a collaborator on this repo. Please let me know when you're ready, and I could test and push to npm.

@tjanson tjanson self-assigned this Oct 25, 2014
@tjanson
Copy link
Collaborator Author

tjanson commented Oct 27, 2014

I’ve pushed to branch gpioutil-switch; it’s not quite finished yet, but ready to be tested.

Apart from adding tests for the auto-export functionality, I’m thinking about rewriting read and write to use bindings to the native Wiring Pi library (rather than the slow exec call of the gpio utility). That would speed up read/writes extremely. I think I’ll open an issue to discuss it.

@tjanson
Copy link
Collaborator Author

tjanson commented Oct 31, 2014

I’ve cleaned everything up and opened a PR #27, please have a look. :)

@rakeshpai
Copy link
Owner

Ah cool. Sorry for the delay. I'll review the PR soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants