From d32e29f8dc2b8b1399ac1bfc8449fe1c97fcde1e Mon Sep 17 00:00:00 2001
From: Helge Brueger <noreply@fortiss.org>
Date: Mon, 26 Jun 2017 10:08:33 +0000
Subject: [PATCH] fixed lrf init device selection bug refs 7890

---
 .../trunk/lib/src/GPIO.c                            |  2 +-
 .../trunk/lib/src/LaserRangeFinder.c                | 13 ++++++++-----
 .../trunk/lib/src/PWM.c                             |  6 +++---
 3 files changed, 12 insertions(+), 9 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 c129d2d9..e6ddf63a 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c
+++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/GPIO.c
@@ -12,7 +12,7 @@ void gpio_init(GPIO_PIN_T pin) {
     // TODO initialize...
 }
 
-void gp_term() {
+void gpio_term(GPIO_PIN_T pin) {
     // important, since all pins are accessing the same method
     if(gpio_terminated) return;
 
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 acdbf44a..1b43284d 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c
+++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/LaserRangeFinder.c
@@ -3,11 +3,14 @@
 
 // init, terminate
 void lrf_init() {
-    char port[] = "/dev/????????";
-
-    FILE* fp = popen("dmesg | grep -A 3 \"Arduino Uno\"  | grep -o \"ttyACM.\" | tail -n 1","r");
-    fgets(port+5, sizeof(port)-6, fp);
-    printf("Port: %s\n", port);
+    //char port[] = "/dev/????????";
+    char port[100];
+
+    //FILE* fp = popen("dmesg | grep -A 3 \"Arduino Uno\"  | grep -o \"ttyACM.\" | tail -n 1","r");
+    FILE* fp = popen("ls -d /dev/serial/by-id/* | grep \"Arduino\" | tr -d \"\n"\"", "r");
+    //fgets(port+5, sizeof(port)-6, fp);
+    fgets(port, sizeof(port), fp);
+    printf("lrf port=%s\n", port);
     pclose(fp);
 
     uart_setup(port);
diff --git a/org.fortiss.af3.platform.raspberry/trunk/lib/src/PWM.c b/org.fortiss.af3.platform.raspberry/trunk/lib/src/PWM.c
index f00bc0aa..12e5e112 100644
--- a/org.fortiss.af3.platform.raspberry/trunk/lib/src/PWM.c
+++ b/org.fortiss.af3.platform.raspberry/trunk/lib/src/PWM.c
@@ -41,7 +41,7 @@ void* pwm_worker(void* pt_args) {
     }
 
     close(fd);
-    
+
     return NULL;
 }
 
@@ -57,13 +57,13 @@ void pwm_init(PWM_CHANNEL_T channel) {
 
         pwm_initialized = true;
     }
-    
+
     pwm_channel_enabled[channel] = true;
 }
 
 void pwm_term(PWM_CHANNEL_T channel) {
     // important, since all pwms are accessing the same method
-    if(!pwm_terminated) return;
+    if(pwm_terminated) return;
 
     free(pwm_channel_values);
     free(pwm_channel_enabled);
-- 
GitLab