From 1246fc29621cb79dcdc5344cce61f3da05551bc0 Mon Sep 17 00:00:00 2001 From: leo Date: Sat, 17 Jun 2023 17:17:20 +0200 Subject: [PATCH] fused currend --- ble_interface.py | 13 ++++++++++++- main.py | 12 +++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/ble_interface.py b/ble_interface.py index 2eaffda..12a6251 100644 --- a/ble_interface.py +++ b/ble_interface.py @@ -14,6 +14,7 @@ import myUUIDs class ble_interface: CURRENT = "current" + CURRENT_F = "current_f" VOLTAGE = "volts" CONFIGURATION = "conf" RANGE = "range" @@ -29,6 +30,7 @@ class ble_interface: self.services: Dict[str, BleakGATTService] = {} self.handlers = { self.CURRENT: self.__current_meas_handler, + self.CURRENT_F: self.__current_f_meas_handler, self.VOLTAGE: self.__voltage_meas_handler, self.RANGE: self.__range_handler, } @@ -78,7 +80,10 @@ class ble_interface: s = services[i] if(s.uuid == normalize_uuid_str(myUUIDs.METROLOGY_SERVICE)): if(s.characteristics[0].uuid == normalize_uuid_str(myUUIDs.ELECTRIC_CURRENT_CHAR)): - self.services[self.CURRENT] = s + if(len(s.characteristics) == 1): + self.services[self.CURRENT_F] = s + else: + self.services[self.CURRENT] = s if(s.characteristics[0].uuid == normalize_uuid_str(myUUIDs.VOLTAGE_CHAR)): self.services[self.VOLTAGE] = s @@ -122,6 +127,12 @@ class ble_interface: self.call_callback(self.CURRENT, gain, val) + def __current_f_meas_handler(self, char: BleakGATTCharacteristic, data: bytearray): + val = struct.unpack("