Skip to content

Commit

Permalink
Changes required to enable the inverted logic on the Pin constructor …
Browse files Browse the repository at this point in the history
…and pin() GPIO method.
  • Loading branch information
allebb committed Aug 25, 2017
1 parent e1987e8 commit 93cf9ed
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/GPIO.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ public function __construct(AdapterInterface $adapter = null)
*
* @param int $pin The GPIO pin number
* @param string $type The pin type (input or output) - Use GPIO::IN and GPIO::OUT
* @param bool $invert Invert the logic so that high->low and low->high
* @return Pin
*/
public function pin(int $pin, string $type): Pin
public function pin(int $pin, string $type, bool $invert = false): Pin
{
return new Pin($pin, $type, $this->ioAdapter);
return new Pin($pin, $type, $this->ioAdapter, $invert);
}

/**
Expand Down
5 changes: 3 additions & 2 deletions src/Pin.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ class Pin
* @param int $pin The BCM pin number
* @param string $type The pin type (Input or Output)
* @param AdapterInterface $adapter The GPIO adapter interface
* @param bool $invert Invert the logic so that high->low and low->high
*/
public function __construct(int $pin, string $type, AdapterInterface $adapter)
public function __construct(int $pin, string $type, AdapterInterface $adapter, bool $invert = false)
{
$this->adapter = $adapter;

$this->adapter->setDirection($pin, $type);
$this->adapter->setDirection($pin, $type, $invert);

$this->validatePin($pin);
$this->pin = $pin;
Expand Down

0 comments on commit 93cf9ed

Please sign in to comment.