Merge branch 'master' of ssh://vato.ddns.net:222/vato007/swiftrplidar

This commit is contained in:
=
2020-07-12 10:59:05 +09:30
4 changed files with 32 additions and 10 deletions

View File

@@ -6,21 +6,16 @@ import PackageDescription
let package = Package(
name: "SwiftRPLidar",
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.library(
name: "SwiftRPLidar",
targets: ["SwiftRPLidar"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://vato.ddns.net/gitlab/vato007/SwiftSerial.git", .branch("dtr_support"))
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "SwiftRPLidar",
dependencies: [.product(name: "SwiftSerial", package: "SwiftSerial")]),
dependencies: []),
.testTarget(
name: "SwiftRPLidarTests",
dependencies: ["SwiftRPLidar"]),

View File

@@ -7,4 +7,5 @@ public protocol LidarSerial {
func openPort() throws;
func readData(ofLength: Int) throws -> Data;
func writeData(_ data: Data) throws -> Int;
func setBaudrate(baudrate: Int)
}

View File

@@ -46,10 +46,10 @@ func processScan(raw: Data) throws -> LidarScan {
}
public struct LidarScan{
var newScan: Bool
var quality: UInt8
var angle: Float
var distance: Float
public let newScan: Bool
public let quality: UInt8
public let angle: Float
public let distance: Float
}
@@ -78,6 +78,7 @@ public class SwiftRPLidar {
public func connect() throws {
disconnect()
try serialPort!.openPort()
serialPort?.setBaudrate(baudrate: 115200)
}
public func disconnect(){

View File

@@ -13,3 +13,28 @@ final class SwiftRPLidarTests: XCTestCase {
("testExample", testExample),
]
}
struct MockSerialPort: LidarSerial {
var dtr: Bool
var inWaiting: Int
func closePort() {
}
func openPort() throws {
}
func readData(ofLength: Int) throws -> Data {
return Data()
}
func writeData(_ data: Data) throws -> Int {
return 0
}
func setBaudrate(baudrate: Int) {
}
}