This commit is contained in:
2025-04-19 23:06:54 +02:00
parent e4663df500
commit 05abcca6f5
5 changed files with 143 additions and 59 deletions

View File

@@ -1,6 +1,7 @@
from bleak import BleakClient, BleakScanner
import pandas as pd
from tkinter.ttk import Entry
import asyncio
from ..config import MILLIS_UUID, WEIGHT_UUID
@@ -26,15 +27,28 @@ class Device:
async def connect(self):
self.device = await BleakScanner.find_device_by_name(self.device_name.get())
assert self.device is not None, "No Device found!"
async def read_values(self):
assert self.is_connected, "Not connected"
async with BleakClient(self.device.address) as client:
millis = await client.read_gatt_char(MILLIS_UUID)
millis = int.from_bytes(millis, byteorder='little') # Adjust based on your data format
weight = await client.read_gatt_char(WEIGHT_UUID)
weight = int.from_bytes(weight, byteorder='little') # Adjust based on your data format
return self.device is not None
self.timestamps.append(millis)
self.weights.append(weight)
def disconnect(self):
self.device = None
async def read_values(self, interval):
while await asyncio.sleep(interval, True):
if self.is_connected:
async with BleakClient(self.device.address) as client:
while await asyncio.sleep(interval, True):
millis = await client.read_gatt_char(MILLIS_UUID)
millis = int.from_bytes(millis, byteorder='little') # Adjust based on your data format
weight = await client.read_gatt_char(WEIGHT_UUID)
weight = int.from_bytes(weight, byteorder='little') # Adjust based on your data format
self.timestamps.append(millis)
self.weights.append(weight)
if not self.is_connected:
break
def clear_data(self):
self.timestamps = []
self.weights = []

View File

@@ -9,15 +9,10 @@ class Slider:
command):
self.command = command
self.frame = ttk.Frame(parent)
self.frame.pack(pady=10)
self.label = ttk.Label(parent, text=f"{label_text}: {int(initial_value)}")
self.label = ttk.Label(self.frame, text=f"{label_text}: {int(initial_value)}")
self.label.pack()
self.slider = ttk.Scale(self.frame, from_=from_, to=to, orient='horizontal', command=self.update)
self.slider = ttk.Scale(parent, from_=from_, to=to, orient='horizontal', command=self.update)
self.slider.set(initial_value)
self.slider.pack()
def update(self, event=None):
value = self.slider.get()
@@ -25,4 +20,12 @@ class Slider:
self.command()
def get_value(self):
return self.slider.get()
return self.slider.get()
def pack(self, **kwargs):
self.label.pack(**kwargs)
self.slider.pack(**kwargs)
def pack_forget(self):
self.label.pack_forget()
self.slider.pack_forget()