You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@PublishedvarisSwitchedOn=false // for now this is used to display if bluetooth is on in the main app screen. maybe an alert in the future?
31
+
@PublishedvarisScanning=false // another UI flag. Probably not necessary for anything but debugging. I dunno maybe a little swirly animation or something could be triggered by this
32
+
@PublishedvarisConnectedToPinetime=false // another flag published to update UI stuff. Can probably be implemented better in the future
33
+
@PublishedvarheartBPM:String! // published var to communicate the HRM data to the UI. I don't know enough about Swift to know if this is a bad idea.
34
+
@PublishedvarbatteryLevel:String! // Same as heartBPM but for battery data
35
+
36
+
// Selecting and connecting variables
37
+
@Publishedvarperipherals=[Peripheral]() // used to print human-readable device names to UI in selection process
38
+
@PublishedvardeviceToConnect:Int! // When the user selects a device from the UI, that peripheral's ID goes in this var, which is passed to the peripheralDictionary
39
+
@PublishedvarperipheralDictionary:[Int:CBPeripheral]=[:] // this is the dictionary that relates human-readable peripheral names to the CBPeripheral class that CoreBluetooth actually interacts with
40
+
@PublishedvarinfiniTime:CBPeripheral! // variable to save the CBPeripheral that you're connecting to
38
41
39
42
overrideinit(){
40
43
super.init()
@@ -66,7 +69,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
66
69
}
67
70
68
71
func connect(peripheral:CBPeripheral){
69
-
// working on adding user choice, but still blocking anything but InfiniTime until I can set up a proper way to test it, because it might crash everything?
72
+
// Still blocking connections to anything not named "InfiniTime" until I can set up a proper way to test other devices
70
73
71
74
if peripheral.name =="InfiniTime"{
72
75
self.myCentral.stopScan()
@@ -81,8 +84,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
// scan BLE devices, looking for any named InfiniTime, and then automatically connect to InfiniTime
85
-
// I know this sucks for anyone who has more than one watch, a dev/sealed pair, waspOS, etc. I'll open this up when I've got the core functionality for InfiniTime locked in
86
87
87
88
varperipheralName:String! // ** not necessary without below scan list thing
88
89
@@ -97,55 +98,21 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
97
98
print(newPeripheral)
98
99
99
100
// ************************* remove if statement from code! but holy fuck this TV is the noisiest BLE advertiser in the world what the actual fuck *****************************
101
+
/*
102
+
P.S. I'd love to figure out how to filter by a unique ID other than the name, but all I can seem to find online is that MAC address and other hardware flag things I think would be helpful to filter by are not advertised over BLE, so I don't know what to do about it.
103
+
A unique identifier would be super helpful for flagging your pinetime in the app so you can have the app automatically connect and skip the process of scanning and selecting a pinetime.
104
+
For now I'm going to selfishly block my TV, and anyone else who touches this can either modify the if statement below to suit their TV or remove it.
105
+
*/
100
106
101
107
if newPeripheral.name !="[TV] Samsung 8 Series (50)"{
scan for all nearby BLE devices -- this was part of one of the tuts I was following. For now I'm just going to keep the app tightly coupled to PineTimes running Infinitime to reduce complexity for initial development. This code will be useful if it turns out this app is functional with other similar watches/waspOS/etc.
129
-
********
130
-
131
-
var peripheralName: String! ** not necessary without below scan list thing
132
-
133
-
if let name = advertisementData[CBAdvertisementDataLocalNameKey] as? String {
134
-
peripheralName = name
135
-
}
136
-
else {
137
-
peripheralName = "Unknown"
138
-
}
139
-
140
-
let newPeripheral = Peripheral(id: peripherals.count, name: peripheralName, rssi: RSSI.intValue)
// I'm sure there's a less clunky way to grab the full characteristic for the sendNotification() function, but this ad-hoc method works okay and allows it to be published as well.
letpaddedNotification=""+ notification // I'm pretty sure this is due to a lack of understanding on my part of the notification protocol, but sending ascii text as a notification eats the first 3 characters, so add 3 spaces here to absorb that
191
+
// I'm pretty sure this is due to a lack of understanding on my part of the notification protocol, but sending ascii text as a notification eats the first 3 characters seemingly no matter what they are, so add 3 spaces here to absorb that, then encode the string to ASCII Data
// function to translate heart rate to decimal, copied straight up from this tut: https://www.raywenderlich.com/231-core-bluetooth-tutorial-for-ios-heart-rate-monitor#toc-anchor-014
0 commit comments