This commit is contained in:
2025-04-13 22:55:55 +02:00
commit 9abfb936a3
16 changed files with 527 additions and 0 deletions

View File

40
filter_dev/gui/device.py Normal file
View File

@@ -0,0 +1,40 @@
from bleak import BleakClient, BleakScanner
import pandas as pd
from tkinter.ttk import Entry
from ..config import MILLIS_UUID, WEIGHT_UUID
class Device:
@property
def is_connected(self):
return self.device is not None
@property
def data(self):
return pd.DataFrame({
"timestamps": self.timestamps,
"weights": self.weights
})
def __init__(self, device_name: Entry):
self.device = None
self.device_name = device_name
self.timestamps = []
self.weights = []
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
self.timestamps.append(millis)
self.weights.append(weight)

28
filter_dev/gui/slider.py Normal file
View File

@@ -0,0 +1,28 @@
from tkinter import ttk
class Slider:
def __init__(self,
parent,
label_text,
from_, to,
initial_value,
command):
self.command = command
self.frame = ttk.Frame(parent)
self.frame.pack(pady=10)
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.set(initial_value)
self.slider.pack()
def update(self, event=None):
value = self.slider.get()
self.label.config(text=f"{self.label.cget('text').split(':')[0]}: {int(value)}")
self.command()
def get_value(self):
return self.slider.get()