Tuesday, June 16, 2015

Digital Dash Documentation, Part 3: Tracking Connections

All three of the Bluetooth connections used by the system are actively monitored.  The audio link serves to start or stop the system (as described in the previous part of the documentation), but the network and OBD connections are watched simply to provide a status indicator.

The bottom center of the main screen contains the three connection icons, just above the audio controls:


The audio link is considered always active, but the icons for the other two connections may appear or disappear as controlled by the following profiles.

Profile: V3_ConnectToNetwork (297)
State: Variable Value [ %V3_DrivingMode Set ]
State: Not BT Connected [ Name:SCH-R970 Address:* ]
Enter: V3_ConnectToNetwork (298)

When the %V3_DrivingMode variable becomes SET by the V3_Startup task, as described earlier, this profile is fully enabled and is one of the first to activate.  It sees that there is no Bluetooth connection to my phone and attempts to remedy that by running its entry task.  The profile may also activate if the the network connection is lost at any time.

A1: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_Network Set:False Animation Time (MS):0 ]
A2: Secure Settings [ Configuration:SCH-R970 (9C:3A:AF:66:AB:DE) - Connect Package:com.intangibleobject.securesettings.plugin Name:Secure Settings Timeout (Seconds):0 Continue Task After Error:On ]
A3: Profile Status [ Name:V3_ConnectToNetwork Set:Off ]
A4: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ]
A5: Profile Status [ Name:V3_ConnectToNetwork Set:On ]

The above task sets the network connection icon visibility to false to indicate a lack of connectivity.  It then attempts to make a connection to the phone.  In order to keep the profile from firing constantly during this process, the profile itself is turned off for five seconds to give the system time to make a connection.  After that it is reactivated.  This means that the system will continue trying to make a connection every five seconds if its previous attempt was unsuccessful.  Currently, there is no limit on the number of tries (mainly because I haven't had a problem with this arrangement) but that could certainly be added.

Profile: V3_Network Connected (299)
State: BT Connected [ Name:SCH-R970 Address:* ]
State: Variable Value [ %V3_DrivingMode Set ]
Enter: V3_NetworkConnected (300)

A1: Wait [ MS:0 Seconds:3 Minutes:0 Hours:0 Days:0 ]
A2: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_Network Set:True Animation Time (MS):0 ]

The above profile and task just notice that there is now a valid network connection and make the onscreen icon visible.  The three second delay, along with the five second delay in the connection routine, will make the icon blink slowly if the tablet is having trouble making the connection to the phone.

Because I use the system in two vehicles and want it to know which one it's connected to, I have two nearly identical profiles that listen for a connection to an OBD transmitter.  The profiles use the addresses of the adapters rather than the names since they are both called "OBDII" in the Bluetooth Devices list and renaming doesn't work due to an Android bug.  If I didn't care which one was connected, I could use a single profile with the name as the identifier and it would activate regardless of which one connected.

Profile: V3_Z3OBDTracker (372)
State: BT Connected [ Name:* Address:00:02:5B:00:A5:90 ]
State: Variable Value [ %V3_DrivingMode Set ]
Enter: V3_BMW_OBDConnected (373)

This profile listens for the Z3 OBD adapter.

A1: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_OBD Set:True Animation Time (MS):0 ]
A2: Variable Set [ Name:%V3_CarLogo To:beam/BMW_logo.png Do Maths:Off Append:Off ]

The entry task just turns on the OBD onscreen indicator and sets the %V3_CarLogo variable to point to the BMW logo I have stored on the tablet.  The V3_RH scene has an image element tied to this variable, so when this task runs the system's main screen is branded with the BMW logo. 

Exit: V3_OBDDisconnected (374)
A1: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_OBD Set:False Animation Time (MS):0 ]

All the exit task does is turn off the OBD icon; the branding logo continues to be shown.

Profile: V3_JagOBDTracker (375)
State: BT Connected [ Name:* Address:00:0D:18:3A:67:89 ]
State: Variable Value [ %V3_DrivingMode Set ]
Enter: V3_Jag_OBDConnected (302)

This profile listens for the Jag OBD adapter.

A1: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_OBD Set:True Animation Time (MS):0 ]
A2: Variable Set [ Name:%V3_CarLogo To:beam/Jag.png Do Maths:Off Append:Off ]

The only difference in this entry task is the path to the logo; this one points to the snarling cat Jag logo.

Exit: V3_OBDDisconnected (374)
A1: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_OBD Set:False Animation Time (MS):0 ]

Both profiles share the same exit task.

No comments: