More methods, start on tier measurements.
This commit is contained in:
@@ -27,8 +27,8 @@ struct Constants{
|
|||||||
static let DEFAULT_MOTOR_PWM = 660
|
static let DEFAULT_MOTOR_PWM = 660
|
||||||
}
|
}
|
||||||
|
|
||||||
enum HEALTH_STATUSES {
|
enum HEALTH_STATUSES: UInt8 {
|
||||||
case GOOD, WARNING, ERROR
|
case GOOD = 0, WARNING, ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SwiftRPLidar {
|
struct SwiftRPLidar {
|
||||||
@@ -127,25 +127,63 @@ class RPLidar{
|
|||||||
return (raw[0], raw[2], raw[3], serialNumber)
|
return (raw[0], raw[2], raw[3], serialNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
public func getHealth(){
|
public func getHealth() throws -> (HEALTH_STATUSES, UInt8){
|
||||||
|
try sendCommand(Constants.GET_HEALTH.asData())
|
||||||
|
let (dataSize, isSingle, dataType) = try readDescriptor()!
|
||||||
|
if (dataSize != Constants.HEALTH_LEN){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if (!isSingle){
|
||||||
|
|
||||||
|
}
|
||||||
|
if(dataType != Constants.HEALTH_TYPE){
|
||||||
|
|
||||||
|
}
|
||||||
|
let raw = try readResponse(dataSize)
|
||||||
|
let status = HEALTH_STATUSES(rawValue: raw[0])!
|
||||||
|
let errorCode = raw[1] << 8 + raw[2]
|
||||||
|
return (status, errorCode)
|
||||||
|
}
|
||||||
|
|
||||||
public func clearInput(){
|
public func clearInput(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func stop(){
|
public func stop() throws{
|
||||||
|
try sendCommand(Constants.STOP.asData())
|
||||||
|
}
|
||||||
|
|
||||||
|
public func reset() throws{
|
||||||
|
try sendCommand(Constants.RESET.asData())
|
||||||
|
}
|
||||||
|
|
||||||
|
public func iterMeasurements(maxBufferMeasurements: Int = 500, _ onMeasure: MeasurementHandler) throws {
|
||||||
|
try startMotor()
|
||||||
|
let (status, errorCode) = try getHealth()
|
||||||
|
if status == .ERROR{
|
||||||
|
// Throw Exception
|
||||||
|
}
|
||||||
|
|
||||||
|
else if status == .WARNING {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func reset(){
|
try sendCommand(Constants.SCAN.asData())
|
||||||
|
let (dataSize, isSingle, dataType) = try readDescriptor()!
|
||||||
|
if (dataSize != 5){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
if isSingle{
|
||||||
|
|
||||||
public func iterMeasurements(maxBufferMeasurements: Int = 500, _ onMeasure: MeasurementHandler) {
|
}
|
||||||
|
if dataType != Constants.SCAN_TYPE{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
for _ in 0..<500{
|
||||||
|
let raw = try readResponse(Int(dataSize))
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public func iterScans(maxBufferMeasurements: Int = 500, minLength: Int = 5, _ onScan: ScanHandler){
|
public func iterScans(maxBufferMeasurements: Int = 500, minLength: Int = 5, _ onScan: ScanHandler){
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user