Added lcdbridge

This commit is contained in:
Chris 2014-06-15 00:34:33 +02:00
parent 093f164121
commit 3e4765d071
9 changed files with 242 additions and 11 deletions

View File

@ -1,10 +1,36 @@
Linux Userspace GPIO Library Linux Userspace GPIO Library
============================ ============================
* Export and Unexport GPIO pins Current and planned features:
* Export and Unexport GPIO pins via sysfs
* Interrupt support (*) * Interrupt support (*)
* Hardware-neutral rewrite of NoccyLabs RaspIO * Hardware-neutral rewrite of NoccyLabs RaspIO
* Compatible with psr/logs LoggerInterface for logging * 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 ## Interrupts
@ -40,6 +66,33 @@ be portable/supported/efficient/a good idea):
// The interrupts will now be polled approx every 5th php vm "tick" // 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 ## Devices
$lcd = new NoccyLabs\Gpio\Device\Display\Pcd8544Device; $lcd = new NoccyLabs\Gpio\Device\Display\Pcd8544Device;
@ -55,6 +108,7 @@ be portable/supported/efficient/a good idea):
echo $lcd->getRows(); // 5 echo $lcd->getRows(); // 5
echo $lcd->getCols(); // 19 echo $lcd->getCols(); // 19
### LCD Bridge ### LCD Bridge
The LCD bridge will be able to bridge any device class implementing `LcdDeviceInterface` 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 CLR
LOC 0 0 LOC 0 0
FONT 0 FONT 0
OUT Hello World MODE +BR
OUT "Hello World"
^C ^C
$ $
Commands should include: Commands should include:
* `CLR` clears the display (`LcdDeviceInterface#clear()`) * `CLR` - clears the display (`LcdDeviceInterface#clear()`)
* `LOC n m` moves the cursor to line n column m (0-indexed) (`LcdDeviceInterface#setCursorPos(n,m)`) * `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()`) * `FONT n` - loads the default font (0) or a custom font file (`LcdDeviceInterface#setFont()`)
* `OUT` Write text to the display (`LcdDeviceInterface#write()`) * `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

10
bin/lcdbridge Executable file
View File

@ -0,0 +1,10 @@
#!/usr/bin/env php
<?php
require_once __DIR__."/../vendor/autoload.php";
NoccyLabs\LcdBridge\LcdBridgeApplication::main();

View File

@ -11,12 +11,14 @@
"require": { "require": {
}, },
"require-dev": { "require-dev": {
"symfony/console": "2.4.*",
"noccylabs/sansi": "dev-master", "noccylabs/sansi": "dev-master",
"noccylabs/crap": "dev-master" "noccylabs/crap": "dev-master"
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"NoccyLabs\\Gpio\\": "lib/" "NoccyLabs\\Gpio\\": "lib/",
"NoccyLabs\\LcdBridge\\": "lcdbridge/"
} }
}, },
"extra": { "extra": {

61
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "f8730bf5cb8eaf8085a06df386769d3a", "hash": "9c1aac445406a8b57812c08571a9420b",
"packages": [ "packages": [
], ],
@ -15,7 +15,7 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "http://satis.noccylabs.info/packages/php-crap.git", "url": "http://satis.noccylabs.info/packages/php-crap.git",
"reference": "f17cd1ce2933870c30e1311b466d3d5e900066c4" "reference": "33d3929fb5fab4056ea9993b8d148aa3ba44e4c3"
}, },
"type": "library", "type": "library",
"extra": { "extra": {
@ -38,7 +38,7 @@
} }
], ],
"description": "Crap is an exception/error/assertion handling library", "description": "Crap is an exception/error/assertion handling library",
"time": "2014-06-13 23:33:50" "time": "2014-06-14 01:11:31"
}, },
{ {
"name": "noccylabs/sansi", "name": "noccylabs/sansi",
@ -65,6 +65,61 @@
], ],
"description": "Simple ANSI User Interface", "description": "Simple ANSI User Interface",
"time": "2014-06-05 12:10:14" "time": "2014-06-05 12:10:14"
},
{
"name": "symfony/console",
"version": "v2.4.6",
"target-dir": "Symfony/Component/Console",
"source": {
"type": "git",
"url": "https://github.com/symfony/Console.git",
"reference": "24f723436e62598c9dddee2a8573d6992504dc5d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/Console/zipball/24f723436e62598c9dddee2a8573d6992504dc5d",
"reference": "24f723436e62598c9dddee2a8573d6992504dc5d",
"shasum": ""
},
"require": {
"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": [ "aliases": [

View File

@ -8,7 +8,7 @@ use NoccyLabs\Gpio\GpioTickHandler;
use NoccyLabs\Gpio\Bus\SoftwareSpiBus as SPI; use NoccyLabs\Gpio\Bus\SoftwareSpiBus as SPI;
use NoccyLabs\Crap\Dumper; use NoccyLabs\Crap\Dumper;
$gpio = new Gpio(true); $gpio = new Gpio();
// create spi bus // create spi bus
$spi = new SPI(); $spi = new SPI();

View File

@ -0,0 +1,23 @@
<?php
namespace NoccyLabs\LcdBridge;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class DaemonCommand extends Command
{
protected function configure()
{
$this
->setName("daemon")
->setDescription("Spawn a new daemon")
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
}
}

View File

@ -0,0 +1,17 @@
<?php
namespace NoccyLabs\LcdBridge;
use Symfony\Component\Console\Application as ConsoleApplication;
class LcdBridgeApplication extends ConsoleApplication
{
public static function main()
{
$app = new self("lcdbridge", "0.1");
$app->add( new DaemonCommand );
$app->run();
}
}

View File

@ -0,0 +1,40 @@
<?php
/*
* Copyright (C) 2014, NoccyLabs
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
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
}
}

View File

@ -54,6 +54,11 @@ class GpioPin
$this->gpio = $gpio; $this->gpio = $gpio;
} }
public function getPin()
{
return $this->pin;
}
private function findHardware() private function findHardware()
{ {
$chips = glob("/sys/class/gpio/gpiochip*"); $chips = glob("/sys/class/gpio/gpiochip*");