|
@@ -8,7 +8,7 @@ from kivy.lang import Builder
|
|
import asyncio
|
|
import asyncio
|
|
from bleak import BleakClient,BleakScanner
|
|
from bleak import BleakClient,BleakScanner
|
|
|
|
|
|
-import json
|
|
|
|
|
|
+# import json
|
|
|
|
|
|
STM32_UUID = "00001101-0000-1000-8000-00805F9B34FB"
|
|
STM32_UUID = "00001101-0000-1000-8000-00805F9B34FB"
|
|
|
|
|
|
@@ -36,11 +36,11 @@ class InfoWidget(Widget):
|
|
''')
|
|
''')
|
|
grid00.add_widget(connect_button)
|
|
grid00.add_widget(connect_button)
|
|
|
|
|
|
- for d in devices:
|
|
|
|
- if d.name == deviceName:
|
|
|
|
- await self.connect_and_receive(d.address)
|
|
|
|
- self.add_widget(Label(text="Connected",width=self.width,height=self.height / 4))
|
|
|
|
- break
|
|
|
|
|
|
+ # for d in devices:
|
|
|
|
+ # if d.name == deviceName:
|
|
|
|
+ # await self.connect_and_receive(d.address)
|
|
|
|
+ # self.add_widget(Label(text="Connected",width=self.width,height=self.height / 4))
|
|
|
|
+ # break
|
|
# grid1 = GridLayout(cols=2,rows=5,width=self.width,height=self.height)
|
|
# grid1 = GridLayout(cols=2,rows=5,width=self.width,height=self.height)
|
|
# self.add_widget(grid1)
|
|
# self.add_widget(grid1)
|
|
# for num,d in enumerate(devices):
|
|
# for num,d in enumerate(devices):
|
|
@@ -52,36 +52,36 @@ class InfoWidget(Widget):
|
|
# if num >= 9:
|
|
# if num >= 9:
|
|
# break
|
|
# break
|
|
|
|
|
|
- async def connect_and_receive(self, address):
|
|
|
|
- async with BleakClient(address) as client:
|
|
|
|
- if await client.is_connected():
|
|
|
|
- rawdata = await client.read_gatt_char(STM32_UUID)
|
|
|
|
- data = rawdata.decode("utf-8")
|
|
|
|
- if data.startswith("[") and data.endswith("]"):
|
|
|
|
- list = json.loads(data)
|
|
|
|
- info = "基波频率:" + str(list[0]) + "Hz\n" + \
|
|
|
|
- "THD:" + str(list[6]) + "%\n" + \
|
|
|
|
- "基波幅值:" + str(list[1]) + "V\n" + \
|
|
|
|
- "二次谐波:" + str(list[2]) + "V\n" + \
|
|
|
|
- "三次谐波:" + str(list[3]) + "V\n" + \
|
|
|
|
- "四次谐波:" + str(list[4]) + "V\n" + \
|
|
|
|
- "五次谐波:" + str(list[5]) + "V\n"
|
|
|
|
- else:
|
|
|
|
- info = "传输数据出错"
|
|
|
|
- label = Label(text=info)
|
|
|
|
- self.add_widget(label)
|
|
|
|
- return
|
|
|
|
- else:
|
|
|
|
- print("Failed to connect to device.")
|
|
|
|
- def debug(self):
|
|
|
|
- # self.size = (800,480)
|
|
|
|
- grid = GridLayout(cols=2,rows=4,width=self.width,height=self.height)
|
|
|
|
- self.add_widget(grid)
|
|
|
|
- for i in range(8):
|
|
|
|
- button = Button(text=str(i))
|
|
|
|
- button.width = grid.width / 2
|
|
|
|
- button.height = grid.height / 4
|
|
|
|
- grid.add_widget(button)
|
|
|
|
|
|
+ # async def connect_and_receive(self, address):
|
|
|
|
+ # async with BleakClient(address) as client:
|
|
|
|
+ # if await client.is_connected():
|
|
|
|
+ # rawdata = await client.read_gatt_char(STM32_UUID)
|
|
|
|
+ # data = rawdata.decode("utf-8")
|
|
|
|
+ # if data.startswith("[") and data.endswith("]"):
|
|
|
|
+ # list = json.loads(data)
|
|
|
|
+ # info = "基波频率:" + str(list[0]) + "Hz\n" + \
|
|
|
|
+ # "THD:" + str(list[6]) + "%\n" + \
|
|
|
|
+ # "基波幅值:" + str(list[1]) + "V\n" + \
|
|
|
|
+ # "二次谐波:" + str(list[2]) + "V\n" + \
|
|
|
|
+ # "三次谐波:" + str(list[3]) + "V\n" + \
|
|
|
|
+ # "四次谐波:" + str(list[4]) + "V\n" + \
|
|
|
|
+ # "五次谐波:" + str(list[5]) + "V\n"
|
|
|
|
+ # else:
|
|
|
|
+ # info = "传输数据出错"
|
|
|
|
+ # label = Label(text=info)
|
|
|
|
+ # self.add_widget(label)
|
|
|
|
+ # return
|
|
|
|
+ # else:
|
|
|
|
+ # print("Failed to connect to device.")
|
|
|
|
+ # def debug(self):
|
|
|
|
+ # # self.size = (800,480)
|
|
|
|
+ # grid = GridLayout(cols=2,rows=4,width=self.width,height=self.height)
|
|
|
|
+ # self.add_widget(grid)
|
|
|
|
+ # for i in range(8):
|
|
|
|
+ # button = Button(text=str(i))
|
|
|
|
+ # button.width = grid.width / 2
|
|
|
|
+ # button.height = grid.height / 4
|
|
|
|
+ # grid.add_widget(button)
|
|
|
|
|
|
class STI2021A(App):
|
|
class STI2021A(App):
|
|
def build(self):
|
|
def build(self):
|