diff --git a/ble_darwin.go b/ble_darwin.go index fa499a2..2007292 100644 --- a/ble_darwin.go +++ b/ble_darwin.go @@ -18,7 +18,6 @@ type BLE struct { state ns.CBManagerState events chan interface{} peripherals Peripherals - hr int cd *ns.CBDelegate cm *ns.CBCentralManager @@ -164,6 +163,10 @@ type DiscoverCharacteristicEvent struct { Characteristic *ns.CBCharacteristic } +type UpdateValueEvent struct { + Data []byte +} + type ConnectEvent struct { Peripheral Peripheral } @@ -180,12 +183,6 @@ func (b *BLE) Events() chan interface{} { return b.events } -func (b *BLE) HR() int { - b.Lock() - defer b.Unlock() - return b.hr -} - func stringState(x ns.CBManagerState) string { switch x { case (ns.CBManagerState)(ns.CBManagerStateResetting): @@ -430,14 +427,10 @@ func (p Peripheral) SetNotifyValue(c *ns.CBCharacteristic) { } func updateValue(p *ns.CBPeripheral, chr *ns.CBCharacteristic, e *ns.NSError) { - //ble := pdLookup[p] - ble := gble - if chr.UUID().IsEqualTo(hrv_uuid) { - v := chr.Value() - ble.Lock() - ble.hr = hr(v) - ble.Unlock() - fmt.Printf("Heart rate: %d\n", ble.hr) + b := pdLookup[p.Ptr()] + v := chr.Value() + b.events <-UpdateValueEvent{ + Data: C.GoBytes(v.Bytes(), (C.int)(v.Length())), } }