-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge branch 'ladislas/feature/robotkit+send_commands'
- Loading branch information
Showing
11 changed files
with
660 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
extension Array where Element == UInt8 { | ||
|
||
public var checksum8: UInt8 { | ||
var checksum: Int = 0 | ||
|
||
for value in self { | ||
checksum = (Int(value) + checksum) % 256 | ||
} | ||
|
||
return UInt8(checksum) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import Foundation | ||
|
||
extension Robot { | ||
|
||
public struct Color { | ||
|
||
public var data: [UInt8] | ||
|
||
init(_ values: UInt8...) { | ||
guard values.count == 3 else { fatalError() } | ||
data = values | ||
} | ||
|
||
public var red: UInt8 { | ||
data[0] | ||
} | ||
|
||
public var green: UInt8 { | ||
data[1] | ||
} | ||
|
||
public var blue: UInt8 { | ||
data[2] | ||
} | ||
|
||
public static let black: Color = Color(0, 0, 0) | ||
public static let white: Color = Color(255, 255, 255) | ||
|
||
public static let red: Color = Color(255, 0, 0) | ||
public static let green: Color = Color(0, 150, 0) | ||
public static let blue: Color = Color(0, 0, 255) | ||
|
||
public static let orange: Color = Color(248, 100, 0) | ||
public static let yellow: Color = Color(255, 255, 0) | ||
public static let lightBlue: Color = Color(0, 121, 255) | ||
public static let purple: Color = Color(20, 0, 80) | ||
public static let pink: Color = Color(255, 0, 127) | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Leka - iOS Monorepo | ||
// Copyright 2023 APF France handicap | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import Foundation | ||
|
||
extension Robot { | ||
|
||
static let kHeaderPattern: [UInt8] = [0x2A, 0x2A, 0x2A, 0x2A] | ||
|
||
func commandGenerator(commands: [UInt8]...) -> Data { | ||
commandGenerator(commands: commands) | ||
} | ||
|
||
func commandGenerator(commands: [[UInt8]]) -> Data { | ||
let commands = commands.filter { $0 != [] } | ||
var output: [UInt8] = [] | ||
|
||
output.append(contentsOf: Robot.kHeaderPattern) | ||
output.append(UInt8(commands.count)) | ||
|
||
for command in commands { | ||
output.append(contentsOf: command) | ||
} | ||
|
||
return Data(output) | ||
} | ||
|
||
} |
Oops, something went wrong.