From b517780a1a65198dd4c5394c7f22289cd41eaf2b Mon Sep 17 00:00:00 2001
From: Helge Brueger <noreply@fortiss.org>
Date: Tue, 20 Jun 2017 12:32:27 +0000
Subject: [PATCH] fixed lrf bug, added gpio function refs 7890

---
 .../trunk/lib/src/GPIO.c                           | 14 ++++++++++++--
 .../trunk/lib/src/LaserRangeFinder.c               |  5 ++++-
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c
index 2f10a17e..c129d2d9 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c
+++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c
@@ -1,12 +1,22 @@
 #include "inc/GPIO.h"
 
 // init, term
+GEN_TYPE_boolean gpio_initialized = false;
+GEN_TYPE_boolean gpio_terminated = false;
+
 void gpio_init(GPIO_PIN_T pin) {
+    // important, since all pins are accessing the same method
+    if(gpio_initialized) return;
 
+    gpio_initialized = true;
+    // TODO initialize...
 }
 
-void gpio_term(GPIO_PIN_T pin) {
+void gp_term() {
+    // important, since all pins are accessing the same method
+    if(gpio_terminated) return;
 
+    gpio_terminated = false;
 }
 
 // noval
@@ -15,7 +25,7 @@ GEN_TYPE_boolean gpio_is_noval(GPIO_PIN_T pin) {
 }
 
 void gpio_set_noval(GPIO_PIN_T pin) {
-
+    // do nothing
 }
 
 // readers
diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c
index af773b6f..8583b0fb 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c
+++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c
@@ -30,12 +30,15 @@ GEN_TYPE_int lrf_read() {
     // looks like a blocking call and actually is but is always very fast
     // since it only has to read the queue
     while (1) {
-        n_read = uart_receive(bytes, 5, 0);
+        n_read = uart_receive(&bytes, 5, 0);
 
         for (i = 0; i < n_read; i++) {
             if (bytes[i] != 0xd && bytes[i] != 0xa) {
                 value[n++] = bytes[i];
             } else if (atoi(value) != 0) {
+                for (i = n; i < 3; i++) {
+                    value[i] = 0;
+                }
                 return atoi(value);
             }
         }
-- 
GitLab