定制 dept-of-scrapyard-robotics/generic-buttons 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

dept-of-scrapyard-robotics/generic-buttons

Composer 安装命令:

composer require dept-of-scrapyard-robotics/generic-buttons

包简介

Drive basic on/off GPIO buttons with PHP

README 文档

README

Basic on/off GPIO buttons with PHP

PHP package for simple digital buttons (momentary switches to GND or VCC). It sits on the ScrapyardIO GPIO stack and plugs into the BareMetal HumanInput components (BasicButton, DigitalButtonPad).

Compatible Digital Interfaces

Buttons are read from a digital input pin. Most switches to ground need an internal pull-up.

You can interface with them the following ways:

  • A Linux single-board computer's exposed GPIO pins using the POSIX / libgpiod carrier (posix) with LineBias::PULL_UP
  • An MPSSE-enabled USB-to-serial device such as an FT232H using the USB carrier (usb)

Dependencies

This package makes use of modules within:

For GPIO buttons you also need:

Installing from Composer

composer require dept-of-scrapyard-robotics/generic-buttons

Basic Usage

Active-low button with pull-up (POSIX)

<?php

use GPIO\Common\GPIO;
use GPIO\Contracts\Digital\LineBias;
use BareMetal\Actuation\HumanInput\BasicButton;
use BareMetal\Actuation\HumanInput\DigitalButtonPad;
use DeptOfScrapyardRobotics\Actuators\GenericButtons\GenericButton;

$input = GPIO::digitalIn('posix')
    ->device(4)              // gpiochip4 on Raspberry Pi 5 (RP1)
    ->pin(17)
    ->name('btn-a')
    ->lineBias(LineBias::PULL_UP)
    ->create();

$ic = new GenericButton($input);                 // active-low by default
// $ic = new GenericButton($input, active_low: false);

$button = new BasicButton('A', $ic);
$pad = new DigitalButtonPad([$button]);

$pad->poll();

if ($pad->isPressed('A')) {
    // rising edge this frame
}

if ($pad->isHolding('A')) {
    // held past the default 500ms threshold
}

$input->close();

Multiple GPIO buttons on one pad

<?php

use BareMetal\Actuation\HumanInput\BasicButton;
use BareMetal\Actuation\HumanInput\DigitalButtonPad;
use DeptOfScrapyardRobotics\Actuators\GenericButtons\GenericButton;

$pad = new DigitalButtonPad([
    new BasicButton('A', new GenericButton($inputA)),
    new BasicButton('B', new GenericButton($inputB)),
]);

$pad->poll();

if ($pad->chord('A', 'B')) {
    // both down
}

Notes

  • Configure LineBias on the DigitalInput factory — GenericButton does not set bias itself.
  • Default polarity is active-low (line reads low when pressed), matching pull-up + switch-to-GND wiring.
  • Wrap GenericButton in BasicButton for edge / hold semantics, then inject into DigitalButtonPad.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-07-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固