12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- /**
- * Created by PhpStorm.
- * User: robin
- * Date: 11/24/15
- * Time: 12:49 AM
- */
-
- namespace App\Http\Business\Sensors;
-
- use App\Http\DBO\SensorsValueDbo;
-
- class PiFaceSensor extends AbstractSensor
- {
- /**
- * @return SensorsValueDbo
- */
- public function getValue()
- {
- $data = $this->_sensor->getData();
-
- $device = intval(isset($data['Device']) ? $data['Device'] : 0);
- $pin = intval(isset($data['Pin']) ? $data['Pin'] : 0);
- $trueValue = isset($data['True']) ? $data['True'] : 'Yes';
- $falseValue = isset($data['False']) ? $data['False'] : 'No';
-
- $args = [
- 'camotion-piface',
- escapeshellarg('--device=' . $device),
- escapeshellarg('--read=' . $pin)
- ];
- $cli = implode(' ', $args) . ' | grep Pin | grep -Eo "[01]$"';
- $code = 0;
- $output = [];
- exec($cli, $output, $code);
- if ($code != 0) {
- abort(500, "PiFace failed with code " . $code);
- }
-
- $value = new SensorsValueDbo();
- if ($output[0] == "0") {
- $value->setValue($falseValue);
- }
- else {
- $value->setValue($trueValue);
- }
- return $value;
- }
- }
|