Conform to IteratorProtocol for scanning.

I've left the old callback implementations in for now, undecided whether these should be removed. The nice thing about the callback method is that it's more compact, however the logic behind it is less clear.
This commit is contained in:
Piv
2020-10-02 23:01:53 +09:30
parent 3cc661542b
commit f4ef8ed829
2 changed files with 155 additions and 24 deletions

View File

@@ -11,10 +11,21 @@ catch {
func main() throws {
let serialPort = SerialPort(path: "/dev/cu.usbserial-0001")
let lidar = try SwiftRPLidar(onPort: serialPort)
var index = 0
try lidar.iterMeasurements { measurement in
print("Quality: ",measurement.quality, ", Angle: ", measurement.angle, ", Distance: ", measurement.distance)
return true
index += 1
return index <= 10
}
index = 0
_ = try lidar.startScanning()
for measurement in lidar {
print("Quality: ",measurement.quality, ", Angle: ", measurement.angle, ", Distance: ", measurement.distance)
index += 1
if index > 10 {
break
}
}
}