scrapyard-io/i2c
最新稳定版本:0.3.0
Composer 安装命令:
composer require scrapyard-io/i2c
包简介
I2C Section of The ScrapyardIO Framework
关键字:
README 文档
README
dept-of-scrapyard-robotics/gpio — GPIO module for the ScrapyardIO Framework.
Provides an object-oriented PHP interface to Linux GPIO character devices (/dev/gpiochip*) via the ext-gpio PHP extension. Supports configuring lines as inputs or outputs, setting line bias, and listening for rising/falling edge events.
Requirements
- PHP ^8.3
ext-gpio0.1.0 (Zephir extension — see DeptOfScrapyardRobotics/GPIO for build & install instructions)dept-of-scrapyard-robotics/fd0.3.0- Linux with GPIO char device support (
/dev/gpiochip0or similar)
Installation
composer require dept-of-scrapyard-robotics/gpio
Quick Start
Output — driving a pin high or low
use ScrapyardIO\GPIO\GPIO; use ScrapyardIO\GPIO\Exceptions\GPIOException; try { $gpio = (new GPIO())->usePin(6)->asOutput('my-app'); $gpio->high(); // drive pin 6 high $gpio->low(); // drive pin 6 low } catch (GPIOException $e) { echo $e->getMessage(); }
Input — reading a button with edge events
use ScrapyardIO\GPIO\GPIO; use ScrapyardIO\GPIO\Enums\GPIOLineEvent; use ScrapyardIO\GPIO\Exceptions\GPIOException; try { $gpio = (new GPIO())->usePin(18) ->asInput('my-app') ->hasEvent(GPIOLineEvent::EDGE_FALLING) ->hasEvent(GPIOLineEvent::EDGE_RISING) ->build(); fwrite(STDOUT, "Trigger your button.\n\n"); var_dump($gpio->listen()); } catch (GPIOException $e) { echo $e->getMessage(); }
API Reference
GPIO
The entry point. Opens a GPIO chip device node.
new GPIO(string $chip = '/dev/gpiochip0')
| Method | Returns | Description |
|---|---|---|
usePin(int $pin) |
GPIOConnectionBuilder |
Begin configuring a line by pin number |
useLine(int $pin) |
GPIOConnectionBuilder |
Alias for usePin() |
chipInfo() |
array |
Returns chip metadata from the kernel |
Throws GPIOException if the requested line is already in use or unavailable.
GPIOConnectionBuilder
Fluent builder returned by GPIO::usePin(). Configure the line before finalizing it.
| Method | Returns | Description |
|---|---|---|
asInput(string $consumer, int $eventBufferSize = 64) |
static |
Configure as an input; must call build() to finalize |
asOutput(string $consumer = 'scrapyard-io') |
GPIOOutput |
Configure and open as an output immediately |
hasEvent(GPIOLineEvent $edge) |
static |
Subscribe to a rising or falling edge event (input only) |
addBias(GPIOLineBias $bias) |
static |
Set pull-up, pull-down, or disabled bias (input only) |
build() |
GPIOInput|GPIOOutput |
Finalize the configuration and open the line |
GPIOInput
Returned by ->asInput(...)->build().
| Method | Returns | Description |
|---|---|---|
read() |
int |
Raw line value (0 or 1) |
isHigh() |
bool |
true if line is high |
isLow() |
bool |
true if line is low |
listen() |
?array |
Block until the next edge event; returns event data |
getEvents() |
array |
Drain buffered events (non-blocking mode) as GPIOEvent[] |
nonblocking() |
static |
Switch the line FD to non-blocking I/O |
GPIOOutput
Returned by ->asOutput(...) or ->build() when configured as output.
| Method | Returns | Description |
|---|---|---|
high() |
void |
Drive the line high |
low() |
void |
Drive the line low |
Enums
GPIOLineBias
Controls the electrical bias applied to an input line.
| Case | Linux Flag | Description |
|---|---|---|
NONE |
— | No bias (default) |
PULL_UP |
GPIO_V2_LINE_FLAG_BIAS_PULL_UP |
Internal pull-up resistor |
PULL_DOWN |
GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN |
Internal pull-down resistor |
DISABLED |
GPIO_V2_LINE_FLAG_BIAS_DISABLED |
Bias explicitly disabled |
GPIOLineEvent
Edge types for event subscriptions on inputs.
| Case | Linux Flag | Description |
|---|---|---|
EDGE_RISING |
GPIO_V2_LINE_FLAG_EDGE_RISING |
Triggered on low → high transition |
EDGE_FALLING |
GPIO_V2_LINE_FLAG_EDGE_FALLING |
Triggered on high → low transition |
Exceptions
All exceptions are of type ScrapyardIO\GPIO\Exceptions\GPIOException.
| Factory method | Thrown when |
|---|---|
gpioChipNotAvailable(int $chip) |
The chip device cannot be opened |
gpioPinLineNotAvailable(int $line, int $chip) |
The requested line is already consumed or does not exist |
missingGpioChipLine() |
The line file descriptor could not be obtained |
missingGpioChip() |
The chip file descriptor is missing |
Examples
See the examples/ directory:
gpio-button-example.php— reading a button via edge events on pin 18gpio-fan-example.php— driving an output (fan/trigger) on pin 6
License
MIT — © Angel Gonzalez / Project Saturn Studios
scrapyard-io/i2c 适用场景与选型建议
scrapyard-io/i2c 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 05 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「framework」 「scrapyard-io」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 scrapyard-io/i2c 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 scrapyard-io/i2c 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 scrapyard-io/i2c 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Framework HLEB2 is the foundation of the web application. Provides ease of development and application performance.
High-performance, opinionated PHP 8 web framework with O(1) routing, parallel async MySQL, type-safe asset bridge, and React-island frontend
Drive Barometric Pressure sensors from Bosch Sensortec over I2C with PHP
Drive VEML7000 lux sensors over I2C with PHP
Drive BH1750 ALS sensors over I2C with PHP
The skeleton application for the Geoffrey agent framework.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-05-06