Meshtastic-Apple/Meshtastic/Helpers/BluetoothManager.swift

28 lines
596 B
Swift
Raw Normal View History

2021-12-10 17:44:28 -08:00
//
// BluetoothManager.swift
// MeshtasticClient
//
// Created by Garth Vander Houwen on 12/1/21.
//
import Combine
import CoreBluetooth
final class BluetoothManager: NSObject {
2021-12-25 23:48:12 -08:00
2021-12-10 17:44:28 -08:00
private var centralManager: CBCentralManager!
2021-12-25 23:48:12 -08:00
2021-12-10 17:44:28 -08:00
var stateSubject: PassthroughSubject<CBManagerState, Never> = .init()
var peripheralSubject: PassthroughSubject<CBPeripheral, Never> = .init()
2021-12-25 23:48:12 -08:00
2021-12-10 17:44:28 -08:00
func start() {
centralManager = .init(delegate: self, queue: .main)
}
2021-12-25 23:48:12 -08:00
2021-12-10 17:44:28 -08:00
func connect(_ peripheral: CBPeripheral) {
centralManager.stopScan()
peripheral.delegate = self
centralManager.connect(peripheral)
}
}