Skip to content
Snippets Groups Projects
Commit b9f35c42 authored by schneider's avatar schneider
Browse files

ecg: handle ble inactive exception

parent 94cc9f71
No related branches found
No related tags found
No related merge requests found
...@@ -8,9 +8,9 @@ import math ...@@ -8,9 +8,9 @@ import math
import struct import struct
import itertools import itertools
import bluetooth import bluetooth
from ecg.settings import * import ecg.settings
config = ecg_settings() config = ecg.settings.ecg_settings()
WIDTH = 160 WIDTH = 160
HEIGHT = 80 HEIGHT = 80
...@@ -89,6 +89,7 @@ class ECG: ...@@ -89,6 +89,7 @@ class ECG:
self.disp.backlight(0) self.disp.backlight(0)
def __init__(self): def __init__(self):
try:
self.b = bluetooth.BLE() self.b = bluetooth.BLE()
self.b.active(True) self.b.active(True)
self.b.irq(self.ble_irq) self.b.irq(self.ble_irq)
...@@ -106,6 +107,9 @@ class ECG: ...@@ -106,6 +107,9 @@ class ECG:
# Disable streaming by default # Disable streaming by default
self.ble_streaming = False self.ble_streaming = False
self.b.gatts_write(self.ecg_cccd_handle, "\x00\x00") self.b.gatts_write(self.ecg_cccd_handle, "\x00\x00")
except OSError:
self.ble_streaming = False
pass
leds.dim_top(1) leds.dim_top(1)
...@@ -169,15 +173,11 @@ class ECG: ...@@ -169,15 +173,11 @@ class ECG:
def callback_ecg(self, datasets): def callback_ecg(self, datasets):
if self.ble_streaming: if self.ble_streaming:
# try:
if 1:
self.b.gatts_notify( self.b.gatts_notify(
1, 1,
self.ecg_data_handle, self.ecg_data_handle,
struct.pack(">" + ("h" * len(datasets)), *datasets), struct.pack(">" + ("h" * len(datasets)), *datasets),
) )
# except:
pass
# Don't update the screen if it should be off during a connection # Don't update the screen if it should be off during a connection
if not config.get_option("BLE Disp"): if not config.get_option("BLE Disp"):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment