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?
32
42
@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
@@ -86,7 +96,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate {
// compare peripheral hashes to make sure we're only adding each device once -- super helpful if you have a very noisy BLE advertiser nearby!
111
+
// this hash value is functional only for separating devices during this search, and is not at all guaranteed to be a persistent value. Probably not to be trusted for long-term autoconnect persistence. So far, I have gotten the same value for my PineTime every time I run the app, but based on the Apple docs this is not a guarantee.
101
112
if !peripherals.contains(where:{$0.peripheralHash == newPeripheral.peripheralHash}){
102
113
// I think there's probably a way to get rid of this array someday, but for now it's useful for displaying the device names. You cant have a Peripheral struct as a key in the peripheralDictionary, so there has to be some way to pass the names to the UI, and the peripherals array seems like it.
TODO: hey alpha testers! Please send me a message/comment/email/toot/whatever with the peripheralHash of your PineTime! While the hash is valuable for weeding out repeat broadcasters, I'm not sure what exactly is hashed, and if that would be unique between two of the same device. If it's just a hash of "InfiniTime" + $INFINITIMEUUID, then there will be unintended collisions and this won't solve anything for people that have more than one InfiniTime watch to sync.
109
-
110
-
I'm getting the same value each time I run the app (138271609), let's hope yours is different!
// 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.
177
+
// I'm sure there's a less clunky way to grab the full characteristic for the sendNotification() function, but this works fine for now
// 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
// when CoreBluetooth gets an update from the music control characteristic, parse that number and take an action, and in any case, make sure the track and artist are relatively up to date
16
+
switch controlNumber {
17
+
case0:
18
+
if musicController.getPlaybackStatus()==1{
19
+
musicController.pause()
20
+
}else{
21
+
musicController.play()
22
+
}
23
+
case2:
24
+
print("volUp") // system volume controls are not accessible from an app
25
+
case3:
26
+
musicController.nextTrack()
27
+
case4:
28
+
musicController.prevTrack()
29
+
case5:
30
+
print("volDown") // system volume controls are not accessible from an app
For now, this is a rudimentary implementation of apple's MediaPlayer framework, which unfortunately only works with Apple Music. Apple does not allow control of system volume levels at from the app level, so the volume controls do not work currently. Control of the "Now Playing" media on the device is also not supported at the app level, so we have to specifically work with Apple Music through the existing framework.
14
+
15
+
In the future, if Apple's proprietary AMS (Apple Media Service) is implemented in InfiniTime, these controls should work on their own, and the track/artist/elapsed time/total time should automatically populate. Not sure how much work that would be to implement, so this may be the best we can do for a while.
16
+
17
+
TODO: figure out the formatting that PineTime expects for time elapsed/total time. Hex value of 0101 = 12:32, 0102 = 04:48. Writing decimal does nothing. ASCII also gives wacky results
// 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
Copy file name to clipboardExpand all lines: README.md
+12-18Lines changed: 12 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,41 +3,35 @@
3
3
This is a proof-of-concept, barely-functional iOS application to interact with your PineTime running (at least) InfiniTime 1.3.0 (and maybe more, I haven't tested it against other watches or OSes).
4
4
5
5
### What works:
6
-
- Scan nearby devices and allow the user to select a device to connect to
7
-
- so far this is card coded to be a device named 'InfiniTime' because I don't have anything else to test it against and I don't want to fat-finger the wrong device and have it break
6
+
- Scan nearby devices and allow the user to select an InfiniTime device to connect to
8
7
- Connect to a PineTime running InfiniTime 1.3.0
9
8
- Set time and date immediately after connection
10
9
- Read heart rate, and subscribe to HRM's notifier for updated values
11
10
- Read battery level, and subscribe to battery level's notifier for updated values
12
11
- Display heart rate, battery level, and connection/bluetooth/scanning status to app main page
12
+
- Music controls on InfiniTime can control Apple Music. I can't access system-level music controls or system volume from within an app, so the controls literally only work on Apple Music.
13
13
14
14
### What sort of works but mostly just sucks:
15
15
- The UI: It's just a proof of concept so far, so I put as little effort as possible into the UI.
16
-
- Notifications: I can send a test notification to the PineTime, but can't send phone notifications to the watch yet.
17
-
- Music controls: I have subscribed to the InfiniTime music app notifier, but so far have only implemented printing music control button presses to console. They do print though, so it should be doable if I can access the phone's music controls somehow!
16
+
- Notifications: I can send a test notification to the PineTime, but can't send phone notifications to the watch yet. Apple requires the ANCS protocol and bonding to be implemented on the peripheral device, so there's some big hills to climb before notifications are functional.
18
17
19
18
### What's next:
20
-
- Figure out how to send phone notifications to watch
21
-
- Figure out how to control music from watch
22
-
- Optional auto-connect: save some device-specific characteristic (MAC address? Serial number?) to the app, and allow users to automatically connect to their device. I know I probably won't want to connect to anything other than my own pinetime with very few exceptions, so it'd save me a few taps if it just snagged my watch automatically when I open the app.
23
-
- Learn anything whatsoever about making an app design in SwiftUI that isn't a horrific clusterwhoops
24
-
- Send notifications to the phone, probably. Might be nice to get a buzz on your phone if the watch disconnects for some reason
25
-
- User-configurable settings:
26
-
- select device for autoconnect
27
-
- enable/disable notifications
28
-
- taking suggestions
29
-
- Clean everything up. Still tons of commented lines and code blocks from debugging and trial and error stuff that I should really remove. Probably should add a few more explanatory comments here and there too, mostly for my own benefit...
30
-
- I mean, there's the navigation thing? I guess poke at that. I'm not super sure that's a priority for me at all, but if that's something that people want I can definitely look into it sooner.
19
+
- Learn anything whatsoever about making an app design in SwiftUI that isn't an awful mess
20
+
- Send notifications to the phone, probably. Might be nice to get a buzz on your phone if the watch disconnects for some reason or if the watch battery is running low
21
+
- User-configurable settings, like enabling or disabling Apple Music controls, notifications, etc
22
+
- Clean everything up. Being my first major foray into larger-scale coding projects, I have not done a great job of compartmentalizing my code, so the BLEManager.swift file is pretty monolithic.
23
+
- Watch navigation app. This is a lower priority to me personally, but I'll definitely give it a shot eventually. Based on how the music control and notifications have gone, I'm guessing there's another proprietary Apple service that will need to be implemented to make this work.
31
24
32
-
### How to try it out
25
+
### How to try it out:
33
26
- Snag this repo and open it in XCode on a Mac
34
27
- Plug an iPhone into your computer and select it as the build target in XCode
35
28
- Make sure you're signed into your appleID in XCode and that you've done whatever it wants you to do to flag yourself as a code signer
36
29
- Change the code signing information in the Infini-iOS properties:
37
30
- Click the main project in the files sidebar
38
31
- Navigate to the 'Signing and Capabilities' tab
39
32
- Change the 'Team' pulldown to reflect your appleID that you used to sign into XCode
33
+
- Change the Bundle Identifier to match your team
40
34
- Build and run!
41
35
42
-
### Disclaimers
43
-
**This is the first time I've worked with Swift, SwiftUI, XCode, BLE, or anything else in this application. I take no responsibility for what happens if you interact with this repository in any way. If it breaks your phone or your watch or your brain,*****that's on you buddy!***
36
+
### Disclaimer
37
+
**This is the first time I've worked with Swift, SwiftUI, XCode, BLE, or anything else in this application. I take no responsibility for what happens if you interact with this repository in any way. If it breaks your phone, your watch, or your brain,*****that's on you buddy!***
0 commit comments