Use C.GoBytes() in examples/bluetooth.
This commit is contained in:
parent
2fe435f137
commit
49fd749fe3
|
@ -5,7 +5,6 @@ import "C"
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"unsafe"
|
|
||||||
"gitlab.wow.st/gmp/nswrap/examples/bluetooth/ns"
|
"gitlab.wow.st/gmp/nswrap/examples/bluetooth/ns"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -59,24 +58,16 @@ func discoverServices(p *ns.CBPeripheral, e *ns.NSError) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func hr(d *ns.NSData) int {
|
func hr(d *ns.NSData) int {
|
||||||
var x []byte
|
|
||||||
if l := int(d.Length()); l < 4 {
|
if l := int(d.Length()); l < 4 {
|
||||||
return 0
|
return 0
|
||||||
} else {
|
|
||||||
bs := d.Bytes()
|
|
||||||
x = make([]byte,l)
|
|
||||||
for i := 0; i < l; i++ {
|
|
||||||
x[i] = *(*byte)(unsafe.Pointer(uintptr(bs) + uintptr(i)))
|
|
||||||
}
|
}
|
||||||
}
|
x := C.GoBytes(d.Bytes(),4)
|
||||||
var hr int
|
|
||||||
flags := x[0]
|
flags := x[0]
|
||||||
if flags & 0x80 != 0 { // uint16 format
|
if flags & 0x80 != 0 { // uint16 format
|
||||||
hr = int(binary.BigEndian.Uint16(x[1:2]))
|
return int(binary.BigEndian.Uint16(x[1:2]))
|
||||||
} else {
|
} else {
|
||||||
hr = int(x[1])
|
return int(x[1])
|
||||||
}
|
}
|
||||||
return hr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func discoverCharacteristics(p *ns.CBPeripheral, s *ns.CBService, e *ns.NSError) {
|
func discoverCharacteristics(p *ns.CBPeripheral, s *ns.CBService, e *ns.NSError) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user