ballen/gpio

使用PHP编写的RaspberryPi GPIO库。

2.0.3 2022-12-28 12:13 UTC

This package is auto-updated.

Last update: 2024-08-28 15:50:17 UTC


README

Build Code Coverage Scrutinizer Code Quality Code Climate Latest Stable Version Latest Unstable Version License

这是一个使用PHP编写的RaspberryPi GPIO库,该库使得处理简单的输入和输出(如按钮、开关、LED灯、电机和继电器)变得非常简单。

要求

  • PHP >= 7.3.0

此库已通过PHP 7.3、7.4、8.0、8.1和8.2进行单元测试!

如果您需要使用较旧的PHP版本,您应该安装此库的1.x版本(下面提供详细信息)。

许可证

此库在GPLv3许可证下发布,欢迎您使用、改进并向回贡献您的更改!

安装

安装此库最新版本的推荐方法是使用Composer;要使用Composer安装,请在控制台输入以下命令

composer require ballen/gpio

如果您需要使用较旧的PHP版本,1.x.x版本支持PHP 7.1和7.2,您可以使用以下命令使用Composer安装此版本

composer require ballen/gpio ^1.0

示例用法

闪烁单个LED的示例

use Ballen\GPIO\GPIO;

// Create a new instane of the GPIO class.
$gpio = new GPIO();

// Configure our 'LED' output...
$led = $gpio->pin(18, GPIO::OUT);

// Create a basic loop that runs continuously...
while (true) {
    // Turn the LED on...
    $led->setValue(GPIO::HIGH);
    // Wait for one second...
    sleep(1);
    // Turn off the LED...
    $led->setValue(GPIO::LOW);
    // Wait for one second...
    sleep(1);
}

测试和覆盖率

此库使用PHPUnit进行完全单元测试。

我使用GitHub Actions进行持续集成,每次提交都会触发PHP 7.3、7.4、8.0、8.1和8.2的测试。

如果您想自行运行测试,应运行以下命令

# Install the GPIO Library (which will include PHPUnit as part of the require-dev dependencies)
composer install

# Now we run the unit tests (from the root of the project) like so:
./vendor/bin/phpunit

也可以运行代码覆盖率测试并生成报告(这需要安装XDebug)...

./vendor/bin/phpunit --coverage-html ./report

支持

我很乐意通过我的个人邮箱地址提供支持,因此如果您需要帮助,请给我发邮件到:ballen@bobbyallen.me