Explorar o código

made algorithm to better detect punches and update score:w

Lucas hai 7 meses
pai
achega
dc0e716d50
Modificáronse 4 ficheiros con 34 adicións e 6 borrados
  1. 32 4
      GUI.py
  2. BIN=BIN
      __pycache__/dobluetooth.cpython-313.pyc
  3. 1 1
      dobluetooth.py
  4. 1 1
      scores.txt

+ 32 - 4
GUI.py

@@ -1,10 +1,12 @@
 import platform
 import platform
+import sys
 import customtkinter as ctk
 import customtkinter as ctk
 from PIL import Image, ImageTk
 from PIL import Image, ImageTk
 import time
 import time
 import threading
 import threading
 import tkinter as tk
 import tkinter as tk
 import dobluetooth
 import dobluetooth
+import math
 
 
 # If on Windows, allow STA for Bleak
 # If on Windows, allow STA for Bleak
 if platform.system() == "Windows":
 if platform.system() == "Windows":
@@ -114,8 +116,8 @@ def start_ble_thread():
 
 
 def update_dinger_position():
 def update_dinger_position():
     global dinger
     global dinger
-    score = currentScore.get() * 0.01
-    
+    score = currentScore.get()
+
     # Example logic: map score (0–100) to y-position (900 to 300)
     # Example logic: map score (0–100) to y-position (900 to 300)
     # You can adjust the ranges to suit your needs
     # You can adjust the ranges to suit your needs
     max_score = 100
     max_score = 100
@@ -137,12 +139,38 @@ def update_dinger_position():
 
 
 # Data processing loop in background thread
 # Data processing loop in background thread
 def data_loop():
 def data_loop():
+    last_data = None
+    last_value = 0.00
     while True:
     while True:
         bledata = dobluetooth.getDataArr()
         bledata = dobluetooth.getDataArr()
         if punch_on:
         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)
             app.after(0, update_dinger_position)
+            last_data = bledata
+            last_value = value
         time.sleep(0.1)
         time.sleep(0.1)
 
 
 def start_data_loop_thread():
 def start_data_loop_thread():

BIN=BIN
__pycache__/dobluetooth.cpython-313.pyc


+ 1 - 1
dobluetooth.py

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

+ 1 - 1
scores.txt

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