Skip to content

Commit 6524751

Browse files
committed
Initial commit
0 parents  commit 6524751

12 files changed

+6178
-0
lines changed

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 2
7+
indent_style = space
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.gitattributes

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.editorconfig export-ignore
2+
.gitattributes export-ignore
3+
.gitignore export-ignore
4+
infection.json.dist export-ignore
5+
phpunit.xml.dist export-ignore
6+
psaml.xml.dist export-ignore
7+
ruleset.xml.dist export-ignore
8+
tests/ export-ignore
9+
10+
# Auto detect text files and perform LF normalization
11+
* text=auto

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.env
2+
/vendor/
3+
composer.phar
4+
infection.json
5+
infection.log
6+
phpunit.xml
7+
psalm.xml
8+
ruleset.xml

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Flávio Heleno
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Embedded PHP: Examples
2+
3+
This project carries code samples for different types of displays and sensors, using the Embedded PHP library.
4+
5+
## Available Examples
6+
7+
### Displays
8+
9+
- [OLED: SSD1322 Driver](Displays/Ssd1322.php)
10+
11+
### Sensors
12+
13+
- [HCSR04: Ultrasonic ranging sensor](Sensors/HcSr04.php)
14+
15+
## License
16+
17+
This library is licensed under the [MIT License](LICENSE).

Sensors/HcSr04.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
declare(strict_types = 1);
3+
4+
require_once __DIR__ . '/../vendor/autoload.php';
5+
6+
/**
7+
* This example measures distance using the HC-SR04 Ultrassonic sensor.
8+
* Requires ext-gpio (https://github.com/embedded-php/ext-gpio) to be installed.
9+
*
10+
* Assembly instructions:
11+
* - VCC: Wired to 5V
12+
* - Trigger: Wired to GPIO25 on a RPi
13+
* - Echo: Wired to GPIO24 on a RPi
14+
* - GND: Wired to GND
15+
*/
16+
17+
use EmbeddedPhp\Core\Gpio\PhpGpioExt;
18+
use EmbeddedPhp\Sensors\HcSr04;
19+
20+
$gpio = new PhpGpioExt('/dev/gpiochip0', PhpGpioExt::PIN_LOG);
21+
22+
$sensor = new HcSr04($gpio, 25, 24);
23+
for ($i = 0; $i < 10; $i++) {
24+
echo 'Probe ', $i + 1, ': ', $sensor->getDistance(), ' millimeters', PHP_EOL;
25+
sleep(1);
26+
}

composer.json

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "embedded-php/examples",
3+
"description": "Embedded PHP: Code Examples",
4+
"type": "project",
5+
"license": "mit",
6+
"authors": [
7+
{
8+
"name": "Flavio Heleno",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"config": {
13+
"optimize-autoloader": true,
14+
"sort-packages": true,
15+
"preferred-install": "dist",
16+
"allow-plugins": {
17+
"infection/extension-installer": true,
18+
"composer/package-versions-deprecated": true
19+
}
20+
},
21+
"minimum-stability": "dev",
22+
"prefer-stable": true,
23+
"funding": [
24+
{
25+
"type": "patreon",
26+
"url": "https://www.patreon.com/flavioheleno"
27+
}
28+
],
29+
"require": {
30+
"php": ">=8.0",
31+
"embedded-php/display": "dev-main",
32+
"embedded-php/sensors": "dev-main"
33+
},
34+
"require-dev": {
35+
"infection/infection": "^0.25.0",
36+
"php-parallel-lint/php-parallel-lint": "^1.3",
37+
"phpstan/phpstan": "^0.12.90",
38+
"phpunit/phpunit": "^9.5",
39+
"psy/psysh": "^0.10.8",
40+
"roave/security-advisories": "dev-master",
41+
"squizlabs/php_codesniffer": "^3.6",
42+
"vimeo/psalm": "^4.8"
43+
},
44+
"scripts": {
45+
"console": "vendor/bin/psysh",
46+
"infection": "vendor/bin/infection",
47+
"lint": "vendor/bin/parallel-lint --exclude vendor .",
48+
"phpcs": "vendor/bin/phpcs --standard=ruleset.xml src/ tests/",
49+
"phpstan": "vendor/bin/phpstan analyse --level=max --autoload-file=vendor/autoload.php src/",
50+
"phpunit": "vendor/bin/phpunit ./tests/ --coverage-html=./report/coverage/ --whitelist=./src/ --testdox-html=./report/testdox.html --disallow-test-output --process-isolation",
51+
"psalm": "vendor/bin/psalm --taint-analysis",
52+
"test": [
53+
"@infection",
54+
"@lint",
55+
"@phpunit",
56+
"@phpstan",
57+
"@psalm",
58+
"@phpcs"
59+
]
60+
},
61+
"scripts-descriptions": {
62+
"console": "Runs PsySH Console",
63+
"infection": "Runs mutation test framework",
64+
"lint": "Runs complete codebase lint testing",
65+
"phpcs": "Runs coding style checking",
66+
"phpstan": "Runs complete codebase static analysis",
67+
"phpunit": "Runs library test suite",
68+
"psalm": "Runs complete codebase taint analysis",
69+
"test": "Runs all tests"
70+
}
71+
}

0 commit comments

Comments
 (0)