Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hugo/feature/Play behavior with RobotKit #898

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,34 @@ struct RobotControlView: View {
}
}

VStack(alignment: .leading, spacing: 5) {
Text("Behaviors")
.font(.title)
HStack {
RobotControlActionButton(title: "Magic Card detected", image: "figure.wave", tint: .orange) {
self.robot.run(.magicCardDetected)
}
RobotControlActionButton(title: "BLE Connection without video", image: "figure.wave", tint: .green) {
self.robot.run(.bleConnectionWithoutVideo)
}
RobotControlActionButton(title: "Launching", image: "figure.wave", tint: .indigo) {
self.robot.run(.launching)
}
RobotControlActionButton(title: "Low battery", image: "figure.wave", tint: .teal) {
self.robot.run(.lowBattery)
}
RobotControlActionButton(title: "Charging full", image: "figure.wave", tint: .orange) {
self.robot.run(.chargingFull)
}
RobotControlActionButton(title: "Medium low battery", image: "figure.wave", tint: .green) {
self.robot.run(.mediumLowBattery)
}
RobotControlActionButton(title: "BLE Connection with video", image: "figure.wave", tint: .indigo) {
self.robot.run(.bleConnectionWithVideo)
}
}
}

VStack(alignment: .leading, spacing: 5) {
Text("Magic Cards")
.font(.title)
Expand Down
48 changes: 48 additions & 0 deletions Modules/RobotKit/Sources/Robot+Behaviors.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Leka - iOS Monorepo
// Copyright APF France handicap
// SPDX-License-Identifier: Apache-2.0

public extension Robot {
enum Behavior: UInt8, CaseIterable {
case stop = 0x00
case launching = 0x01
case sleeping = 0x02
case waiting = 0x03
case blinkOnCharge = 0x04
case lowBattery = 0x05
case chargingEmpty = 0x06
case chargingLow = 0x07
case chargingMedium = 0x08
case chargingHigh = 0x09
case chargingFull = 0x0A
case bleConnectionWithoutVideo = 0x0B
case bleConnectionWithVideo = 0x0C
case working = 0x0D
case fileExchange = 0x0E
case magicCardDetected = 0x0F
case mediumLowBattery = 0x10

// MARK: Internal

static let id: UInt8 = 0x60

var cmd: [UInt8] {
let output: [UInt8] = [
Self.id,
rawValue,
[rawValue].checksum8,
]

return output
}
}

func run(_ behavior: Behavior) {
log.trace("🤖 RUN reinforcer \(behavior)")

let output = Self.commandGenerator(commands: behavior.cmd)

connectedPeripheral?
.sendCommand(output)
}
}
Loading