calcinai/phpi
Composer 安装命令:
composer require calcinai/phpi
包简介
Event driven bindings for the Raspberry Pi GPIO
关键字:
README 文档
README
Event driven bindings for the Raspberry Pi GPIO. Supports A, A+, B, Brev2, B+, 2B, 3B, Compute Module and Pi Zero.
This library interacts (almost) directly with the peripheral registers for maximum functionality and speed. See note on mmap/dma
As there is no ability to
mmapin PHP, by default, this has been delegated to a python subprocess. The python has been kept to an absolute minimum (<25 lines) in terms of complexity to allow flexibility at PHP level.
This means that you MUST have python installed alongside PHP for it to function. …sortof
There is also a native PHP extension that is a drop-in replacement for the python subprocess which greatly improves performance. I'd strongly recommend using it, especially with less powerful Pis.
This library will function without any kernel drivers/sysfs etc enabled.
Setup
Using composer:
composer require calcinai/phpi
Although it is possible to add this to your own autoloader, it's not recommended as you'll have no control of the dependencies. If you haven't used composer before, I strongly recommend you check it out at https://getcomposer.org
Usage
All of this code is designed to be run in cli mode, as root to permit the memory access. It is not recommended to try and run this in a synchronous nature (namely under apache/nginx) as this would introduce stability and security issues. See below for more information about webservices.
You can test your install and get a visual display of the pin states by running ./bin/phpi info from the install directory.
The board factory:
$board = \Calcinai\PHPi\Factory::create();
Minimal example of reading and setting a pin
use Calcinai\PHPi\Pin\PinFunction; use Calcinai\PHPi\Pin; $pin = $board->getPin(17) //BCM pin number ->setFunction(PinFunction::INPUT) ->setPull(Pin::PULL_UP); //Will be === to Pin::LEVEL_HIGH or Pin::LEVEL_LOW var_dump($pin->getLevel()); $pin->setFunction(PinFunction::OUTPUT); $pin->high(); $pin->low();
Higher level devices and events
$button = new Button($board->getPin(17)); $led = new LED($board->getPin(18)); $button->on('press', [$led, 'on']); $button->on('release', [$led, 'off']); $board->getLoop()->run();
GPIO
GPIO (input) is the default mode of the pin objects. Alternate functions can be accessed by using the ->setFunction(PinFunction::x) method. It is
recommended to use the function names as opposed to ALT0..5 unless you know exactly what you're doing, as quite a lot are reserved.
A few useful classes are also included for digital interaction. With the default python-mmap, you can expect a raw transition speed of ~20kHz, with the
native extension, it's more like 80kHz on a Pi 3.
PWM
Hardware PWM is supported by this library, and to an extent, so is soft PWM. As this code runs in the react event loop, it's not practical to interact with the ports more than a few hundred times/sec.
SPI
SPI is supported along with some device protocols (MPC300x etc). With the default python-mmap, it is limited to about 3kB/s before there is no CPU left! With the native extension, you can reach speeds of over 30kB/s.
The event loop
One of the original reasons for basing this project on the react event loop was for the other components that can be leveraged. A good example is the websocket server; it will run seamlessly inline with this library to provide real time, bidirectional, non-polling interaction with the Pi from any modern browser.
See phpi-websocket for more on this.
External Devices
There are included helper classes for interfacing with common devices, with more added regulary.
- Generic Inputs/Outputs
- Buttons
- LEDs
- Relays
- ADC (MCP 3xxx series)
- H Bridge Motors
- 2 and 4 Phase stepper motors
calcinai/phpi 适用场景与选型建议
calcinai/phpi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 674 次下载、GitHub Stars 达 96, 最近一次更新时间为 2016 年 06 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「websocket」 「GPIO」 「raspberry」 「rpi」 「pi」 「spi」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 calcinai/phpi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 calcinai/phpi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 calcinai/phpi 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A RaspberryPi GPIO library written in PHP.
WebSocket view engine
Scaffolding for Websocket server using Ratchet & PHPi
GPIO-related utils & toolkit PHP library
Gpio library implementing Carica Io Devices
This is a PHP Framework base on Swoole
统计信息
- 总下载量: 674
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 97
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-06-05