Implemented base of GpioMapperInterface with WiringPiMapper

This commit is contained in:
2014-06-06 19:50:17 +02:00
parent d00bcde3ee
commit 633e254958
7 changed files with 445 additions and 36 deletions

View File

@ -2,21 +2,41 @@
require_once __DIR__."/../vendor/autoload.php";
use NoccyLabs\Linux\Gpio;
use NoccyLabs\Gpio\Gpio;
use NoccyLabs\Gpio\GpioMapper\WiringPiMapper;
try {
$gpio = new Gpio\Gpio();
$gpio = new Gpio();
} catch (Gpio\Exception $e) {
error_log("Error: {$e}");
}
$pin = $gpio->export(0);
$pin->setInterrupt("rising", function() {
echo "Interrupt on GPIO0\n";
});
// The mapper translates GPIO to logical pins and vice versa
$gpio->setMapper( new WiringPiMapper(2) );
// Access logical pin 0, since we got a mapper assigned. Otherwise this would
// be the actual GPIO0 pin.
$led = $gpio[0]
->export()
->setDirection("output")
->setValue(0)
->setLabel("red led")
->dumpStatus(true);
$btn = $gpio[1]
->setDirection("input")
->setValue(0)
->setEdge("rising")
->setHandler(function() { echo "INTERRUPT!\n"; })
->setLabel("button 1")
->dumpStatus(true);
$gpio[2]
->setDirection("input")
->setValue(0)
->setEdge("rising")
->setHandler(function() { echo "INTERRUPT!\n"; })
->setLabel("button 2")
->dumpStatus(true);
while(true) {
// We need to call this for our interrupt status to be polled
$gpio->update();
usleep(10000);
}