pushinbr / pam-native-sensors
Motion sensors for PAM Native: one-shot reads and throttled watches of the accelerometer, gyroscope, magnetometer and rotation vector.
Package info
github.com/push-in/pam-native-sensors
Type:pam-native-plugin
pkg:composer/pushinbr/pam-native-sensors
Requires
- php: ^8.5
- pushinbr/pam-native: ^1.46
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-14 15:02:18 UTC
README
Motion sensors for PAM Native apps.
One-shot reads and throttled watches of the accelerometer, gyroscope, magnetometer and device motion.
Install · Quick example · Platforms · Requirements · Docs · Issues
Install
Inside a PAM Native project, add only this capability:
pam composer require pushinbr/pam-native-sensors pam doctor --fix
New to PAM? Create a project with pam init my-app --template native (see the PAM Native overview), then come back here. Composer owns the manifest and the lockfile; pam composer runs it on PAM's verified PHP runtime.
Quick example
<?php declare(strict_types=1); use Pam\Native\Sensors\SensorReading; use Pam\Native\Sensors\Sensors; use Pam\Native\Sensors\SensorType; // One-shot read (null on timeout or when the sensor is unavailable). Sensors::read(SensorType::Accelerometer, static function (?SensorReading $reading): void { // $reading->x, $reading->y, $reading->z, $reading->timestamp }); // Throttled watch: stop it when the screen is no longer visible. $watch = Sensors::watch(SensorType::Gyroscope, static function (SensorReading $reading): void {}, intervalMs: 50); Sensors::unwatch($watch);
SensorType cases: Accelerometer, Gyroscope, Magnetometer, DeviceMotion. read() takes an optional timeoutMs (default 2000, clamped to 100 to 10000); watch() defaults to intervalMs: 100.
Platform support
| Platform | Support | Notes |
|---|---|---|
| Android | API 26+ | Platform SensorManager; no extra dependencies |
| iOS | 15.0+ | CoreMotion |
| PAM Native | 1.46.0 to < 2.0.0 | From pam-native.plugin.json; PHP 8.5+ |
Requirements
- Native module:
sensors(Android and iOS). - Permissions: none on Android, no usage descriptions on iOS.
- Requires
pushinbr/pam-native1.46 or newer (plugin hooksWatchChannelandActivityResultHost). The plugin is discovered from Composer; no manual registration is needed.
Migrating from the core
Moved out of the PAM Native core in 1.46: the core keeps only the base every app needs, and this feature ships as a plugin. The native module name and its wire payloads did not change.
The 1.46 core keeps the old class names (Pam\Native\System\... and the top-level value types) as deprecated aliases of this plugin's classes; they are removed in 1.47. Replace the imports with the Pam\Native\Sensors\... names above.
Tests
pam tests/run.php # after pam composer install
PAM_NATIVE_SRC=../pam-native/packages/native/src pam tests/run.php
Docs
Part of the PAM ecosystem
PAM runs PHP natively on servers, desktops and phones. This repository is one piece of it.
| PAM | PAM Desktop | PAM Native | Ecosystem |
|---|---|---|---|
| the runtime and CLI | native desktop apps in PHP | native Android and iOS apps in PHP | every official package and plugin |
Docs: push-in.github.io/pam-docs · Issues
Apache License 2.0 · Made in Brazil by Pushin