From f658e23e9dbc4fc5057ee8b47fa88fde8c5b7375 Mon Sep 17 00:00:00 2001
From: "benjamin.sitbon" <benjamin.sibon@etu.hesge.ch>
Date: Sun, 23 May 2021 23:22:40 +0200
Subject: [PATCH] wheel_stop fault

---
 one_armed_bandit.c |  3 ++-
 wheel.c            | 15 ++++++---------
 wheel.h            |  2 +-
 3 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/one_armed_bandit.c b/one_armed_bandit.c
index 07155b8..f8a8e37 100644
--- a/one_armed_bandit.c
+++ b/one_armed_bandit.c
@@ -19,7 +19,7 @@
 
 int main()
 {
-	
+	int wheel_turn = 0;
 	pthread_t threads[4];
 
 	machine mas;
@@ -59,6 +59,7 @@ int main()
 							break;
 						case SDLK_SPACE:
 							wait_key_release();
+							stop_wheel(&mas.wheels[wheel_turn]);
 							break;
 						case SDLK_s:
 							wait_key_release();
diff --git a/wheel.c b/wheel.c
index 465fce0..3516906 100644
--- a/wheel.c
+++ b/wheel.c
@@ -22,10 +22,7 @@ void *wheel_func(void *param){
     printf("\nwheel_func");
     wheel* id = (wheel *) (param);
 
-    while(1){
-        // for(double a = 0; a<8.0; a +=0.1){
-
-            // wheel_spin(a,id.current_px,id.speed);
+    while(id->speed > 0){
       wheel_spin_1_tick(id);
       wait_until(wheel_delay_ms(*id));
     }
@@ -42,13 +39,13 @@ int wheel_spin_1_tick(wheel* this){
 int wheel_delay_ms(wheel this){
   if (this.speed) {
     return this.speed * 2;
-  } return 2;
+  } 
 }
 
-int stop_wheel(wheel this){
-  while (this.current_px % 128 != 32) { // 32 is the offset to center the item
+int stop_wheel(wheel* this){
+  while (this->current_px % 128 != 32) { // 32 is the offset to center the item
     wheel_spin_1_tick(&this);
-    wait_until(wheel_delay_ms(this));
+    wait_until(wheel_delay_ms(*this));
   }
-  this.speed = 0;
+  this->speed = 0;
 }
diff --git a/wheel.h b/wheel.h
index bfa751e..f66b13e 100644
--- a/wheel.h
+++ b/wheel.h
@@ -15,7 +15,7 @@ int get_current_px();
 void *wheel_func(void *param);
 int wheel_spin_1_tick(wheel* this);
 int wheel_delay_ms(wheel this);
-int stop_wheel(wheel this);
+int stop_wheel(wheel* this);
 
 
 #endif
-- 
GitLab