diff --git a/Documentation/bluetooth/ecg.rst b/Documentation/bluetooth/ecg.rst index 3af7cf771a757baf4a9ab6f4ab0fccb1046761e1..42d39a331858cc6b7395a7378aa4e92e14d1e047 100644 --- a/Documentation/bluetooth/ecg.rst +++ b/Documentation/bluetooth/ecg.rst @@ -25,3 +25,5 @@ ECG samples characteristic List of 16 bit samples (big endian). Enable notifications to receive a stream of samples while the ECG app is open. + +The first 16 bit are a sample counter (big endian). diff --git a/preload/apps/ecg/__init__.py b/preload/apps/ecg/__init__.py index 3b9b5fa7de2d1f8dfa11f4fd91fd2bf5796dfdd8..971b59e11377c341134e3a1cf12b596f89934e60 100644 --- a/preload/apps/ecg/__init__.py +++ b/preload/apps/ecg/__init__.py @@ -85,6 +85,7 @@ class ECG: self.disp.backlight(20) else: self.ble_streaming = True + self.ble_sample_count = 0 if not config.get_option("BLE Disp"): self.disp.backlight(0) @@ -173,10 +174,12 @@ class ECG: def callback_ecg(self, datasets): if self.ble_streaming: + self.ble_sample_count += len(datasets) self.b.gatts_notify( 1, self.ecg_data_handle, - struct.pack(">" + ("h" * len(datasets)), *datasets), + struct.pack(">h", self.ble_sample_count & 0xFFFF) + + struct.pack(">" + ("h" * len(datasets)), *datasets), ) # Don't update the screen if it should be off during a connection