Added lcdbridge
This commit is contained in:
parent
093f164121
commit
3e4765d071
91
README.md
91
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
|
||||
|
||||
|
||||
|
10
bin/lcdbridge
Executable file
10
bin/lcdbridge
Executable file
@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
require_once __DIR__."/../vendor/autoload.php";
|
||||
|
||||
NoccyLabs\LcdBridge\LcdBridgeApplication::main();
|
||||
|
||||
|
||||
|
||||
|
@ -11,12 +11,14 @@
|
||||
"require": {
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/console": "2.4.*",
|
||||
"noccylabs/sansi": "dev-master",
|
||||
"noccylabs/crap": "dev-master"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"NoccyLabs\\Gpio\\": "lib/"
|
||||
"NoccyLabs\\Gpio\\": "lib/",
|
||||
"NoccyLabs\\LcdBridge\\": "lcdbridge/"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
|
61
composer.lock
generated
61
composer.lock
generated
@ -4,7 +4,7 @@
|
||||
"Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "f8730bf5cb8eaf8085a06df386769d3a",
|
||||
"hash": "9c1aac445406a8b57812c08571a9420b",
|
||||
"packages": [
|
||||
|
||||
],
|
||||
@ -15,7 +15,7 @@
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "http://satis.noccylabs.info/packages/php-crap.git",
|
||||
"reference": "f17cd1ce2933870c30e1311b466d3d5e900066c4"
|
||||
"reference": "33d3929fb5fab4056ea9993b8d148aa3ba44e4c3"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
@ -38,7 +38,7 @@
|
||||
}
|
||||
],
|
||||
"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",
|
||||
@ -65,6 +65,61 @@
|
||||
],
|
||||
"description": "Simple ANSI User Interface",
|
||||
"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": [
|
||||
|
@ -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();
|
||||
|
23
lcdbridge/DaemonCommand.php
Normal file
23
lcdbridge/DaemonCommand.php
Normal 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
17
lcdbridge/LcdBridgeApplication.php
Normal file
17
lcdbridge/LcdBridgeApplication.php
Normal 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();
|
||||
}
|
||||
}
|
40
lib/Device/ShiftRegister.php
Normal file
40
lib/Device/ShiftRegister.php
Normal 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
|
||||
}
|
||||
|
||||
}
|
@ -54,6 +54,11 @@ class GpioPin
|
||||
$this->gpio = $gpio;
|
||||
}
|
||||
|
||||
public function getPin()
|
||||
{
|
||||
return $this->pin;
|
||||
}
|
||||
|
||||
private function findHardware()
|
||||
{
|
||||
$chips = glob("/sys/class/gpio/gpiochip*");
|
||||
|
Loading…
Reference in New Issue
Block a user