Skip to content

Commit

Permalink
✨ (RobotKit): Add Behaviors
Browse files Browse the repository at this point in the history
  • Loading branch information
HPezz committed Mar 20, 2024
1 parent 79a34bc commit 7227216
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
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)
}
}

0 comments on commit 7227216

Please sign in to comment.