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
|
state ns.CBManagerState
|
||||||
events chan interface{}
|
events chan interface{}
|
||||||
peripherals Peripherals
|
peripherals Peripherals
|
||||||
hr int
|
|
||||||
cd *ns.CBDelegate
|
cd *ns.CBDelegate
|
||||||
cm *ns.CBCentralManager
|
cm *ns.CBCentralManager
|
||||||
|
|
||||||
|
@ -164,6 +163,10 @@ type DiscoverCharacteristicEvent struct {
|
||||||
Characteristic *ns.CBCharacteristic
|
Characteristic *ns.CBCharacteristic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateValueEvent struct {
|
||||||
|
Data []byte
|
||||||
|
}
|
||||||
|
|
||||||
type ConnectEvent struct {
|
type ConnectEvent struct {
|
||||||
Peripheral Peripheral
|
Peripheral Peripheral
|
||||||
}
|
}
|
||||||
|
@ -180,12 +183,6 @@ func (b *BLE) Events() chan interface{} {
|
||||||
return b.events
|
return b.events
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BLE) HR() int {
|
|
||||||
b.Lock()
|
|
||||||
defer b.Unlock()
|
|
||||||
return b.hr
|
|
||||||
}
|
|
||||||
|
|
||||||
func stringState(x ns.CBManagerState) string {
|
func stringState(x ns.CBManagerState) string {
|
||||||
switch x {
|
switch x {
|
||||||
case (ns.CBManagerState)(ns.CBManagerStateResetting):
|
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) {
|
func updateValue(p *ns.CBPeripheral, chr *ns.CBCharacteristic, e *ns.NSError) {
|
||||||
//ble := pdLookup[p]
|
b := pdLookup[p.Ptr()]
|
||||||
ble := gble
|
v := chr.Value()
|
||||||
if chr.UUID().IsEqualTo(hrv_uuid) {
|
b.events <-UpdateValueEvent{
|
||||||
v := chr.Value()
|
Data: C.GoBytes(v.Bytes(), (C.int)(v.Length())),
|
||||||
ble.Lock()
|
|
||||||
ble.hr = hr(v)
|
|
||||||
ble.Unlock()
|
|
||||||
fmt.Printf("Heart rate: %d\n", ble.hr)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user