From b38fc25919674e2deaef3fdacdfcc95250d968c8 Mon Sep 17 00:00:00 2001
From: DNOALEE <oliver.ljungberg@epfl.ch>
Date: Sat, 14 May 2022 15:35:39 +0200
Subject: [PATCH] Blinky added

---
 blinky.c          | 45 +++++++++++++++++++++++++++++++++++++++++++++
 blinky.h          | 15 +++++++++++++++
 check_collision.c |  2 +-
 compute_case.c    |  2 +-
 main.c            | 27 ++++++++++-----------------
 main.h            |  6 ++++++
 makefile          |  1 +
 motor_speed.c     |  2 +-
 8 files changed, 80 insertions(+), 20 deletions(-)
 create mode 100644 blinky.c
 create mode 100644 blinky.h

diff --git a/blinky.c b/blinky.c
new file mode 100644
index 0000000..60afff0
--- /dev/null
+++ b/blinky.c
@@ -0,0 +1,45 @@
+/*
+ * blinky.c
+ *
+ *  Created on: 12 mai 2022
+ *      Author: oliver
+ */
+// Standard includes
+#include <ch.h>
+#include <hal.h>
+#include <leds.h>
+
+// Project files includes
+#include "blinky.h"
+#include "check_collision.h"
+#include "compute_case.h"
+
+static THD_WORKING_AREA(waBlinky, 128);
+static THD_FUNCTION(Blinky, arg) {
+
+	chRegSetThreadName(__FUNCTION__);
+	(void)arg;
+
+	while(1){
+	// Blink the back LED when the robot moves backward
+		if( ((get_acc_case() == 2) | (get_acc_case() == 4)) &
+			 (get_wall_detection() != 2) ){
+
+			set_led(LED5, 1);
+			chThdSleepMilliseconds(300);
+			set_led(LED5, 0);
+			chThdSleepMilliseconds(200);
+		}else if( ((get_acc_case() == 0) | (get_acc_case() == 1) | (get_acc_case() == 3)) &
+				   (get_wall_detection() != 2) & (get_check_back_wall() == 1) ){
+
+			set_led(LED5, 0);
+			clear_check_back_wall();
+		}
+	    // 10Hz
+	    chThdSleepMilliseconds(100);
+	}
+}
+
+void blinky_start(void){
+	chThdCreateStatic(waBlinky, sizeof(waBlinky), NORMALPRIO, Blinky, NULL);
+}
diff --git a/blinky.h b/blinky.h
new file mode 100644
index 0000000..4b45d0d
--- /dev/null
+++ b/blinky.h
@@ -0,0 +1,15 @@
+/*
+ * blinky.h
+ *
+ *  Created on: 12 mai 2022
+ *      Author: oliver
+ */
+
+#ifndef BLINKY_H_
+#define BLINKY_H_
+
+void blinky_start(void);
+
+
+
+#endif /* BLINKY_H_ */
diff --git a/check_collision.c b/check_collision.c
index 4d76b4e..fa90501 100644
--- a/check_collision.c
+++ b/check_collision.c
@@ -13,7 +13,7 @@
 #include <selector.h>
 #include <audio/audio_thread.h>
 
-// project files includes
+// Project files includes
 #include "check_collision.h"
 #include "compute_case.h"
 
diff --git a/compute_case.c b/compute_case.c
index 8ebfab1..0928223 100644
--- a/compute_case.c
+++ b/compute_case.c
@@ -9,7 +9,7 @@
 #include <hal.h>
 #include <sensors/imu.h>
 
-// project files includes
+// Project files includes
 #include "compute_case.h"
 
 #define		XAXIS		0
diff --git a/main.c b/main.c
index 49f1192..b5853ad 100644
--- a/main.c
+++ b/main.c
@@ -1,3 +1,9 @@
+/*
+ * main.c
+ *
+ *  Created on: 14 avr. 2022
+ *      Author: Corentin Jossi
+ */
 // Standard includes
 #include <stdio.h>
 #include <stdlib.h>
@@ -15,11 +21,12 @@
 #include <audio/audio_thread.h>
 
 
-// project files includes
+// Project files includes
 #include "main.h"
 #include "compute_case.h"
 #include "check_collision.h"
 #include "motor_speed.h"
+#include "blinky.h"
 
 messagebus_t bus;
 MUTEX_DECL(bus_lock);
@@ -82,6 +89,7 @@ int main(void)
     check_collision_start();
     select_case_start();
     motor_speed_start();
+    blinky_start();
 
     // Front LED indicates that the calibration is completed
     for(uint8_t i = 0 ; i < 3; ++i){
@@ -95,22 +103,7 @@ int main(void)
 
     /* Infinite loop. */
     while (1) {
-    	// Blink the back LED when the robot moves backward
-    	if( ((get_acc_case() == 2) | (get_acc_case() == 4)) &
-    			  (get_wall_detection() != 2) ){
-
-    		set_led(LED5, 1);
-    		chThdSleepMilliseconds(300);
-    		set_led(LED5, 0);
-    		chThdSleepMilliseconds(200);
-    	}else if( ((get_acc_case() == 0) | (get_acc_case() == 1) | (get_acc_case() == 3)) &
-    			  (get_wall_detection() != 2) & (get_check_back_wall() == 1) ){
-
-    		set_led(LED5, 0);
-    		clear_check_back_wall();
-    	}
-    // 10Hz
-    chThdSleepMilliseconds(100);
+    	chThdSleepMilliseconds(1000);
     }
 }
 
diff --git a/main.h b/main.h
index 91d8a0b..cf24fd3 100644
--- a/main.h
+++ b/main.h
@@ -1,3 +1,9 @@
+/*
+ * main.h
+ *
+ *  Created on: 14 avr. 2022
+ *      Author: Corentin Jossi
+ */
 #ifndef MAIN_H
 #define MAIN_H
 
diff --git a/makefile b/makefile
index 23d6437..4e6033c 100644
--- a/makefile
+++ b/makefile
@@ -13,6 +13,7 @@ CSRC += ./main.c \
 		./compute_case.c \
 		./motor_speed.c \
 		./check_collision.c \
+		./blinky.c \
 
 #Header folders to include
 INCDIR += 
diff --git a/motor_speed.c b/motor_speed.c
index 23de1b8..2c9bd97 100644
--- a/motor_speed.c
+++ b/motor_speed.c
@@ -11,7 +11,7 @@
 #include <motors.h>
 #include <selector.h>
 
-// project files includes
+// Project files includes
 #include "motor_speed.h"
 #include "compute_case.h"
 #include "check_collision.h"
-- 
GitLab