Return subscribed characteristic values as []byte in
UpdateValueEvent{}
This commit is contained in:
parent
822b3529c0
commit
f53dd7481a
|
@ -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) {
|
||||
b := pdLookup[p.Ptr()]
|
||||
v := chr.Value()
|
||||
ble.Lock()
|
||||
ble.hr = hr(v)
|
||||
ble.Unlock()
|
||||
fmt.Printf("Heart rate: %d\n", ble.hr)
|
||||
b.events <-UpdateValueEvent{
|
||||
Data: C.GoBytes(v.Bytes(), (C.int)(v.Length())),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user