Skip to content

Commit

Permalink
Updated the documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jegge committed Sep 5, 2023
1 parent 3bfc1ef commit d7a0a10
Show file tree
Hide file tree
Showing 19 changed files with 139 additions and 62 deletions.
32 changes: 16 additions & 16 deletions Sources/OldMoofKit/Bike/Bike.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import CoreBluetooth
import Combine
import OSLog

/// A connectable bike
/// A connectable bike.
public final class Bike: Codable {
enum CodingKeys: String, CodingKey {
case identifier
Expand All @@ -21,41 +21,41 @@ public final class Bike: Codable {
/// The details of the bike.
public let details: BikeDetails

/// Subscribe this publisher to get informed about changes of this bike's ``state``
/// Subscribe this publisher to get informed about changes of this bike's ``state``.
public let statePublisher = PassthroughSubject<BikeState, Never>()
/// Subscribe this publisher to get informed about errors that may occur.
///
/// These errors do not stem from the bike, but rather from within this api.
/// To get informed about the bike's error codes, use ``errorCodePublisher``
/// To get informed about the bike's error codes, use ``errorCodePublisher``.
public let errorPublisher = PassthroughSubject<Error, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``lock``
/// Subscribe this publisher to get informed about changes of this bike's ``lock``.
public let lockPublisher = PassthroughSubject<Lock, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``alarm``
/// Subscribe this publisher to get informed about changes of this bike's ``alarm``.
public let alarmPublisher = PassthroughSubject<Alarm, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``lighting``
/// Subscribe this publisher to get informed about changes of this bike's ``lighting``.
public let lightingPublisher = PassthroughSubject<Lighting, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``batteryLevel``
/// Subscribe this publisher to get informed about changes of this bike's ``batteryLevel``.
public let batteryLevelPublisher = PassthroughSubject<Int, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``batteryState``
/// Subscribe this publisher to get informed about changes of this bike's ``batteryState``.
public let batteryStatePublisher = PassthroughSubject<BatteryState, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``moduleState``
/// Subscribe this publisher to get informed about changes of this bike's ``moduleState``.
public let moduleStatePublisher = PassthroughSubject<ModuleState, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``errorCode``
/// Subscribe this publisher to get informed about changes of this bike's ``errorCode``.
///
/// This error code stems from the bike. To get informed about errors coming from within this api,
/// use ``errorPublisher`` instead.
public let errorCodePublisher = PassthroughSubject<ErrorCode, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``motorAssistance``
/// Subscribe this publisher to get informed about changes of this bike's ``motorAssistance``.
public let motorAssistancePublisher = PassthroughSubject<MotorAssistance, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``mutedSounds``
/// Subscribe this publisher to get informed about changes of this bike's ``mutedSounds``.
public let mutedSoundsPublisher = PassthroughSubject<MutedSounds, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``speed``
/// Subscribe this publisher to get informed about changes of this bike's ``speed``.
public let speedPublisher = PassthroughSubject<Int, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``distance``
/// Subscribe this publisher to get informed about changes of this bike's ``distance``.
public let distancePublisher = PassthroughSubject<Double, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``region``
/// Subscribe this publisher to get informed about changes of this bike's ``region``.
public let regionPublisher = PassthroughSubject<Region, Never>()
/// Subscribe this publisher to get informed about changes of this bike's ``unit``
/// Subscribe this publisher to get informed about changes of this bike's ``unit``.
public let unitPublisher = PassthroughSubject<Unit, Never>()

private var key: Data
Expand Down
5 changes: 5 additions & 0 deletions Sources/OldMoofKit/Bike/BikeHardware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@

import Foundation

/// Represents the hardware capabilities a bike may have.
public struct BikeHardware: OptionSet {
public let rawValue: Int

public init(rawValue: Int) {
self.rawValue = rawValue
}

/// This bike has an electronically disengaging, physical lock.
public static let elock = BikeHardware(rawValue: 1 << 0)
/// This bike has an automatic anti-theft device.
public static let alarm = BikeHardware(rawValue: 1 << 1)
/// This bike has a motor.
public static let motor = BikeHardware(rawValue: 1 << 2)
/// This bike has a speaker.
public static let speaker = BikeHardware(rawValue: 1 << 3)
}
4 changes: 4 additions & 0 deletions Sources/OldMoofKit/Bike/Data/Alarm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// Created by Sebastian Boettcher on 09.08.23.
//

// The alarm state of the bike.
public enum Alarm: UInt8 {
// The anti-theft device is disabled.
case off = 0
// The anti-theft device has to be armed manually.
case manual = 1
// The bike will automatically arm the anti-theft device after a period of time.
case automatic = 2
}
4 changes: 4 additions & 0 deletions Sources/OldMoofKit/Bike/Data/BatteryState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Sebastian Boettcher on 30.08.23.
//

/// The state of the battery. For bikes having a motor, this refers to the motor battery.
/// Otherwise, this refers to the module battery.
public enum BatteryState: UInt8 {
/// The battery is currently discharging.
case discharging = 0
/// The battery is currently charging.
case charging = 1
}
3 changes: 3 additions & 0 deletions Sources/OldMoofKit/Bike/Data/BikeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
// Created by Sebastian Boettcher on 02.09.23.
//

/// The connection state of the bike.
public enum BikeState {
/// The bike is currently connected.
case connected
/// The bike is currently disconnected.
case disconnected
}
2 changes: 2 additions & 0 deletions Sources/OldMoofKit/Bike/Data/ErrorCode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import Foundation

/// An error code that got reported from the bike.
public struct ErrorCode: CustomStringConvertible, Equatable {

let data: Data
Expand All @@ -18,6 +19,7 @@ public struct ErrorCode: CustomStringConvertible, Equatable {
init(code: UInt8) {
self.data = Data([code])
}

init(rawData: Data) {
self.data = rawData
}
Expand Down
4 changes: 4 additions & 0 deletions Sources/OldMoofKit/Bike/Data/Lighting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// Created by Sebastian Boettcher on 09.08.23.
//

/// The lighting mode of the bike.
public enum Lighting: UInt8 {
/// The lights will switch on or off depending on the ambient light.
case automatic = 0
/// The lights will always be switched on.
case alwaysOn = 1
/// The lights will be switched off.
case off = 2
}
5 changes: 5 additions & 0 deletions Sources/OldMoofKit/Bike/Data/Lock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
// Created by Sebastian Boettcher on 30.08.23.
//

/// The lock state of the bike.
public enum Lock: UInt8 {
/// The bike is currently unlocked.
case unlocked = 0
/// The bike is currently locked.
case locked = 1
/// The bike is triggered to unlock and is awaiting physical user interaction.
case awaitingUnlock = 2

/// Creates a complementary lock state.
public func toggle () -> Lock {
return (self == .locked) ? .unlocked : .locked
}
Expand Down
10 changes: 10 additions & 0 deletions Sources/OldMoofKit/Bike/Data/ModuleState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@
// Created by Sebastian Boettcher on 10.08.23.
//

/// The module state of the bike.
public enum ModuleState: UInt8 {
/// The bike is currently on.
case on = 0
/// The bike is currently off.
case off = 1
/// The bike is currently being shipped.
case shipping = 2
/// The bike is in standby.
case standby = 3
/// The bike's anti-theft device triggered once.
case alarmOne = 4
/// The bike's anti-theft device triggered twice.
case alarmTwo = 5
/// The bike's anti-theft device triggered thrice.
case alarmThree = 6
/// The bike is currenty sleeping.
case sleeping = 7
/// The bike is currently tracking.
case tracking = 8
}
6 changes: 6 additions & 0 deletions Sources/OldMoofKit/Bike/Data/MotorAssistance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@
// Created by Sebastian Boettcher on 12.08.23.
//

/// The level of motor assistance of the bike.
public enum MotorAssistance: UInt8 {
/// The motor assistance is switched off.
case off = 0
/// The motor assistance is on level 1.
case one = 1
/// The motor assistance is on level 2.
case two = 2
/// The motor assistance is on level 3.
case three = 3
/// The motor assistance is on level 4.
case four = 4
}
14 changes: 13 additions & 1 deletion Sources/OldMoofKit/Bike/Data/MutedSounds.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,50 @@
// Created by Sebastian Boettcher on 19.08.23.
//

/// Defines which sounds are muted and wich sounds can be heard, provided that the bike has a speaker.
public struct MutedSounds: OptionSet {
public let rawValue: UInt16

public init(rawValue: UInt16) {
self.rawValue = rawValue
}

/// The sound that signals feedback to configuration changes.
public static let feedback = MutedSounds(rawValue: 1 << 0)
// public static let unknown1 = MuteState(rawValue: 1 << 1) // long tick on unlock, long tick on lock
// public static let unknown2 = MuteState(rawValue: 1 << 2) // long tick on lock
/// The sound that signals locking the bike.
public static let timer = MutedSounds(rawValue: 1 << 3) // no lockTimer
// public static let unknown4 = MuteState(rawValue: 1 << 4) // long tick on unlock, short tick on lock
// public static let unknown5 = MuteState(rawValue: 1 << 5) // very long tick on unlock, short tick on lock
// public static let unknown6 = MuteState(rawValue: 1 << 6)
// public static let unknown7 = MuteState(rawValue: 1 << 7)

/// The sound that signals the bike got locked.
public static let lock = MutedSounds(rawValue: 1 << 8)
/// The sound that signals the bike got unlocked.
public static let unlock = MutedSounds(rawValue: 1 << 9)
// public static let unknownA = MuteState(rawValue: 1 << 10)
// public static let unknownB = MuteState(rawValue: 1 << 11)
/// The sound that signals that the bike wakes up from sleep.
public static let wakeup = MutedSounds(rawValue: 1 << 12)
/// The sound that signals that the bike shuts down.
public static let sleep = MutedSounds(rawValue: 1 << 13)
// public static let unknownE = MuteState(rawValue: 1 << 14)
// public static let unknownF = MuteState(rawValue: 1 << 15)

/// All sounds.
public static let all = MutedSounds([.feedback, .lock, .unlock, .wakeup, .sleep, .timer])
/// No sound at all.
public static let none = MutedSounds([])
/// All sounds related to the ``ModuleState``.
public static let moduleState = MutedSounds([.wakeup, .sleep])
/// All sounds related to the ``Lock``.
public static let lockState = MutedSounds([.lock, .unlock])
}

extension MutedSounds: CustomStringConvertible {
public static var debugDescriptions: [(Self, String)] = [
static var debugDescriptions: [(Self, String)] = [
(.feedback, "feedback"),
(.timer, "timer"),
(.lock, "lock"),
Expand All @@ -46,6 +57,7 @@ extension MutedSounds: CustomStringConvertible {
(.sleep, "sleep")
]

/// A human readable description of this instance.
public var description: String {
if self == .none {
return "none"
Expand Down
4 changes: 2 additions & 2 deletions Sources/OldMoofKit/Bike/Data/Parameters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import Foundation

public struct Parameters: CustomStringConvertible {
struct Parameters: CustomStringConvertible {
let data: Data?
let alarm: Alarm?
let moduleState: ModuleState
Expand All @@ -24,7 +24,7 @@ public struct Parameters: CustomStringConvertible {
let distance: Double
let errorCode: ErrorCode

public var description: String {
var description: String {
let motorAssistance = self.motorAssistance == nil ? "-" : "\(self.motorAssistance!)"
let alarm = self.alarm == nil ? "-" : "\(self.alarm!)"
let region = self.region == nil ? "-" : "\(self.region!)"
Expand Down
14 changes: 9 additions & 5 deletions Sources/OldMoofKit/Bike/Data/Region.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
// Created by Sebastian Boettcher on 20.08.23.
//

/// The region that this bike is currently located in. This implicitly sets the speed limit.
public enum Region: UInt8 {
case invalid = 255
case eu = 0 // 25 kmh
case us = 1 // 32 kmh
case offroad = 2 // 37 kmh
case japan = 3 // 24 kmh
/// The European Union. Enforces a speed limit of 25 km/h.
case eu = 0
/// The United States of America. Enforces a speed limit of 32 km/h.
case us = 1
/// Offroad. Allows the maximum possible speed of 37 km/h.
case offroad = 2
/// Japan. Enforces a speed limit of 24 km/h.
case japan = 3
}
15 changes: 15 additions & 0 deletions Sources/OldMoofKit/Bike/Data/Sound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,34 @@
// Created by Sebastian Boettcher on 19.08.23.
//

/// A sound that the bike may play.
public enum Sound: UInt8 {
/// Played when an option got selected.
case selection = 0x01
/// Played when an action turned out not ok.
case negativeBeep = 0x02
/// Played when an action turned out ok.
case affirmativeBeep = 0x03
/// Played when the timer ticks a countdown for a short period of time.
case shortCountdown = 0x04
/// Played when the timer ticks a countdown for a long period of time.
case longCountdown = 0x05
/// Played when beginning the manual disarm sequence.
case beginDisarm = 0x06
/// Played when using the bell (soft).
case bell = 0x07
/// Played when using the bell (hard).
case horn = 0x08
/// Played when the bike got locked.
case lock = 0x09
/// Played when the bike got unlocked.
case unlock = 0x0A
/// Played when the bike's anti-theft device triggers.
case alarm1 = 0x0B
/// Played when the bike's anti-theft device triggers.
case alarm2 = 0x0C
/// Played when the bike wakes up.
case wakeup = 0x0D
/// Played when the bike shuts down.
case sleep = 0x0E
}
3 changes: 3 additions & 0 deletions Sources/OldMoofKit/Bike/Data/Unit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
// Created by Sebastian Boettcher on 20.08.23.
//

/// The measuring unit used for ``Bike/speed`` and ``Bike/distance``.
public enum Unit: UInt8 {
/// The bike's ``Bike/speed`` is measured in km/h and ``Bike/distance`` is measured in km.
case metric = 0
/// The bike's ``Bike/speed`` is measured in mph and ``Bike/distance`` is measured in miles.
case imperial = 1
}
24 changes: 12 additions & 12 deletions Sources/OldMoofKit/Bike/Profiles/Profiles.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,29 @@ public enum BleProfile: LosslessStringConvertible, Hashable, Codable {
}
}

/// The ble profile of a SmartBike
/// The ble profile of a SmartBike.
case smartBike2016
/// The ble profile of a Smart S or Smart X
/// The ble profile of a Smart S or Smart X.
case smartBike2018
/// The ble profile of an Electrified S or Electrified X (2016)
/// The ble profile of an Electrified S or Electrified X (2016).
case electrified2016
/// The ble profile of an Electrified S or Electrified X (2016 - 2017)
/// The ble profile of an Electrified S or Electrified X (2016 - 2017).
case electrified20162017
/// The ble profile of an Electrified S or Electrified X (2017)
/// The ble profile of an Electrified S or Electrified X (2017).
case electrified2017
/// The ble profile of an S2 or X2
/// The ble profile of an S2 or X2.
case electrified2018
/// The ble profile of an S3 or X3
/// The ble profile of an S3 or X3.
case electrified2020
/// The ble profile of an unknown bike
/// The ble profile of an unknown bike.
case electrified2021
/// The ble profile of an unknown bike
/// The ble profile of an unknown bike.
case electrified2022
/// The ble profile of an unknown bike
/// The ble profile of an unknown bike.
case electrified2023track1a
/// The ble profile of an unknown bike
/// The ble profile of an unknown bike.
case electrified2023track1b
/// The ble profile of an unknown bike
/// The ble profile of an unknown bike.
case unknownName(_ name: String)
}

Expand Down
Loading

0 comments on commit d7a0a10

Please sign in to comment.