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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user