Wednesday, January 22, 2014

Pebble Toggle

I recently acquired a Pebble Smart Watch for using with my Nexus 4. I wanted an easy system to connect to Pebble. So I created a task to be used as Toggle in PowerToggles. The steps are given below.

TASK: Pebble Toggle
A1: If [ %BLUE ~ Off ] - Checks if Bluetooth is Off. If it is Off, then executes following actions
A2: Variable Set [ Name:%PTPBLEON To:1] - Stands for PowerTogglePebbleOn: When Pebble is connected using Power Toggles
A3: Bluetooth [ Set:On ] - Enables Bluetooth
A4: Wait [Seconds:1] - Wait for One Second
A5: Load App [ App:Pebble Data] - Loads Pebble App
A6: Flash [ Text:Enabling BT and Launching Pebble] - Flashes a Message (This is not required as this action is inserted merely to provide info)
A7: Wait [ MS:0 Seconds:1 Minutes:0 Hours:0 Days:0 ] - Wait for a Seond
A8: Button [ Button:Back ] If [ %PBLE ~ 1 ] - %PBLE is a variable set by an event context. The context checks if pebble is connected and if so, sets to 1. If Pebble is connected, Back Button is simulated. This is done to return to home screen
A9: Modify PowerToggle state [ Configuration:Set current toggle to on Package:com.painless.pc Name:Modify PowerToggle state Timeout (Seconds):0 ] - Modify the state of Power Toggles Toggle to ON
A10: Else If [ %BLUE ~ On ] - If Bluetooth is Off, checks if Bluetooth is On. If so, executes following actions
A11: Bluetooth [ Set:Off ] - Disables Bluetooth
A12: Kill App [ App:Pebble Use Root:Off ] - Kill Pebble App
A13: Flash [ Text:Disabling BT and Killing Pebble App] - Flashes a Message (This is not required as this action is inserted merely to provide info)
A14: Modify PowerToggle state [ Configuration:Set current toggle to off Package:com.painless.pc Name:Modify PowerToggle state Timeout (Seconds):0 ] - Modify the state of Power Toggles Toggle to OFF
A15: Variable Set [ Name:%PTPBLEON To:0] - Stands for PowerTogglePebbleOn: When Pebble is Disconnected using Power Toggles. 
A16: End If 

The following Tasks are executed when Pebble is connected via Bluetooth. A Profile is Created to Check if Pebble is connected (State: Bluetooth Connected, Name:Pebble) and if so, Task Pebble Connected is executed and if not so, Task Pebble Disconnected is executed.

TASK: Pebble Connected
A1: Modify PowerToggle state [ Configuration:Set Pebble Toggle to on Package:com.painless.pc Name:Modify PowerToggle state Timeout (Seconds):0 ] - Modify the state of Power Toggles Toggle to ON
A2: Variable Set [ Name:%PBLE To:1 Do Maths:Off Append:Off ] - Set the PBLE Variable to 1. Used to check if Pebble is connected in Task Pebble Toggle

TASK: Pebble Disconnected (When Pebble is Disconnected automatically - e.g. loss of Bluetooth Signal)
A1: If [ %PTPBLEON ~ 1 ] - Executes following actions if Pebble was connected using Power Toggles Toggle
A2: Wait [ MS:0 Seconds:5 Minutes:0 Hours:0 Days:0 ] - Wait for 5 Seconds. To check if Pebble is connected.
A3: Bluetooth [ Set:Off ] - Disables Bluetooth to save power
A4: Flash [ Text:Pebble has been disconnected. Switching off Bluetooth Long:Off ] - Flashes a message 
A5: Modify PowerToggle state [ Configuration:Set Pebble Toggle to off Package:com.painless.pc Name:Modify PowerToggle state Timeout (Seconds):0 ] - Modify the state of Power Toggles Toggle to OFF
A6: Variable Set [ Name:%PBLE To:0] - Set variable PBLE to 0 to indicate that Pebble has been disconnected
A7: End If