This is the first part of the digital dash documentation that actually presents some code. I'll be going through it in a fair amount of detail, but not generally line-by-line.
All of the project's profiles, except one, have two contexts; one of which is always %V3_DrivingMode is SET. That keeps any of the profiles from firing unless I'm actually running the system. For example, I may want to start Torque to change a layout or edit a vehicle profile and I don't need or want the overlays coming on at those times.
But, of course, there has to be an exception. The profile presented below (V3_AudioLinkActive) has only one context, so it can fire at any time. All it does is listen for a connection to be made to the Miccus Bluetooth audio receiver. When it sees that, the profile becomes active and runs its entry task (V3_Startup). When the connection is lost (i.e. I shut down the receiver) the exit task (V3_Shutdown) is run. It is, therefore, the starting and ending point for the project.
Here's the profile:
Profile: V3_AudioLinkActive (370)
Restore: no
State: BT Connected [ Name:Miccus Mini-Jack Rx Address:* ]
Enter: V3_Startup (343)
And here's the entry task and it's breakdown, with explanations following the line(s) they are referring to:
A1: Keyguard [ Configuration:Keyguard dismiss Package:com.balda.keyguard Name:Keyguard Timeout (Seconds):0 ]
The first line simply uses the Keyguard plugin to turn on the tablet.
A2: Variable Set [ Name:%V3_OnMain To:True Do Maths:Off Append:Off ]
Now the %V3_OnMain variable is set. This variable is used to tell when the main screen is displayed. Since the system starts up on that screen, this needs to be set. (Actually, it isn't really used at this point; I put it in because I'm going to need it for a planned future enhancement.)
A3: Create Scene [ Name:V3_TopMain Continue Task After Error:On ]
A4: Create Scene [ Name:V3_TopSources Continue Task After Error:On ]
A5: Create Scene [ Name:V3_TopEQ Continue Task After Error:On ]
A6: Create Scene [ Name:V3_LH Continue Task After Error:On ]
A7: Element Visibility [ Scene Name:V3_LH Element Match:LowFuel Set:False Animation Time (MS):0 ]
A8: Create Scene [ Name:V3_Bottom Continue Task After Error:On ]
A9: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_OBD Set:False Animation Time (MS):0 ]
A10: Element Visibility [ Scene Name:V3_Bottom Element Match:V3_Network Set:False Animation Time (MS):0 ]
A11: Create Scene [ Name:V3_RH Continue Task After Error:On ]
A12: Create Scene [ Name:V3_FavoriteSongs Continue Task After Error:On ]
A13: Create Scene [ Name:V3_Destinations Continue Task After Error:On ]
A14: Create Scene [ Name:V3_Menu_Button Continue Task After Error:On ]
A15: Create Scene [ Name:V3_MapSpeedometer Continue Task After Error:On ]
Lines 3-15 create an instance of (almost) all the scenes used in the system. I do that here because many of them have elements that may need to be changed before they are displayed. For example, lines 7, 9, and 10 hide some scene elements whose visibility is controlled by other profiles and tasks.
A16: Variable Set [ Name:%V3_FavoriteSongs To:Song Search Data1,Song Search Data2,Song Search Data3,Song Search Data4,Song Search Data5,Song Search Data6,Song Search Data7,Song Search Data8,Song Search Data9,Song Search Data10 Do Maths:Off Append:Off ]
A17: Variable Split [ Name:%V3_FavoriteSongs Splitter:, Delete Base:Off ]
These two lines set up the Favorite Songs list. In line 16, you would replace every occurrence of "Song Search DataX" with enough information that PowerAmp could locate an individual song from that entry. For example, you might put "Lucy" (with no quotes) as one entry if you wanted to find and play "Lucy in the Sky with Diamonds". That would work as long as you have no other songs with the word "Lucy" in the title and had no artists with that name. Line 17 turns the %V3_FavoriteSongs variable into an array that can later be entered with an index provided by the Favorite Songs menu.
A18: Variable Set [ Name:%V3_Compass To:N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW Do Maths:Off Append:Off ]
A19: Variable Split [ Name:%V3_Compass Splitter:, Delete Base:Off ]
Lines 18 and 19 set up a variable array which is indexed from an AutoLocation profile/task to provide an on-screen compass.
A20: Variable Set [ Name:%V3_Destinations To:Address1, Address2, Address3, Address4, Address5 Do Maths:Off Append:Off ]
A21: Variable Split [ Name:%V3_Destinations Splitter:, Delete Base:Off ]
Lines 20 and 21 set up another array. This one is used by the Destinations menu. Again, you would replace each instance of "AddressX" with the full address that you would like to navigate to when you choose an entry from the menu.
A22: Variable Set [ Name:%V3_DrivingMode To:True Do Maths:Off Append:Off ]
%V3_DrivingMode is SET so that any other profiles in the system can now fire as needed.
A23: Variable Set [ Name:%V3_BatteryDisplay To:%BATT% Do Maths:Off Append:Off ]
Tasker's built-in %BATT Variable is converted to one that can be displayed on the screen. The only real function of this line is to add the % after the value.
A24: AutoLocation Location [ Configuration:Starting Location Monitor
Location Report Name: V3_Compass
Interval: 1 seconds
Update Type: High Accuracy Package:com.joaomgcd.autolocation Name:AutoLocation Location Timeout (Seconds):60 Continue Task After Error:On ]
Line 24 starts the AutoLocation plugin running with a defined name (V3_Compass). From this point on, it will track GPS data. A profile will monitor for changes in that information and use it to display bearing and speed. (As will be explained in a later documentation entry.)
A25: WiFi [ Set:Off ]
A26: Media Volume [ Level:15 Display:Off Sound:Off ]
A27: Display Timeout [ Secs:0 Mins:0 Hours:8 ]
A28: Auto Brightness [ Set:Off ]
A29: Display Brightness [ Level:255 Disable Safeguard:Off Ignore Current Level:Off Immediate Effect:Off ]
The previous five lines simply configure some tablet parameters to the way I want them.
A30: Element Visibility [ Scene Name:V3_RH Element Match:V3_BrightnessAuto Set:False Animation Time (MS):0 ]
Since the system contains an onscreen brightness control that reflects the tablet's brightness state, I need to hide an element so that the display matches. (In retrospect, I could have probably done this above when I was manipulating other elements. Oh, well.)
A31: Launch App [ App:Torque Data: Exclude From Recent Apps:Off Continue Task After Error:On ]
Here we finally get around to starting Torque. At this point the system is mostly (but not entirely) up and running and it's time to see the interface. Because we set the %V3_DrivingMode variable up above, the profile that controls the overlays is able to fire now. Some things, like the network connection, OBD connection, and temperature will not be ready yet, but they are beginning to come online. Torque also begins writing data to its log file as soon as the OBD connection is made.
A32: Perform Task [ Name:V3_TimeAndTorque Priority:2 Parameter 1 (%par1): Parameter 2 (%par2): Return Value Variable: Stop:Off ]
The last step of the Startup procedure is to begin executing a low-priority, looping task. This task repeats about every 30 seconds and is used to update the clock display and bring in the "Estimated Distance to Empty" value from Torque.
Within a few seconds, all the connections should be made and all the initial data displayed. We are now at the the normal steady-state for the system.
When the connection to the Miccus is terminated, the V3_AudioLinkActive profile becomes inactive and runs its exit task, below.
Exit: V3_Shutdown (344)
A1: Variable Clear [ Name:%V3_DrivingMode Pattern Matching:Off ]
The first thing we do is clear the %V3_DrivingMode variable so that none of the system profiles can fire again.
A2: Go Home [ Page:0 ]
Now we display the tablet's home screen.
A3: Destroy Scene [ Name:V3_TopMain Continue Task After Error:On ]
A4: Destroy Scene [ Name:V3_TopSources Continue Task After Error:On ]
A5: Destroy Scene [ Name:V3_TopEQ Continue Task After Error:On ]
A6: Destroy Scene [ Name:V3_LH Continue Task After Error:On ]
A7: Destroy Scene [ Name:V3_Bottom Continue Task After Error:On ]
A8: Destroy Scene [ Name:V3_RH Continue Task After Error:On ]
A9: Destroy Scene [ Name:V3_FavoriteSongs Continue Task After Error:On ]
A10: Destroy Scene [ Name:V3_Destinations Continue Task After Error:On ]
A11: Destroy Scene [ Name:V3_CancelOverlays Continue Task After Error:On ]
A12: Destroy Scene [ Name:V3_Menu_Button Continue Task After Error:On ]
A13: Destroy Scene [ Name:V3_MapSpeedometer Continue Task After Error:On ]
Lines 3-13 destroy all the previously created scenes.
A14: Display Timeout [ Secs:7 Mins:0 Hours:0 ]
Line 14 sets the display timeout so that the system will turn itself off when it completes the exit task.
A15: Auto Brightness [ Set:On ]
AutoBrightness is returned to its default value.
A16: AutoLocation Location [ Configuration:Stopping Location Monitor
Location Report Name: V3_Compass
Update Type: No Power Package:com.joaomgcd.autolocation Name:AutoLocation Location Timeout (Seconds):60 Continue Task After Error:On ]
Location tracking is stopped.
A17: Stop [ With Error:Off Task:V3_TimeAndTorque ]
The task that updates the time and "Distance to Empty" check is stopped.
A18: Send Intent [ Action:org.prowl.torque.REQUEST_TORQUE_QUIT Cat:None Mime Type: Data: Extra: Extra: Package: Class: Target:Broadcast Receiver Continue Task After Error:On ]
Torque is shut down and stops logging its data.
A19: Secure Settings [ Configuration:SCH-R970 (9C:3A:AF:66:AB:DE) - Disconnect Package:com.intangibleobject.securesettings.plugin Name:Secure Settings Timeout (Seconds):0 Continue Task After Error:On ]
The Bluetooth connection to the phone is terminated. This will cause the phone to run its own shutdown sequence and turn everything off.
A20: WiFi [ Set:On ]
Since we don't have network through the phone any more, we need to be ready to connect via WiFi.
A21: Run Shell [ Command:/data/data/burrows.apps.busybox/app_busybox/tail -1 /storage/emulated/0/torqueLogs/trackLog.csv Timeout (Seconds):0 Use Root:Off Store Output In:%obd_log Store Errors In: Store Result In: Continue Task After Error:On ]
A22: Delete File [ File:torqueLogs/trackLog.csv Shred Level:0 Use Root:Off Continue Task After Error:On ]
A23: Wait [ MS:0 Seconds:3 Minutes:0 Hours:0 Days:0 ]
A24: Write File [ File:torqueLogs/trackLog.csv Text:%obd_log Append:Off Add Newline:On Continue Task After Error:On ]
The previous four lines handle Torque's log data between runs of the system. Since I have Torque set up to use the same log file each time, I want to delete it so it doesn't get too large. However, if I just do that, the next time the Digital Dash starts up, it will see a null entry for the Distance to Empty value and think that I'm out of gas. It announces that with a verbal and visual display, which can be a bit startling and I'd rather not have that come on. So, I read the last line of the log, delete the file, and then write a new one with same name that contains only the line I just read. That way, the systems starts up right where it left off with the same data.
A25: Wait [ MS:0 Seconds:10 Minutes:% Hours:0 Days:0 ]
A26: Display Timeout [ Secs:0 Mins:2 Hours:0 ]
All of these tasks take some time, and some of them (like turning on WiFi) can cause screen activity. The Wait command just gives those things some time to complete. And at the end of 10 seconds, the tablet begins to power down. As a last step, we then set the display timeout back to two minutes.
At this point the system is shut down and everything is back to normal.