Skip to content

Commit

Permalink
⚡ (LekaUpdater): Set version and apply update in cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
YannLocatelli committed May 7, 2024
1 parent 56eacf8 commit 0b22f9a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
}

override func didEnter(from _: GKState?) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.setMajorMinorRevision)
DispatchQueue.main.asyncAfter(deadline: .now() + 2, execute: self.applyUpdate)
self.setMajor()
}

override func willExit(to _: GKState) {
Expand All @@ -282,30 +281,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {

private var cancellables: Set<AnyCancellable> = []

private func setMajorMinorRevision() {
private func setMajor() {
let majorData = Data([globalFirmwareManager.major])

let majorCharacteristic = CharacteristicModelWriteOnly(
characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMajor,
serviceUUID: BLESpecs.FirmwareUpdate.service
serviceUUID: BLESpecs.FirmwareUpdate.service,
onWrite: self.setMinor
)

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

private func setMinor() {
let minorData = Data([globalFirmwareManager.minor])

let minorCharacteristic = CharacteristicModelWriteOnly(
characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMinor,
serviceUUID: BLESpecs.FirmwareUpdate.service
serviceUUID: BLESpecs.FirmwareUpdate.service,
onWrite: self.setRevision
)

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

private func setRevision() {
let revisionData = globalFirmwareManager.revision.data

let revisionCharacteristic = CharacteristicModelWriteOnly(
characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionRevision,
serviceUUID: BLESpecs.FirmwareUpdate.service
serviceUUID: BLESpecs.FirmwareUpdate.service,
onWrite: self.applyUpdate
)

Robot.shared.connectedPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {
}

override func didEnter(from _: GKState?) {
DispatchQueue.main.asyncAfter(deadline: .now() + 1, execute: self.setMajorMinorRevision)
DispatchQueue.main.asyncAfter(deadline: .now() + 5, execute: self.applyUpdate)
self.setMajor()
}

override func willExit(to _: GKState) {
Expand All @@ -356,34 +355,37 @@ private class StateApplyingUpdate: GKState, StateEventProcessor {

private var cancellables: Set<AnyCancellable> = []

private func setMajorMinorRevision() {
private func setMajor() {
let majorData = Data([globalFirmwareManager.major])

let majorCharacteristic = CharacteristicModelWriteOnly(
characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMajor,
serviceUUID: BLESpecs.FirmwareUpdate.service
serviceUUID: BLESpecs.FirmwareUpdate.service,
onWrite: self.setMinor
)

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

sleep(1)

private func setMinor() {
let minorData = Data([globalFirmwareManager.minor])

let minorCharacteristic = CharacteristicModelWriteOnly(
characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionMinor,
serviceUUID: BLESpecs.FirmwareUpdate.service
serviceUUID: BLESpecs.FirmwareUpdate.service,
onWrite: self.setRevision
)

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

sleep(1)

private func setRevision() {
let revisionData = globalFirmwareManager.revision.data

let revisionCharacteristic = CharacteristicModelWriteOnly(
characteristicUUID: BLESpecs.FirmwareUpdate.Characteristics.versionRevision,
serviceUUID: BLESpecs.FirmwareUpdate.service
serviceUUID: BLESpecs.FirmwareUpdate.service,
onWrite: self.applyUpdate
)

Robot.shared.connectedPeripheral?.send(revisionData, forCharacteristic: revisionCharacteristic)
Expand Down

0 comments on commit 0b22f9a

Please sign in to comment.