-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from DrAma999/develop
Develop
- Loading branch information
Showing
19 changed files
with
723 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 0 additions & 16 deletions
16
LittleBlueTooth.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// | ||
// Helper.swift | ||
// LittleBlueTooth | ||
// | ||
// Created by Andrea Finollo on 09/08/2020. | ||
// | ||
|
||
import Foundation | ||
import Combine | ||
import os.log | ||
#if TEST | ||
import CoreBluetoothMock | ||
#else | ||
import CoreBluetooth | ||
#endif | ||
|
||
extension AnyCancellable { | ||
func store(in dictionary: inout [UUID : AnyCancellable], | ||
for key: UUID) { | ||
dictionary[key] = self | ||
} | ||
} | ||
extension Publisher { | ||
|
||
func flatMapLatest<T: Publisher>(_ transform: @escaping (Self.Output) -> T) -> AnyPublisher<T.Output, T.Failure> where T.Failure == Self.Failure { | ||
return map(transform).switchToLatest().eraseToAnyPublisher() | ||
} | ||
} | ||
|
||
extension TimeInterval { | ||
var dispatchInterval: DispatchTimeInterval { | ||
let microseconds = Int64(self * TimeInterval(USEC_PER_SEC)) // perhaps use nanoseconds, though would more often be > Int.max | ||
return microseconds < Int.max ? DispatchTimeInterval.microseconds(Int(microseconds)) : DispatchTimeInterval.seconds(Int(self)) | ||
} | ||
} | ||
|
||
extension OSLog { | ||
public static var Subsystem = "it.vanillagorilla.LittleBlueTooth" | ||
public static var General = "General" | ||
public static var CentralManager = "CentralManager" | ||
public static var Peripheral = "Peripheral" | ||
public static var Restore = "Restore" | ||
|
||
public static let LittleBT_Log_General = OSLog(subsystem: Subsystem, category: General) | ||
public static let LittleBT_Log_CentralManager = OSLog(subsystem: Subsystem, category: CentralManager) | ||
public static let LittleBT_Log_Peripheral = OSLog(subsystem: Subsystem, category: Peripheral) | ||
public static let LittleBT_Log_Restore = OSLog(subsystem: Subsystem, category: Restore) | ||
|
||
} | ||
#if TEST | ||
extension CBMPeripheral { | ||
public var description: String { | ||
return "Test peripheral" | ||
} | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// Loggable.swift | ||
// LittleBlueTooth | ||
// | ||
// Created by Andrea Finollo on 07/08/2020. | ||
// | ||
|
||
import Foundation | ||
import os.log | ||
|
||
protocol Loggable { | ||
var isLogEnabled: Bool {get set} | ||
func log(_ message: StaticString, log: OSLog, type: OSLogType, arg: CVarArg...) | ||
} | ||
|
||
|
||
extension Loggable { | ||
func log(_ message: StaticString, log: OSLog, type: OSLogType, arg: CVarArg...) { | ||
#if !TEST | ||
guard isLogEnabled else { | ||
return | ||
} | ||
os_log(type, log: log, message, arg) | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.