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) withLineBias::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:
- POSI Extension v^0.4.0 or newer
- Microscrap POSIX Drivers (
posixcarrier)
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
LineBiason theDigitalInputfactory —GenericButtondoes not set bias itself. - Default polarity is active-low (line reads low when pressed), matching pull-up + switch-to-GND wiring.
- Wrap
GenericButtoninBasicButtonfor edge / hold semantics, then inject intoDigitalButtonPad.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-12