scrapyard-io/i2c 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

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:

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 scrapyard-io/i2c 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 38
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-06