Implemented base of GpioMapperInterface with WiringPiMapper
This commit is contained in:
@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user