Return subscribed characteristic values as []byte in

UpdateValueEvent{}
This commit is contained in:
Greg 2019-10-24 18:30:02 -04:00
parent 822b3529c0
commit f53dd7481a

View File

@ -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())),
}
}