示例#1
0
        private async void Restore(object obj)
        {
            try
            {
                BackupBusy   = true;
                BackupStatus = "Retrieving backup from OneDrive";

                PebbleConnector _pc = PebbleConnector.GetInstance();

                bool Result = await _pc.WatchItems.Restore();

                if (Result)
                {
                    BackupStatus = "Restoring watch items";

                    Result = await _pc.WatchItems.Load();
                }

                if (Result)
                {
                    BackupStatus = "Restore success";
                }
                else
                {
                    BackupStatus = "Restore failed";
                }
            }
            catch (Exception exp)
            {
                BackupStatus = "Restore failed";
            }

            BackupBusy = false;
        }
示例#2
0
        private async void Backup(object obj)
        {
            try
            {
                PebbleConnector _pc = PebbleConnector.GetInstance();

                BackupBusy   = true;
                BackupStatus = "Backing up watch items";

                bool Result = await _pc.WatchItems.Backup();

                if (Result)
                {
                    LastBackup   = DateTime.Now;
                    BackupStatus = "Backup success";
                }
                else
                {
                    BackupStatus = "Backup failed";
                }
            }
            catch (Exception exp)
            {
                BackupStatus = "Backup failed";
            }

            BackupBusy = false;
        }
        /// <summary>
        /// Start the activity
        /// </summary>
        /// <param name="obj"></param>
        private async void StartActivity(object obj)
        {
            if (!Purchased)
            {
                return;
            }

            var localSettings = ApplicationData.Current.LocalSettings;

            localSettings.Values[Constants.BackgroundPace] = true;

            _NotRunning = 0;

            _Timer.Start();

            try
            {
                PebbleConnector _pc = PebbleConnector.GetInstance();
                await _pc.StartBackgroundTask(PebbleConnector.Initiator.Pace);
            }
            catch (Exception exc)
            {
                ExtendedEventArgs _e = new ExtendedEventArgs();
                _e.Error = exc.Message;
                OnFatalError(_e);
            }
        }
        public WipeHandler(ObservableCollection <String> Log, TimeLineSynchronizer TimeLineSynchronizer)
        {
            _pc = PebbleConnector.GetInstance();

            _Log = Log;
            _TimeLineSynchronizer = TimeLineSynchronizer;
            _ConnectionToken      = -1;
        }
        /// <summary>
        /// Stop the activity
        /// </summary>
        /// <param name="obj"></param>
        private void StopActivity(object obj)
        {
            //var localSettings = ApplicationData.Current.LocalSettings;
            //localSettings.Values[Constants.BackgroundPace] = false;

            PebbleConnector _pc = PebbleConnector.GetInstance();

            _pc.StopBackgroundTask(PebbleConnector.Initiator.Pace);
        }
        private void SuspendCommandInvokedHandler(IUICommand command)
        {
            PebbleConnector _pc = PebbleConnector.GetInstance();

            if (command.Label == "Yes")
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                localSettings.Values[Constants.TennisCommand] = "suspend";
            }
        }
示例#7
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            PebbleConnector _pc = PebbleConnector.GetInstance();

            if (!await _pc.IsPebbleAssociated())
            {
                MessageDialog msgBox = new MessageDialog("No Pebble device has been associated with Pebble Time Manager. Do you want to search and associate a device now?" + System.Environment.NewLine + System.Environment.NewLine + "This will take a couple of seconds to complete.");
                msgBox.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(this.AssociateInvokedHandler)));
                msgBox.Commands.Add(new UICommand("No", new UICommandInvokedHandler(this.AssociateInvokedHandler)));

                await msgBox.ShowAsync();
            }
        }
示例#8
0
        private async void PebbleAssociate(IUICommand command)
        {
            Log.Add("Associating " + PebbleDeviceName.Name);

            try
            {
                PebbleConnector _pc = PebbleConnector.GetInstance();
                if (await _pc.AssociatePebble(PebbleDeviceName))
                {
                    Log.Add("Success");

                    var successDialog = new Windows.UI.Popups.MessageDialog(String.Format("Association {0} completed successfully.", PebbleDeviceName.Name));
                    successDialog.Commands.Add(new UICommand("Ok"));

                    await successDialog.ShowAsync();
                }
                else
                {
                    throw new Exception();
                }
            }
            catch (Exception exp)
            {
                if (exp.Message.Length > 0)
                {
                    Log.Add(String.Format("An error occurred while associating {0}: {1}", PebbleDeviceName, exp.Message));
                }
                else
                {
                    Log.Add("Failed");
                }

                var messageDialog = new Windows.UI.Popups.MessageDialog(String.Format("Association {0} failed.", PebbleDeviceName.Name));
                messageDialog.Commands.Add(new UICommand("Ok"));

                await messageDialog.ShowAsync();
            }
            finally
            {
                NotifyPropertyChanged("IsDeviceAssociated");
                NotifyPropertyChanged("AssociatedDeviceFirmware");
                NotifyPropertyChanged("AssociatedDeviceName");
                NotifyPropertyChanged("AssociatedDeviceBoard");
                NotifyPropertyChanged("AssociatedDeviceId");
            }
        }
        private void App_Activated(object sender, string e)
        {
            ConfigWebView.Visibility = Visibility.Collapsed;

            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
            localSettings.Values[Constants.PebbleWebViewClosed] = e;

            if (_WatchAppConfig != null)
            {
                //_WatchFaceConfig.WebViewClosed(e);
                localSettings.Values[Constants.PebbleWatchItem] = _WatchAppConfig.ID.ToString();
            }

            //Process the pebble webviewclosed in the background

            PebbleConnector _pc = PebbleConnector.GetInstance();
            _pc.StartBackgroundTask(PebbleConnector.Initiator.PebbleWebViewClosed);
        }
示例#10
0
        public async void Associate(object obj)
        {
            PebbleConnector _pc = PebbleConnector.GetInstance();
            {
                PebbleDeviceName = await _pc.GetCandidatePebble();

                if (PebbleDeviceName != null)
                {
                    String Message = String.Format("Device {0} found. Do you want to associate it?", PebbleDeviceName.Name);

                    var messageDialog = new Windows.UI.Popups.MessageDialog(Message);
                    messageDialog.Commands.Add(new UICommand("Yes", new UICommandInvokedHandler(this.PebbleAssociate)));
                    messageDialog.Commands.Add(new UICommand("No"));

                    await messageDialog.ShowAsync();
                }
            }
        }
        public async void Configure(object obj)
        {
            Configuring = true;

            var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;

            localSettings.Values[Constants.PebbleWatchItem]         = Item.ID.ToString();
            localSettings.Values[Constants.PebbleShowConfiguration] = "";

            PebbleConnector _pc = PebbleConnector.GetInstance();
            await _pc.StartBackgroundTask(PebbleConnector.Initiator.PebbleShowConfiguration);

            _timer          = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(250);
            _timer.Tick    += _timer_Tick;
            _timer.Start();

            _timerCycles = 0;
        }
        private async void Tennis_OnResume(object sender, EventArgs e)
        {
            PebbleConnector _pc = PebbleConnector.GetInstance();

            try
            {
                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                localSettings.Values[Constants.BackgroundTennis] = true;

                await _pc.StartBackgroundTask(PebbleConnector.Initiator.Tennis);
            }
            catch (Exception exc)
            {
                var messageDialog = new Windows.UI.Popups.MessageDialog(exc.Message, "Error");

                // Show the message dialog
                messageDialog.ShowAsync();
            }
        }
示例#13
0
        private async void Resync(object obj)
        {
            try
            {
                _vmBinder.Log.Clear();

                _vmBinder.Log.Add("Initiating resync...");

                WipeHandler = new WipeHandler(Log, TimeLineSynchronizer);
                await WipeHandler.Wipe();

                PebbleConnector _pc = PebbleConnector.GetInstance();
                IsConnected = _pc.IsConnected;
            }
            catch (Exception exp)
            {
                Log.Add("An exception occurred while resyncing.");
                Log.Add(exp.Message);
            }
        }
        private async void DeleteCommandInvokedHandler(IUICommand command)
        {
            PebbleConnector _pc = PebbleConnector.GetInstance();

            if (command.Label == "Yes")
            {
                await Tennis_Statistics.Helpers.LocalStorage.Delete("tennis_pebble.xml");

                await Tennis_Statistics.Helpers.LocalStorage.Delete("tennismatchstate.json");

                //Show new match page
                ShowPage(NewMatchGrid);

                _vmBinder.Tennis.vmMatch.IsExtendPossible = false;
                _vmBinder.Tennis.vmMatch.Paused           = false;
                _vmBinder.Tennis.vmMatch.InProgress       = false;
                _vmBinder.Tennis.vmMatch.Completed        = false;
                _vmBinder.Tennis.TryInUse = false;
                _vmBinder.Tennis.vmMatch.Notify();
            }
        }
        private async void ExtendCommandInvokedHandler(IUICommand command)
        {
            PebbleConnector _pc = PebbleConnector.GetInstance();

            if (command.Label == "Yes")
            {
                try
                {
                    await _pc.StartBackgroundTask(PebbleConnector.Initiator.Tennis);

                    var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                    localSettings.Values[Constants.BackgroundTennis] = true;
                    localSettings.Values[Constants.TennisCommand]    = "extend";
                }
                catch (Exception exc)
                {
                    var messageDialog = new Windows.UI.Popups.MessageDialog(exc.Message, "Error");

                    // Show the message dialog
                    messageDialog.ShowAsync();
                }
            }
        }
        private async void ReinitiateMatch()
        {
            _vmBinder.Tennis.vmMatch        = new vmMatchState();
            _vmBinder.Tennis.vmMatch.Paused = false;
            _vmBinder.Tennis.TryInUse       = true;

            //_vmBinder.vmMatch.Start(_vmBinder.vmNewMatch);
            ApplicationData.Current.LocalSettings.Values[Constants.TennisState] = "1";
            //ApplicationData.Current.LocalSettings.Values[Constants.BackgroundCommunicatieIsRunning] = false;
            PebbleConnector _pc = PebbleConnector.GetInstance();

            if (!await _pc.IsBackgroundTaskRunning())
            {
                //await _pc.StartBackgroundTask(PebbleConnector.Initiator.Tennis);
            }

            ShowPage(ProgressRing);

            _Timer          = new DispatcherTimer();
            _Timer.Interval = TimeSpan.FromSeconds(1);
            _Timer.Tick    += _Timer_Tick;
            _Timer.Start();
        }
        private async void StartButton_Click(object sender, RoutedEventArgs e)
        {
            PebbleConnector _pc = PebbleConnector.GetInstance();

            //_vmBinder.vmNewMatch = new vmNewMatch();

            _vmBinder.Tennis.vmMatch = new vmMatchState();
            ApplicationData.Current.LocalSettings.Values.Remove(Constants.TennisState);
            ApplicationData.Current.LocalSettings.Values.Remove(Constants.TennisCommand);
            //_vmBinder.vmMatch.Start(_vmBinder.vmNewMatch);

            ShowPage(ProgressRing);

            _Timer          = new DispatcherTimer();
            _Timer.Interval = TimeSpan.FromSeconds(1);
            _Timer.Tick    += _Timer_Tick;
            _Timer.Start();

            try
            {
                await _vmBinder.vmNewMatch.Save();

                var localSettings = Windows.Storage.ApplicationData.Current.LocalSettings;
                localSettings.Values[Constants.BackgroundTennis] = true;

                await _pc.StartBackgroundTask(PebbleConnector.Initiator.Tennis);
            }
            catch (Exception exc)
            {
                var messageDialog = new Windows.UI.Popups.MessageDialog(exc.Message, "Error");

                // Show the message dialog
                messageDialog.ShowAsync();

                ShowPage(NewMatchGrid);
            }
        }
        /// <summary>
        /// An item was clicked, make the watch app active on the Pebble
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void lvWatchApps_ItemClick(object sender, ItemClickEventArgs e)
        {
            try
            {
                vmWatchApp _app = (vmWatchApp)e.ClickedItem;

                switch (_app.Name)
                {
                    case "Pace":

                        // Navigate to the new page
                        Frame.Navigate(typeof(PaceApp), null);

                        break;

                    case "Tennis":

                        // Navigate to the new page
                        Frame.Navigate(typeof(TennisApp), null);

                        break;

                    default:

                        _vmBinder.Log.Add("Select item: " + _app.Name);

                        await PebbleConnector.GetInstance().Select(_app.Model, WatchItems.WatchItemType.WatchApp);

                        break;
                }
            }
            catch (Exception exc)
            {
                System.Diagnostics.Debug.WriteLine("An exception occurred launching watch item: " + exc.Message);
                _vmBinder.Log.Add("An exception occurred launching watch item: " + exc.Message);
            }
        }
示例#19
0
        /// <summary>
        /// Main thread for communication with pebble on a background task.
        ///
        /// Reading the state of the process is possible via the local settings BackgroundIsRunning. Synchronization via
        /// Mutex is not possible due to heavy use of await statements. The mutex will be abandoned and releasing gives
        /// an exception.
        /// </summary>
        /// <param name="taskInstance"></param>
        public async void Run(IBackgroundTaskInstance taskInstance)
        {
            var def = taskInstance.GetDeferral();

            var localSettings = ApplicationData.Current.LocalSettings;

            Handler = -1;
            localSettings.Values[Constants.BackgroundCommunicatieError] = (int)BCState.OK;

            try
            {
                System.Diagnostics.Debug.WriteLine("Start BackgroundCommunication");

                //Connect
                _pc     = PebbleConnector.GetInstance();
                Handler = await _pc.Connect(-1);

                if (_pc.IsConnected)
                {
                    AddToLog("Connection made with Pebble Time");

                    Log = new ObservableCollection <string>();
                    Log.CollectionChanged += Log_CollectionChanged;

                    _pc.Pebble.Log = Log;
                    _pc.StartReceivingMessages();
                    _pc.disconnectEventHandler           += _pc_disconnectEventHandler;
                    _pc.Pebble._protocol.MessageReceived += AppMessageReceived;

                    bool Continue = true;

                    //initialise settings

                    while (Continue)
                    {
                        try
                        {
                            localSettings.Values[Constants.BackgroundCommunicatieIsRunning] = true;

                            if (_pc.IsConnected)
                            {
                                await PaceHandler();

                                await TennisHandler();

                                //await Wipe();

                                await Synchronize();

                                await Select();

                                await Launch();

                                await AddItem();

                                await PebbleKitExecution();
                            }
                            else
                            {
                                await Reconnect();
                            }
                        }
                        catch (Exception e)
                        {
                            System.Diagnostics.Debug.WriteLine(e.Message + e.StackTrace);
                        }

                        await ProcessDelay();

                        //Check if continue
                        Continue = ((int)localSettings.Values[Constants.BackgroundCommunicatieContinue] != 0);
                    }

                    await PaceHandlerCleanup();

                    localSettings.Values[Constants.BackgroundTennis] = false;
                    localSettings.Values[Constants.BackgroundPace]   = false;

                    _pc.Pebble._protocol.MessageReceived -= AppMessageReceived;
                }
                else
                {
                    AddToLog("Connection with Pebble Time Failed.");
                    localSettings.Values[Constants.BackgroundCommunicatieError] = (int)BCState.ConnectionFailed;

                    if (_pc.LastError.Length > 0)
                    {
                        AddToLog(_pc.LastError);
                    }
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Exception BackgroundCommunication: " + e.Message);
                localSettings.Values[Constants.BackgroundCommunicatieError] = (int)BCState.ExceptionOccurred;
            }
            finally
            {
                localSettings.Values[Constants.BackgroundCommunicatieIsRunning] = false;

                //Disconnect
                if (_pc.IsConnected)
                {
                    _pc.Disconnect(Handler);

                    AddToLog("Disconnected from Pebble Time");
                }
            }

            System.Diagnostics.Debug.WriteLine("End BackgroundCommunication");

            def.Complete();
        }
            public async Task sendAppMessage(ExpandoObject data)
            {
                PebbleConnector _pc = PebbleConnector.GetInstance();

                int newToken = await _pc.Connect(-1);

                try
                {
                    if (_pc.IsConnected)
                    {
                        System.Diagnostics.Debug.WriteLine(String.Format("sendAppMessage(data={0})", data.ToString()));

                        P3bble.Messages.AppMessage _am = new P3bble.Messages.AppMessage(P3bble.Constants.Endpoint.ApplicationMessage);
                        uint iKey = 0;

                        _am.Content       = new Dictionary <int, object>(data.Count());
                        _am.Command       = P3bble.Messages.AppCommand.Push;
                        _am.AppUuid       = ParentItem.ID;
                        _am.TransactionId = (byte)_pc.GetNextMessageIdentifier();

                        foreach (var element in data)
                        {
                            if (element.Value != null)
                            {
                                if (ParentItem.AppKeys.ContainsKey(element.Key))
                                {
                                    iKey = (uint)ParentItem.AppKeys[element.Key];

                                    Type VariableType = element.Value.GetType();
                                    System.Diagnostics.Debug.WriteLine(String.Format("  key: {0}-{3}, value: {1}, type: {2}", element.Key, element.Value, VariableType.ToString(), iKey));

                                    if (VariableType == typeof(String))
                                    {
                                        String Value = (String)element.Value;
                                        //_am.AddTuple(iKey, P3bble.Messages.AppMessageTupleDataType.String, System.Text.Encoding.UTF8.GetBytes(Value));
                                        _am.Content.Add((int)iKey, Value);
                                    }

                                    if (VariableType == typeof(Double))
                                    {
                                        double dValue = (double)element.Value;
                                        int    iValue = (int)dValue;
                                        byte[] bytes  = BitConverter.GetBytes(iValue);
                                        //_am.AddTuple(iKey, P3bble.Messages.AppMessageTupleDataType.Int, bytes);
                                        _am.Content.Add((int)iKey, iValue);
                                    }
                                }
                            }
                        }


                        //byte[] package = _am.ToBuffer();
                        //System.Diagnostics.Debug.WriteLine("<< PAYLOAD: " + BitConverter.ToString(package).Replace("-", ":"));

                        await _pc.Pebble._protocol.WriteMessage(_am);
                    }
                }
                catch (Exception exp)
                {
                    System.Diagnostics.Debug.WriteLine(exp.Message);
                }
                finally
                {
                    _pc.Disconnect(newToken);
                }
            }