Example #1
0
        /// <summary>
        /// Wipe the Pebble Time
        /// </summary>

        /*private async Task Wipe()
         * {
         *  if (PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Reset))
         *  {
         *
         *
         *      _tlsynchronizer = new TimeLineSynchronizer();
         *      _tlsynchronizer.Log.CollectionChanged += Log_CollectionChanged;
         *      await _tlsynchronizer.Wipe();
         *
         *      AddProcessDelay(30000, PebbleConnector.Initiator.Reset);
         *  }
         * }*/

        private async Task Synchronize()
        {
            if (PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Synchronize))
            {
                _tlsynchronizer = new TimeLineSynchronizer();
                _tlsynchronizer.Log.CollectionChanged += Log_CollectionChanged;
                await _tlsynchronizer.Synchronize();

                PebbleConnector.ClearBackgroundTaskRunningStatus(PebbleConnector.Initiator.Synchronize);
            }
        }
        /// <summary>
        /// Timer processing
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void _timer_Tick(object sender, object e)
        {
            var localSettings = ApplicationData.Current.LocalSettings;

            Duration = (String)localSettings.Values[Constants.PaceDuration];
            Pace     = (String)localSettings.Values[Constants.PacePace];
            Distance = (String)localSettings.Values[Constants.PaceDistance];

            /*if (localSettings.Values.Keys.Contains(Constants.BackgroundCommunicatieIsRunning))
             * {
             *  IsRunning = (bool)localSettings.Values[Constants.BackgroundCommunicatieIsRunning];
             * }*/

            IsRunning = PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Pace);

            if (localSettings.Values.Keys.Contains(Constants.PacePaused))
            {
                Paused = (bool)localSettings.Values[Constants.PacePaused];
            }
            if (localSettings.Values.Keys.Contains(Constants.PaceGPX))
            {
                Shareable = (bool)localSettings.Values[Constants.PaceGPX];
            }

            if (!IsRunning)
            {
                _NotRunning++;

                if (_NotRunning > 15)
                {
                    _Timer.Stop();
                }
            }
            else
            {
                _NotRunning = 0;
            }

            //Check if error occurred
            if (localSettings.Values.Keys.Contains(Constants.BackgroundCommunicatieError) &&
                (int)localSettings.Values[Constants.BackgroundCommunicatieError] == (int)BCState.ConnectionFailed)
            {
                ExtendedEventArgs _fe = new ExtendedEventArgs();
                _fe.Error = "Connection with Pebble Time failed. Try again.";
                OnFatalError(_fe);

                _Timer.Stop();

                localSettings.Values[Constants.BackgroundCommunicatieError] = (int)BCState.OK;
            }
        }
Example #3
0
        private async Task Launch()
        {
            var localSettings = ApplicationData.Current.LocalSettings;

            if (PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Launch))
            {
                String item     = (string)localSettings.Values[Constants.BackgroundCommunicatieLaunchItem];
                Guid   itemGuid = Guid.Parse(item);

                await _pc.Launch(itemGuid);

                AddToLog("Request send to launch app: " + item);

                AddProcessDelay(30000, PebbleConnector.Initiator.Launch);
            }
        }
Example #4
0
        private async Task AddItem()
        {
            var localSettings = ApplicationData.Current.LocalSettings;

            if (PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.AddItem))
            {
                String Filename = (String)localSettings.Values[Constants.BackgroundCommunicatieDownloadedItem];

                var _newItem = await Pebble_Time_Manager.WatchItems.WatchItem.Load(Filename);

                await _pc.Pebble.AddWatchItemAsync(_newItem);

                AddToLog("New app send: " + _newItem.Name);

                PebbleConnector.ClearBackgroundTaskRunningStatus(PebbleConnector.Initiator.AddItem);
            }
        }
Example #5
0
        private async Task PebbleKitExecution()
        {
            var localSettings = ApplicationData.Current.LocalSettings;

            if (PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.PebbleShowConfiguration))
            {
                String _watchItem = (string)localSettings.Values[Constants.PebbleWatchItem];

                var WatchItem = _pc.WatchItems.FindLast(x => x.ID.ToString() == _watchItem);

                if (WatchItem != null)
                {
                    System.Diagnostics.Debug.WriteLine("PebbleShowConfiguration: " + WatchItem.Name);

                    PebbleKitJS.OpenURL += PebbleKitJS_OpenURL;
                    await WatchItem.ShowConfiguration();

                    AddProcessDelay(180000, PebbleConnector.Initiator.PebbleShowConfiguration);
                }
            }

            if (PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.PebbleWebViewClosed))
            {
                String _watchItem = (string)localSettings.Values[Constants.PebbleWatchItem];
                String _value     = (string)localSettings.Values[Constants.PebbleWebViewClosed];

                var WatchItem = _pc.WatchItems.FindLast(x => x.ID.ToString() == _watchItem);

                if (WatchItem != null)
                {
                    System.Diagnostics.Debug.WriteLine("PebbleWebViewClosed: " + WatchItem.Name);

                    WatchItem.WebViewClosed(_value);

                    AddProcessDelay(30000, PebbleConnector.Initiator.PebbleWebViewClosed);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Tennis handler
        /// </summary>
        private async Task TennisHandler()
        {
            if (!PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Tennis))
            {
                return;
            }

            //initialise settings
            var localSettings   = ApplicationData.Current.LocalSettings;
            var roamingSettings = ApplicationData.Current.RoamingSettings;

            if (localSettings.Values.Keys.Contains(Constants.BackgroundTennis) &&
                (bool)localSettings.Values[Constants.BackgroundTennis])
            {
                //Initiate tennis match
                if (TennisMatch == null)
                {
                    TennisMatch = new vmMatch();
                    await TennisMatch.Load("tennis_pebble.xml");

                    if (TennisMatch.Match == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Initialize Tennis Match in background.");
                        vmNewMatch _vmNewMatch = await vmNewMatch.Load();

                        TennisMatch = new vmMatch();
                        TennisMatch.Start(_vmNewMatch);
                    }
                    else
                    {
                        TennisMatch.NewPoint();
                    }

                    vmMatchState _State = new vmMatchState();
                    _State.Fill(TennisMatch);
                    await Tennis_Statistics.Helpers.LocalStorage.Save(_State.Serialize(), "tennismatchstate.json", false);

                    localSettings.Values[Constants.TennisState] = "1";

                    System.Diagnostics.Debug.WriteLine("Tennis Match state stored");

                    _pc.Pebble._protocol.MessageReceived += this.TennisMessageReceived;

                    Guid TennisWatchApp = Guid.Parse(Constants.TennisAppGuid);
                    await _pc.Launch(TennisWatchApp);

                    await SendPebbleTennisScore(_State, TennisMatch);


                    // await SendPebbleTennisScore(_State);
                }
            }

            //A new state requested
            if (localSettings.Values.Keys.Contains(Constants.TennisState) &&
                (string)localSettings.Values[Constants.TennisState] == "2")
            {
                await SaveMatchState();
            }

            //Check for and process command
            if (localSettings.Values.Keys.Contains(Constants.TennisCommand) &&
                TennisMatch != null)
            {
                String Command = (String)localSettings.Values[Constants.TennisCommand];
                System.Diagnostics.Debug.WriteLine("Processing tennis command: " + Command);

                switch (Command)
                {
                case "switch":

                    TennisMatch.cmdSwitchServer.Execute(null);

                    AddToLog("Tennis: switch command");

                    break;

                case "stop":

                    TennisMatch.Terminate();

                    PebbleConnector.ClearBackgroundTaskRunningStatus(PebbleConnector.Initiator.Tennis);

                    AddToLog("Tennis: stop command");

                    break;

                case "suspend":

                    TennisMatch.Pause();

                    PebbleConnector.ClearBackgroundTaskRunningStatus(PebbleConnector.Initiator.Tennis);

                    AddToLog("Tennis: suspend command");

                    break;

                case "extend":

                    TennisMatch.cmdExtendMatch.Execute(null);

                    AddToLog("Tennis: extend command");

                    break;
                }

                localSettings.Values.Remove(Constants.TennisCommand);

                await SaveMatchState();
            }
        }
Example #7
0
        /// <summary>
        /// Pace handler
        /// </summary>
        /// <returns></returns>
        private async Task PaceHandler()
        {
            //initialise settings
            var localSettings   = ApplicationData.Current.LocalSettings;
            var roamingSettings = ApplicationData.Current.RoamingSettings;

            if (localSettings.Values.Keys.Contains(Constants.BackgroundPace) &&
                (bool)localSettings.Values[Constants.BackgroundPace])
            {
                if (!PebbleConnector.IsBackgroundTaskRunningStatusSet(PebbleConnector.Initiator.Pace))
                {
                    await PaceHandlerCleanup();
                }
                else
                {
                    if (_PaceHandler == null)
                    {
                        localSettings.Values[Constants.PaceSwitchPaused] = false;
                        localSettings.Values[Constants.PaceGPX]          = false;
                        if (localSettings.Values.Keys.Contains(Constants.Miles))
                        {
                            localSettings.Values[Constants.Miles] = localSettings.Values[Constants.Miles];
                        }
                        else
                        {
                            localSettings.Values[Constants.Miles] = !System.Globalization.RegionInfo.CurrentRegion.IsMetric;
                        }
                        localSettings.Values[Constants.BackgroundCommunicatieIsRunning] = true;

                        //initialise pace handler
                        _PaceHandler       = new Pebble_Time_Manager.Connector.PaceHandler();
                        _PaceHandler.Miles = (bool)localSettings.Values[Constants.Miles];
                        _PaceHandler.Start();
                        await _PaceHandler.UpdatePosition();
                    }

                    //Update pace
                    _PaceHandler.UpdatePosition();

                    if (!_PaceHandler.Paused)
                    {
                        //Send Pebble Message
                        await _PaceHandler.SendPebblePaceMessage();

                        localSettings.Values[Constants.PaceDistance] = string.Format("{0:f2}", _PaceHandler.Distance);
                        localSettings.Values[Constants.PaceDuration] = _PaceHandler.Duration.ToString(@"m\:ss");
                        localSettings.Values[Constants.PacePace]     = _PaceHandler.Pace.ToString(@"m\:ss");
                        if (_PaceHandler.Pace.TotalMinutes > 45)
                        {
                            localSettings.Values[Constants.PacePace] = "-";
                        }
                        if (_PaceHandler.Pace.TotalMilliseconds == 0)
                        {
                            localSettings.Values[Constants.PacePace] = "-";
                        }
                    }

                    localSettings.Values[Constants.PacePaused] = _PaceHandler.Paused;

                    //Check the switch pause/resume
                    if (localSettings.Values.Keys.Contains(Constants.PaceSwitchPaused))
                    {
                        bool SwitchPaused = (bool)localSettings.Values[Constants.PaceSwitchPaused];
                        localSettings.Values[Constants.PaceSwitchPaused] = false;
                        if (SwitchPaused)
                        {
                            if (_PaceHandler.Paused)
                            {
                                await _PaceHandler.Resume();
                            }
                            else
                            {
                                await _PaceHandler.Pause();
                            }
                        }
                    }
                }
            }
        }