Skip to content

Commit

Permalink
🔀 Merge branch 'yann/feature/lekaupdater/use-robotkit'
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Nov 21, 2023
2 parents e9e51c5 + 3dd3075 commit 55ff81e
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 243 deletions.
1 change: 1 addition & 0 deletions Apps/LekaUpdater/Project.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let project = Project.iOSApp(
dependencies: [
.project(target: "DesignKit", path: Path("../../Modules/DesignKit")),
.project(target: "BLEKit", path: Path("../../Modules/BLEKit")),
.project(target: "RobotKit", path: Path("../../Modules/RobotKit")),
.project(target: "LocalizationKit", path: Path("../../Modules/LocalizationKit")),
.external(name: "Version"),
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import Combine
import Foundation
import RobotKit
import Version

// MARK: - General (user facing) update process states, errors
Expand Down Expand Up @@ -48,7 +49,7 @@ class UpdateProcessController {
public var sendingFileProgression = CurrentValueSubject<Float, Never>(0.0)

init() {
let currentRobotVersion = globalRobotManager.osVersion
let currentRobotVersion = Version(Robot.shared.osVersion.value)

switch currentRobotVersion {
case Version(1, 0, 0), Version(1, 1, 0), Version(1, 2, 0):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BLEKit
import Combine
import Foundation
import GameplayKit
import RobotKit
import Version

// MARK: - events
Expand Down Expand Up @@ -112,7 +113,7 @@ private class StateSettingDestinationPath: GKState, StateEventProcessor {
}
)

globalRobotManager.robotPeripheral?.send(destinationPath.data(using: .utf8)!, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(destinationPath.data(using: .utf8)!, forCharacteristic: characteristic)
}
}

Expand Down Expand Up @@ -210,11 +211,9 @@ private class StateSendingFile: GKState, StateEventProcessor {
}

private func isInCriticalSection() -> Bool {
guard let battery = globalRobotManager.battery, let isCharging = globalRobotManager.isCharging else {
return true
}
let isNotCharging = !Robot.shared.isCharging.value

let isNotCharging = !isCharging
let battery = Robot.shared.battery.value
let isNearBatteryLevelChange =
23...27 ~= battery || 48...52 ~= battery || 73...77 ~= battery || 88...92 ~= battery

Expand All @@ -229,7 +228,7 @@ private class StateSendingFile: GKState, StateEventProcessor {

let dataToSend = globalFirmwareManager.data[startIndex...endIndex]

globalRobotManager.robotPeripheral?.send(dataToSend, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(dataToSend, forCharacteristic: characteristic)
}
}

Expand Down Expand Up @@ -269,7 +268,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(majorData, forCharacteristic: majorCharacteristic)
Robot.shared.connectedPeripheral?.send(majorData, forCharacteristic: majorCharacteristic)

let minorData = Data([globalFirmwareManager.minor])

Expand All @@ -278,7 +277,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(minorData, forCharacteristic: minorCharacteristic)
Robot.shared.connectedPeripheral?.send(minorData, forCharacteristic: minorCharacteristic)

let revisionData = globalFirmwareManager.revision.data

Expand All @@ -287,7 +286,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic)
Robot.shared.connectedPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic)
}

private func applyUpdate() {
Expand All @@ -298,7 +297,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(applyValue, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(applyValue, forCharacteristic: characteristic)
}
}

Expand Down Expand Up @@ -345,7 +344,7 @@ private class StateWaitingForRobotToReboot: GKState, StateEventProcessor {
},
receiveValue: { robotDiscoveryList in
let robotDetected = robotDiscoveryList.first { robotDiscovery in
robotDiscovery.robotPeripheral == globalRobotManager.robotPeripheral
robotDiscovery.robotPeripheral == Robot.shared.connectedPeripheral
}
if let robotDetected = robotDetected {
self.isRobotUpToDate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import BLEKit
import Combine
import Foundation
import GameplayKit
import RobotKit
import Version

// MARK: - events
Expand Down Expand Up @@ -112,7 +113,7 @@ private class StateSettingFileExchangeState: GKState, StateEventProcessor {
}
)

globalRobotManager.robotPeripheral?.send(data, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(data, forCharacteristic: characteristic)
}
}

Expand Down Expand Up @@ -152,7 +153,7 @@ private class StateSettingDestinationPath: GKState, StateEventProcessor {
}
)

globalRobotManager.robotPeripheral?.send(destinationPath.data(using: .utf8)!, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(destinationPath.data(using: .utf8)!, forCharacteristic: characteristic)
}
}

Expand Down Expand Up @@ -188,7 +189,7 @@ private class StateClearingFile: GKState, StateEventProcessor {
}
)

globalRobotManager.robotPeripheral?.send(data, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(data, forCharacteristic: characteristic)
}
}

Expand Down Expand Up @@ -290,7 +291,7 @@ private class StateSendingFile: GKState, StateEventProcessor {
let dataToSend = globalFirmwareManager.data[startIndex...endIndex]

if let characteristic = characteristic {
globalRobotManager.robotPeripheral?.send(dataToSend, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(dataToSend, forCharacteristic: characteristic)
}
}
}
Expand Down Expand Up @@ -331,7 +332,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(majorData, forCharacteristic: majorCharacteristic)
Robot.shared.connectedPeripheral?.send(majorData, forCharacteristic: majorCharacteristic)

sleep(1)

Expand All @@ -342,7 +343,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(minorData, forCharacteristic: minorCharacteristic)
Robot.shared.connectedPeripheral?.send(minorData, forCharacteristic: minorCharacteristic)

sleep(1)

Expand All @@ -353,7 +354,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic)
Robot.shared.connectedPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic)
}

private func applyUpdate() {
Expand All @@ -364,7 +365,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
serviceUUID: BLESpecs.FirmwareUpdate.service
)

globalRobotManager.robotPeripheral?.send(applyValue, forCharacteristic: characteristic)
Robot.shared.connectedPeripheral?.send(applyValue, forCharacteristic: characteristic)
}
}

Expand Down Expand Up @@ -411,7 +412,7 @@ private class StateWaitingForRobotToReboot: GKState, StateEventProcessor {
},
receiveValue: { robotDiscoveryList in
let robotDetected = robotDiscoveryList.first { robotDiscovery in
robotDiscovery.robotPeripheral == globalRobotManager.robotPeripheral
robotDiscovery.robotPeripheral == Robot.shared.connectedPeripheral
}
if let robotDetected = robotDetected {
self.isRobotUpToDate =
Expand Down
1 change: 0 additions & 1 deletion Apps/LekaUpdater/Sources/MainApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import SwiftUI

var globalFirmwareManager = FirmwareManager()
var globalBleManager = BLEManager.live()
var globalRobotManager = RobotManager()

@main
struct LekaUpdaterApp: App {
Expand Down
164 changes: 0 additions & 164 deletions Apps/LekaUpdater/Sources/Model/RobotManager.swift

This file was deleted.

Loading

0 comments on commit 55ff81e

Please sign in to comment.