|
@@ -0,0 +1,44 @@
|
|
1
|
+<?php
|
|
2
|
+/**
|
|
3
|
+ * Created by PhpStorm.
|
|
4
|
+ * User: robin
|
|
5
|
+ * Date: 11/24/15
|
|
6
|
+ * Time: 12:49 AM
|
|
7
|
+ */
|
|
8
|
+
|
|
9
|
+namespace App\Http\Business\Sensors;
|
|
10
|
+
|
|
11
|
+use App\Http\DBO\SensorsValueDbo;
|
|
12
|
+
|
|
13
|
+class PiFaceSensor extends AbstractSensor
|
|
14
|
+{
|
|
15
|
+ /**
|
|
16
|
+ * @return SensorsValueDbo
|
|
17
|
+ */
|
|
18
|
+ public function getValue()
|
|
19
|
+ {
|
|
20
|
+ $data = $this->_sensor->getData();
|
|
21
|
+
|
|
22
|
+ $device = intval(isset($data['Device']) ? $data['Device'] : 0);
|
|
23
|
+ $pin = intval(isset($data['Pin']) ? $data['Pin'] : 0);
|
|
24
|
+ $trueValue = intval(isset($data['True']) ? $data['True'] : 0);
|
|
25
|
+ $falseValue = intval(isset($data['False']) ? $data['False'] : 0);
|
|
26
|
+
|
|
27
|
+ $args = [
|
|
28
|
+ 'camotion-piface',
|
|
29
|
+ escapeshellarg('--device=' . $device),
|
|
30
|
+ escapeshellarg('--read=' . $pin)
|
|
31
|
+ ];
|
|
32
|
+ $cli = implode(' ', $args) . ' | grep Pin | grep -Eo "[01]$"';
|
|
33
|
+ $code = 0;
|
|
34
|
+ $output = [];
|
|
35
|
+ exec($cli, $output, $code);
|
|
36
|
+ if ($code != 0) {
|
|
37
|
+ abort(500, "PiFace failed with code " . $code);
|
|
38
|
+ }
|
|
39
|
+
|
|
40
|
+ $value = new SensorsValueDbo();
|
|
41
|
+ $value->setValue($output);
|
|
42
|
+ return $value;
|
|
43
|
+ }
|
|
44
|
+}
|