From 3e4765d071fd67f39454228f84f079d18d3dc09a Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Sun, 15 Jun 2014 00:34:33 +0200 Subject: [PATCH] Added lcdbridge --- README.md | 91 ++++++++++++++++++++++++++++-- bin/lcdbridge | 10 ++++ composer.json | 4 +- composer.lock | 61 +++++++++++++++++++- examples/softwarespi.php | 2 +- lcdbridge/DaemonCommand.php | 23 ++++++++ lcdbridge/LcdBridgeApplication.php | 17 ++++++ lib/Device/ShiftRegister.php | 40 +++++++++++++ lib/GpioPin.php | 5 ++ 9 files changed, 242 insertions(+), 11 deletions(-) create mode 100755 bin/lcdbridge create mode 100644 lcdbridge/DaemonCommand.php create mode 100644 lcdbridge/LcdBridgeApplication.php create mode 100644 lib/Device/ShiftRegister.php diff --git a/README.md b/README.md index 86f14fb..f9b0446 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,36 @@ Linux Userspace GPIO Library ============================ - * Export and Unexport GPIO pins +Current and planned features: + + * Export and Unexport GPIO pins via sysfs * Interrupt support (*) * Hardware-neutral rewrite of NoccyLabs RaspIO * Compatible with psr/logs LoggerInterface for logging + * Bit-banged SPI/I2C/1Wire + + +## Gpio + +Without a mapper active, the GPIOs adressed are the direct exported GPIO numbers, +not necessarily in any logical order. Requesting `$gpio[22]` gives you `GPIO22`. + + $gpio = new Gpio(); + $gpio1 = $gpio[1]; + + +### With a Mapper + +With a mapper the pins are arranged logically starting at 0. For example, with +the WiringPi mapper, `$gpio[0]` would return `GPIO17` and so on. The `GpioPin#getPin()` +method will still return the actual GPIO (i.e. *17* rather than *0*). + + $gpio = new Gpio(); + $mapper = new WiringPiMapper(2); + $gpio->setMapper($mapper); + + $gpio17 = $gpio[0]; + ## Interrupts @@ -40,6 +66,33 @@ be portable/supported/efficient/a good idea): // The interrupts will now be polled approx every 5th php vm "tick" + +## Parallel addressing of pins + +*Implemented in* ***0.1.x*** + + $gpio = new Gpio(); + $gpio->setMapper( new WiringPiMapper(2) ); + + $par = new BitmappedGpio(); + for($n = 0; $n < 7; $n++) { + $pin = $gpio[$n]->setDirection("out"); + $par->setGpioPin($n,$pin); + } + $par->write(0x55); // turn on 1, 3, 5, 7. + + +## Buses + +*Not yet implemented* + + $bus = new NoccyLabs\Gpio\Bus\SoftwareSpiBus; + $bus->mosi = $gpio[2]; + $bus->sclk = $gpio[9]; + $bus->write("\0x10\0x20\0x40"); + $r = $bus->read(3); + + ## Devices $lcd = new NoccyLabs\Gpio\Device\Display\Pcd8544Device; @@ -55,6 +108,7 @@ be portable/supported/efficient/a good idea): echo $lcd->getRows(); // 5 echo $lcd->getCols(); // 19 + ### LCD Bridge The LCD bridge will be able to bridge any device class implementing `LcdDeviceInterface` @@ -65,13 +119,38 @@ the display without having to fiddle with bits. CLR LOC 0 0 FONT 0 - OUT Hello World + MODE +BR + OUT "Hello World" ^C $ Commands should include: - * `CLR` clears the display (`LcdDeviceInterface#clear()`) - * `LOC n m` moves the cursor to line n column m (0-indexed) (`LcdDeviceInterface#setCursorPos(n,m)`) - * `FONT n` loads the default font (0) or a custom font file (`LcdDeviceInterface#setFont()`) - * `OUT` Write text to the display (`LcdDeviceInterface#write()`) + * `CLR` - clears the display (`LcdDeviceInterface#clear()`) + * `LOC n m` - moves the cursor to line n column m (0-indexed) (`LcdDeviceInterface#setCursorPos(n,m)`) + * `FONT n` - loads the default font (0) or a custom font file (`LcdDeviceInterface#setFont()`) + * `OUT s` - Write text to the display (`LcdDeviceInterface#write()`) + * `MODE s` - Set text modes (`LcdDeviceInterface#setTextMode()`) + + +#### Modes + +As supported: + + * `+R`/`-R` - Set/clear inverse + * `+B`/`-B` - Set/clear bold + + +#### Fonts + + + +#### Location and write + +Location is maintained and incremented after writes. + + LOC 0 0 + OUT "12345" + OUT "67890" <-- continued at 0 5 + + diff --git a/bin/lcdbridge b/bin/lcdbridge new file mode 100755 index 0000000..1d87401 --- /dev/null +++ b/bin/lcdbridge @@ -0,0 +1,10 @@ +#!/usr/bin/env php +=5.3.3" + }, + "require-dev": { + "symfony/event-dispatcher": "~2.1" + }, + "suggest": { + "symfony/event-dispatcher": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.4-dev" + } + }, + "autoload": { + "psr-0": { + "Symfony\\Component\\Console\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com", + "homepage": "http://fabien.potencier.org", + "role": "Lead Developer" + }, + { + "name": "Symfony Community", + "homepage": "http://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "http://symfony.com", + "time": "2014-05-14 21:48:29" } ], "aliases": [ diff --git a/examples/softwarespi.php b/examples/softwarespi.php index cbd777d..82a3c35 100644 --- a/examples/softwarespi.php +++ b/examples/softwarespi.php @@ -8,7 +8,7 @@ use NoccyLabs\Gpio\GpioTickHandler; use NoccyLabs\Gpio\Bus\SoftwareSpiBus as SPI; use NoccyLabs\Crap\Dumper; -$gpio = new Gpio(true); +$gpio = new Gpio(); // create spi bus $spi = new SPI(); diff --git a/lcdbridge/DaemonCommand.php b/lcdbridge/DaemonCommand.php new file mode 100644 index 0000000..5a3a4ad --- /dev/null +++ b/lcdbridge/DaemonCommand.php @@ -0,0 +1,23 @@ +setName("daemon") + ->setDescription("Spawn a new daemon") + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + + } +} diff --git a/lcdbridge/LcdBridgeApplication.php b/lcdbridge/LcdBridgeApplication.php new file mode 100644 index 0000000..84d59aa --- /dev/null +++ b/lcdbridge/LcdBridgeApplication.php @@ -0,0 +1,17 @@ +add( new DaemonCommand ); + + $app->run(); + } +} diff --git a/lib/Device/ShiftRegister.php b/lib/Device/ShiftRegister.php new file mode 100644 index 0000000..0a61702 --- /dev/null +++ b/lib/Device/ShiftRegister.php @@ -0,0 +1,40 @@ + + */ + +namespace NoccyLabs\Gpio\Device; + +class ShiftRegister extends Device +{ + protected function configure() + { + $this + ->setName("shiftregister") + ->setDescription("Generic shift register") + ->addPin("data") + ->addPin("sclk") + ->addPin("latch") + ; + } + + public function write($value) + { + // write + } + +} diff --git a/lib/GpioPin.php b/lib/GpioPin.php index df4363a..d1fb257 100644 --- a/lib/GpioPin.php +++ b/lib/GpioPin.php @@ -54,6 +54,11 @@ class GpioPin $this->gpio = $gpio; } + public function getPin() + { + return $this->pin; + } + private function findHardware() { $chips = glob("/sys/class/gpio/gpiochip*");