Эх сурвалжийг харах

made algorithm to better detect punches and update score:w

Lucas 7 сар өмнө
parent
commit
dc0e716d50

+ 32 - 4
GUI.py

@@ -1,10 +1,12 @@
 import platform
+import sys
 import customtkinter as ctk
 from PIL import Image, ImageTk
 import time
 import threading
 import tkinter as tk
 import dobluetooth
+import math
 
 # If on Windows, allow STA for Bleak
 if platform.system() == "Windows":
@@ -114,8 +116,8 @@ def start_ble_thread():
 
 def update_dinger_position():
     global dinger
-    score = currentScore.get() * 0.01
-    
+    score = currentScore.get()
+
     # Example logic: map score (0–100) to y-position (900 to 300)
     # You can adjust the ranges to suit your needs
     max_score = 100
@@ -137,12 +139,38 @@ def update_dinger_position():
 
 # Data processing loop in background thread
 def data_loop():
+    last_data = None
+    last_value = 0.00
     while True:
         bledata = dobluetooth.getDataArr()
         if punch_on:
-            accel_mag: float = bledata[6]
-            app.after(0, lambda val=accel_mag: currentScore.set(currentScore.get() + val))
+            if last_data == None:
+                last_data = bledata
+
+            current_x_accel = bledata[3]
+            current_y_accel = bledata[4]
+            last_x_accel = last_data[3]
+            last_y_accel = last_data[4]
+
+            value = math.sqrt((current_x_accel - last_y_accel)**2 + ((current_y_accel - last_y_accel)**2))/4
+            print(value)
+            if(value < 0.26):
+               app.after(0, lambda val=value: currentScore.set(currentScore.get() + val))
+            else:
+                if(last_value - value > 10.00):
+                    app.after(0, lambda val=value: currentScore.set(currentScore.get() + val))
+                else:
+                    if(value - last_value > 10.00):
+                        if(value == last_value):
+                            app.after(0, lambda val=value: currentScore.set(currentScore.get() + val*10))
+                        else:
+                            app.after(0, lambda val=value: currentScore.set(currentScore.get() + val))
+                    else:
+                        app.after(0, lambda val=value: currentScore.set(currentScore.get() + val*25))
+
             app.after(0, update_dinger_position)
+            last_data = bledata
+            last_value = value
         time.sleep(0.1)
 
 def start_data_loop_thread():

BIN
__pycache__/dobluetooth.cpython-313.pyc


+ 1 - 1
dobluetooth.py

@@ -60,7 +60,7 @@ async def getData():
                         datastr = data.decode('utf-8')
                         global dataarr
                         dataarr = convertToNumbers(datastr)
-                        print("📡 Data:", dataarr)
+                        #print("📡 Data:", dataarr)
                         await asyncio.sleep(0.05)
                     except Exception as e:
                         print("⚠ Read error:", e)

+ 1 - 1
scores.txt

@@ -1 +1 @@
-17821.79999999999 
+112.33688838959003