Skip to content

Commit 5e867ea

Browse files
committed
wip
1 parent 3009e8f commit 5e867ea

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

bt-test2/ViewController.swift

+15-22
Original file line numberDiff line numberDiff line change
@@ -127,34 +127,27 @@ class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDe
127127
return
128128
}
129129

130+
130131
if let characteristics = service.characteristics {
131-
for characteristic in characteristics {
132-
//print("Discovered characteristic: \(characteristic.uuid)")
133-
if let characteristics = service.characteristics {
134-
for c in characteristics {
135-
if c.uuid == CBUUID(string:"0001") {
136-
pWriter = c
137-
let max_len = peripheral.maximumWriteValueLength(for: CBCharacteristicWriteType.withoutResponse)
138-
print("Found writer service with max length \(max_len)")
139-
140-
}
141-
if c.uuid == CBUUID(string:"0002") {
142-
pReader = c
143-
}
144-
}
132+
for c in characteristics {
133+
if c.uuid == CBUUID(string:"799d485c-d354-4ed0-b577-f8ee79ec275a") {
134+
pWriter = c
135+
let max_len = peripheral.maximumWriteValueLength(for: CBCharacteristicWriteType.withoutResponse)
136+
print("Found writer service with max length \(max_len)")
137+
138+
}
139+
if c.uuid == CBUUID(string:"419572a5-9f53-4eb1-8db7-61bcab928867") {
140+
peripheral.setNotifyValue(true, for:c);
141+
pReader = c
145142
}
146143
}
144+
147145
}
148146
}
149147

150148
func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {
151-
if waitingForInfo {
152-
// Issue read
153-
peripheral.readValue(for: pReader!)
154-
waitingForInfo = false
155-
}
156-
if let _ = error {
157-
log("Failed to write")
149+
if let e = error {
150+
log("Failed to write \(e)")
158151
return
159152
}
160153
acks += 1;
@@ -257,7 +250,7 @@ class ViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDe
257250
let sz = [UInt8](_:[0, 1]);
258251
let header = cid + cmd + sz;
259252
let packet = header + [Character("i").asciiValue!];
260-
var report = Data(count: 64);
253+
var report = Data(count: 10);
261254
for (i, c) in packet.enumerated() {
262255
report[i] = c;
263256
}

0 commit comments

Comments
 (0)