Ver código fonte

updated camotion-piface version; added piface sensor support

tags/v0.1.4
Robin Thoni 7 anos atrás
pai
commit
34ef8a4c76

+ 2
- 2
app/Http/Business/Commands/PiFaceCommand.php Ver arquivo

@@ -19,7 +19,7 @@ class PiFaceCommand extends AbstractCommand
19 19
     {
20 20
         $data = $this->_command->getData();
21 21
         $args = [
22
-            'camotion-pifaceo'
22
+            'camotion-piface'
23 23
         ];
24 24
         foreach ($data["Commands"] as $cmd) {
25 25
             $args[] = escapeshellarg("--" . $cmd);
@@ -32,4 +32,4 @@ class PiFaceCommand extends AbstractCommand
32 32
             abort(500, "PiFace failed with code " . $code);
33 33
         }
34 34
     }
35
-}
35
+}

+ 44
- 0
app/Http/Business/Sensors/PiFaceSensor.php Ver arquivo

@@ -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
+}

Carregando…
Cancelar
Salvar