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

Example #1

Closed
GeoffreyPlitt opened this issue May 21, 2018 · 4 comments
Closed

Example #1

GeoffreyPlitt opened this issue May 21, 2018 · 4 comments
Labels
question Further information is requested

Comments

@GeoffreyPlitt
Copy link

Very interested to use this. Could you throw up a full example?

@johntalton
Copy link
Owner

First, this is a beta (maybe alpha) version so far, and thus master is tracking dev and changes (aka breaks) a lot.

Second, the dependencies are not published npms. And specifically rasbus also is a wrapper for several i2c and spi libraries. Though the lib itself just assumes the interface (duck for now, typescript later maybe)

Third, example/client is the current working app. It follows similar style used in other repo here (aka boschieu etc). The current examples focus less on creating Gpio style access (though it is stubbed in and headed in that direction as per notes etc) and more on managing the chip settings directly as a low level api.

Node, the Gpio will follow the onoff style api and work interchangeably with it. The chip has two interrupts that can be managed via onoff and feed back to this lib (other gpio libs should also work)

Last, the usefulness of many of the existing and target features add a complexity not found in other (all?) libraries for the mcp23 chips. And as such usefulness of such added complexity weight against any performance gains may be negligible under V8 runtimes (as examples. supporting both 8bit and 16bit poll mode, as well as the interlaced and dual-blocks addressing mode may provide little production usages ... time will tell :) )

I would be interested in any use cases / features etc you have in mind.
thank

@GeoffreyPlitt
Copy link
Author

Gotcha. So is this polling-only, or is it interrupt-driven? Looking for something that doesn't eat CPU unless buttons are pressed.

@johntalton johntalton added the question Further information is requested label May 22, 2018
@johntalton
Copy link
Owner

Full Interrupt driven event can be achieved. But support for single and no interrupts is supported.

This chip can generate interrupts on its intA and itB pins. If those are wired to a raspberry pi, a library like onoff is need to driver those.

The intent of this library is to then provide the callbacks Mcp23.interruptA() in order to trigger the chip read and production of software events for the corresponding Gpio/Port/Word interfaces.

The chip provides two interrupts. It is however the intent to support both independent A and B interrupts as well as the Mirrored Interrupt mode the chip supports. Also, as software fast poll example will be added when no A or B interrupt can be added and needs to be emulated.

const intA = new onoff.Gpio(INT_A_PIN_NAME, 'in', 'high');
...
Mcp23.from(bus, { ... }).then(device => {
   ..
   intA.watch( ... (err, value) => {
      ... 
      device.interruptA();
    }

  const portA = device.exportPort('A'); // pins 21 - 28 on the mcp23017
  // this could have also just been device.exportGpio(21, 'in', 'both'); etc
  ..
  portA.watch( ... (err, value) => {
    ...
    // here we write our application code specific to handling events on portA
    ..

The "point" of all that being that this extra abstraction allows for the use of any external library to provide the interrupt pins for the mcp23 while still providing a flexible Gpio style interface.

The expectation is that higher-level APIs will be developed atop of these structures (such as examples/client) that abstract much of the setup process hidden. Projects like johnny-five and other accumulate much of this dependency glue, however, many sacrifice exposing simplified API to the end user, which is for most acceptable :)

@GeoffreyPlitt
Copy link
Author

Killer explanation, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants