|
@@ -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():
|