Forráskód Böngészése

separated ESPcommunication

Lucas 7 hónapja
szülő
commit
3b1dfffffb
4 módosított fájl, 88 hozzáadás és 22 törlés
  1. 2 22
      GUI.py
  2. BIN
      __pycache__/dobluetooth.cpython-313.pyc
  3. 47 0
      dobluetooth.py
  4. 39 0
      graphing.py

+ 2 - 22
GUI.py

@@ -4,27 +4,7 @@ import json
 from PIL import Image, ImageTk
 from PIL import Image, ImageTk
 import time
 import time
 import asyncio
 import asyncio
-from bleak import BleakScanner
-from bleak import BleakClient
-
-target_name = "Long name works now"
-global target_address
-target_address = None
-
-SERVICE_UUID=        "d86aecf2-d87d-489f-b664-b02de82b2fc0"
-CHARACTERISTIC_UUID= "d86aecf2-d87d-489f-b664-b02de82b2fc0"
-
-async def connect():
-    devices = await BleakScanner.discover()
-    for d in devices:
-        print(d)
-        if target_name == d.name:
-            target_address = d.address
-            print("found target {} bluetooth device with address {} ".format(target_name,target_address))
-            return target_address
-            break
-        else:
-            print("could not find device")
+from dobluetooth import connect, getData
 
 
 """
 """
 parse esp32 data string and make each axis and accell data its own varible
 parse esp32 data string and make each axis and accell data its own varible
@@ -113,7 +93,7 @@ def convertToNumbers(stringlist):
         intlist.append(float(string))
         intlist.append(float(string))
     return intlist
     return intlist
 
 
-async def getData():
+async def runLoop():
     target_address = await connect()
     target_address = await connect()
     if target_address is not None:
     if target_address is not None:
         async with BleakClient(target_address) as client:
         async with BleakClient(target_address) as client:

BIN
__pycache__/dobluetooth.cpython-313.pyc


+ 47 - 0
dobluetooth.py

@@ -0,0 +1,47 @@
+import asyncio
+from bleak import BleakScanner
+from bleak import BleakClient
+import time
+
+target_name = "Long name works now"
+global target_address
+target_address = None
+
+SERVICE_UUID=        "d86aecf2-d87d-489f-b664-b02de82b2fc0"
+CHARACTERISTIC_UUID= "d86aecf2-d87d-489f-b664-b02de82b2fc0"
+
+async def connect():
+    devices = await BleakScanner.discover()
+    for d in devices:
+        print(d)
+        if target_name == d.name:
+            target_address = d.address
+            print("found target {} bluetooth device with address {} ".format(target_name,target_address))
+            return target_address
+            break
+        else:
+            print("could not find device")
+
+async def getData():
+    target_address = await connect()
+    if target_address is not None:
+        async with BleakClient(target_address) as client:
+            print(f"Connected: {client.is_connected}")
+
+            while 1:
+                try:
+                    data = await client.read_gatt_char(CHARACTERISTIC_UUID)
+                    datastr = data.decode('utf-8') #convert byte to str
+                    dataarr = convertToNumbers(datastr)
+                    print("time: {} ||| numbers: {}".format(time.time(), dataarr))
+                except Exception:
+                    print("failed to get data, restarting connection.")
+
+def convertToNumbers(stringlist):
+    dlist = stringlist.split(",")
+    dlist = dlist[0:-1]
+    intlist = []
+
+    for string in dlist:
+        intlist.append(float(string))
+    return intlist

+ 39 - 0
graphing.py

@@ -0,0 +1,39 @@
+import pygame
+import sys
+
+# Initialize Pygame
+pygame.init()
+
+# Set up the display
+width, height = 800, 600
+screen = pygame.display.set_mode((width, height))
+pygame.display.set_caption("Draw a Circle")
+
+# Define colors
+WHITE = (255, 255, 255)
+BLUE = (0, 102, 255)
+
+# Circle parameters
+circle_center = (width // 2, height // 2)
+circle_radius = 75
+
+# Main loop
+running = True
+while running:
+    # Handle events
+    for event in pygame.event.get():
+        if event.type == pygame.QUIT:
+            running = False
+
+    # Fill the background
+    screen.fill(WHITE)
+
+    # Draw the circle
+    pygame.draw.circle(screen, BLUE, circle_center, circle_radius)
+
+    # Update the display
+    pygame.display.flip()
+
+# Quit Pygame
+pygame.quit()
+sys.exit()