PrePAN

Sign in to PrePAN

POE::Component::GPIO Hook up GPIO pins to POE

Author
torbjorn@github
Date
URL
Status
In Review
Good

Synopsis

use POE qw(Component::GPIO);

POE::Component::GPIO->spawn(
  alias => "gpio",
  device => "...",
);

sub gpio_pinup {
  print "pin ", $_[ARG0], " came alive!\n";
}

sub gpio_pindown {
  print "pin ", $_[ARG0], " is down!\n";
}

sub gpio_pinchange {
  print "pin ", $_[ARG0], " changed state, it is now ", ($_[ARG1] ? "HIGH" : "LOW"), "\n";
}

#.. and also allow this, in some other nearby code:

sub foo {

  # set pin 17 to LOW
  $_[KERNEL]->post( "gpio", "pindown", GPIO17 );
  # also support symbols for alternative pin numbering.

  # the same, only with "pinup"

  # also this:
  $_[KERNEL]->call( "gpio", "pinstate", GPIO17 );
  # gets the state of pin17

}

Description

The synapsis is pretty self-explanatory, using POE::XS::Loop::EPoll, or similar, provide state changes and pin control on GPIO pins to POE.

Essentially integrate GPIO pin operations as easily as possible into your project, simple as that. In an ideal world.

Comments

Please sign up to post a review.