Esempio n. 1
0
 private void NotConnected()
 {
     _pebble = null;
     PebbleName.Text = "Not connected";
     PebbleVersion.Text = string.Empty;
     RetryConnection.Visibility = Visibility.Visible;
 }
Esempio n. 2
0
        private async Task TryConnection()
        {
            Pebble.IsMusicControlEnabled = true;
            Pebble.IsLoggingEnabled = true;

            List<Pebble> pebbles = await Pebble.DetectPebbles();

            if (pebbles.Count >= 1)
            {
                _pebble = pebbles[0];
                await _pebble.ConnectAsync();

                if (_pebble != null && _pebble.IsConnected)
                {
                    _pebble.MusicControlReceived += new MusicControlReceivedHandler(this.MusicControlReceived);
                    _pebble.InstallProgress += new InstallProgressHandler(this.InstallProgressReceived);

                    PebbleName.Text = "Connected to Pebble " + _pebble.DisplayName;
                    PebbleVersion.Text = "Version " + _pebble.FirmwareVersion.Version + " - " + _pebble.FirmwareVersion.Timestamp.ToShortDateString();
                    RetryConnection.Visibility = Visibility.Collapsed;
                }
                else
                {
                    NotConnected();
                }
            }
        }
Esempio n. 3
0
        private async Task GetPebbleTimeAsyc()
        {
            TimeDisplay = "Getting curret Pebble time";
            TimeResponse timeResponse = await Pebble.GetTimeAsync();

            var current = DateTime.Now;

            if (timeResponse.Success)
            {
                var differece = timeResponse.Time - current;
                if (differece < TimeSpan.FromSeconds(2))
                {
                    TimeDisplay = "Pebble time is in sync with the phone";
                }
                else
                {
                    TimeDisplay = string.Format("Pebble is {0} {1} than the phone", differece.ToString(@"h\:mm\:ss"),
                                                timeResponse.Time > current ? "faster" : "slower");
                }
            }
            else
            {
                TimeDisplay = "Failed to get time from Pebble: " + timeResponse.ErrorMessage;
            }
        }
Esempio n. 4
0
 protected virtual void OnPebbleDisconnected( PebbleDisconnected pebbleDisconnected )
 {
     if ( pebbleDisconnected.Pebble == _pebble )
     {
         _pebble = null;
     }
 }
Esempio n. 5
0
 public PebbleViewModel( Pebble pebble )
 {
     if ( pebble == null ) throw new ArgumentNullException( "pebble" );
     _pebble = pebble;
     
     _toggleConnectionCommand = new RelayCommand( OnToggleConnect );
 }
Esempio n. 6
0
        private static void InstallApp(Pebble pebble)
        {
            var progress = new Progress <ProgressValue>(pv => Console.WriteLine(pv.ProgressPercentage + " " + pv.Message));

            string appPath = SelectApp();

            if (!string.IsNullOrEmpty(appPath) && File.Exists(appPath))
            {
                using (var stream = new FileStream(appPath, FileMode.Open))
                {
                    using (var zip = new Zip())
                    {
                        zip.Open(stream);
                        var bundle = new AppBundle();
                        stream.Position = 0;
                        bundle.Load(zip, pebble.Firmware.HardwarePlatform.GetSoftwarePlatform());
                        pebble.InstallClient.InstallAppAsync(bundle, progress).Wait();

                        //for firmware v3, launch is done as part of the install
                        //Console.WriteLine("App Installed, launching...");
                        //var uuid=new UUID(bundle.AppInfo.UUID);
                        //pebble.LaunchApp(uuid);
                        //Console.WriteLine ("Launched");
                    }
                }
            }
            else
            {
                Console.WriteLine("No .pbw");
            }
        }
Esempio n. 7
0
        public async Task InstallFirmwareAsyncRequiresBundle()
        {
            var bluetoothConnection = new Mock<IBluetoothConnection>();
            var pebble = new Pebble(bluetoothConnection.Object, TEST_PEBBLE_ID);

            await pebble.InstallFirmwareAsync(null);
        }
Esempio n. 8
0
    // Override from parent class, used to run specific projectile logic
    public override void Shoot(Transform t, Vector2 dir)
    {
        GameObject pebble       = Instantiate(m_Pebble, t.position, Quaternion.identity);
        Pebble     pebbleScript = pebble.GetComponent <Pebble>();

        pebbleScript.direction = dir;
    }
Esempio n. 9
0
        public async Task InstallFirmwareAsyncRequiresBundle()
        {
            var bluetoothConnection = new Mock <IBluetoothConnection>();
            var pebble = new Pebble(bluetoothConnection.Object, TEST_PEBBLE_ID);

            await pebble.InstallFirmwareAsync(null);
        }
Esempio n. 10
0
        /// <summary>
        /// Delete a watch item and send it to the Pebble (if connected)
        /// </summary>
        /// <param name="_deleteItem"></param>
        /// <returns></returns>
        public async Task <bool> DeleteWatchItemAsync(WatchItem _deleteItem)
        {
            try
            {
                //Remove from app
                await WatchItems.DeleteWatchItem(_deleteItem);

                //Remove from storage
                await LocalStorage.Delete(_deleteItem.File);

                await LocalStorage.Delete(_deleteItem.File.Replace(".zip", ".gif"));

                //Remove from watch
                if (IsConnected)
                {
                    await Pebble.DeleteWatchItemAsync(_deleteItem);
                }

                return(true);
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("DeleteWatchItemAsync exception: " + e.Message);
            }

            return(false);
        }
Esempio n. 11
0
 protected virtual void OnPebbleDisconnected(PebbleDisconnected pebbleDisconnected)
 {
     if (pebbleDisconnected.Pebble == _pebble)
     {
         _pebble = null;
     }
 }
Esempio n. 12
0
        private static async Task ShowPebbleMenu(Pebble pebble)
        {
            var menu = new Menu(
                "Disconnect",
                "Get Time",
                "Set Current Time",
                "Get Firmware Info",
                "Send Ping",
                "Media Commands",
                "Install App",
                "Send App Message");

            while (true)
            {
                switch (menu.ShowMenu())
                {
                case 0:
                    pebble.Disconnect();
                    return;

                case 1:
                    var timeResult = await pebble.GetTimeAsync();

                    DisplayResult(timeResult, x => string.Format("Pebble Time: " + x.Time.ToString("G")));
                    break;

                case 2:
                    await pebble.SetTimeAsync(DateTime.Now);

                    goto case 1;

                case 3:
                    var firmwareResult = await pebble.GetFirmwareVersionAsync();

                    DisplayResult(firmwareResult,
                                  x => string.Join(Environment.NewLine, "Firmware", x.Firmware.ToString(),
                                                   "Recovery Firmware", x.RecoveryFirmware.ToString()));
                    break;

                case 4:
                    var pingResult = await pebble.PingAsync();

                    DisplayResult(pingResult, x => "Received Ping Response");
                    break;

                case 5:
                    ShowMediaCommands(pebble);
                    break;

                case 6:
                    InstallApp(pebble);
                    break;

                case 7:
                    SendAppMessage(pebble);
                    break;
                }
            }
        }
Esempio n. 13
0
 public PebbleConnected(Pebble pebble)
 {
     if (pebble == null)
     {
         throw new ArgumentNullException("pebble");
     }
     _pebble = pebble;
 }
Esempio n. 14
0
        public void ConstructorTest()
        {
            var bluetoothConnection = new Mock <IBluetoothConnection>(MockBehavior.Strict);

            var pebble = new Pebble(bluetoothConnection.Object, TEST_PEBBLE_ID);

            Assert.AreEqual(TEST_PEBBLE_ID, pebble.PebbleID);
        }
Esempio n. 15
0
        public void ConstructorTest()
        {
            var bluetoothConnection = new Mock<IBluetoothConnection>(MockBehavior.Strict);

            var pebble = new Pebble(bluetoothConnection.Object, TEST_PEBBLE_ID);

            Assert.AreEqual(TEST_PEBBLE_ID, pebble.PebbleID);
        }
Esempio n. 16
0
 private async void OnSetTime()
 {
     if (Pebble != null)
     {
         TimeDisplay = "Setting Pebble time";
         await Pebble.SetTimeAsync(DateTime.Now);
         await GetPebbleTimeAsyc();
     }
 }
Esempio n. 17
0
        public async Task ScanForPairedDevicesAsync()
        {
            _pebbles.Clear();
            foreach ( var pebble in await PebbleWinRT.DetectPebbles() )
                _pebbles.Add( pebble );

            if ( _pebbles.Count >= 1 )
                SelectedPebble = _pebbles[0];
        }
Esempio n. 18
0
        private async Task LoadFirmwareAsync()
        {
            FirmwareVersionResponse firmwareResponse = await Pebble.GetFirmwareVersionAsync();

            if (firmwareResponse.Success)
            {
                Firmware         = firmwareResponse.Firmware;
                RecoveryFirmware = firmwareResponse.RecoveryFirmware;
            }
        }
Esempio n. 19
0
        public PebbleViewModel(Pebble pebble)
        {
            if (pebble == null)
            {
                throw new ArgumentNullException("pebble");
            }
            _pebble = pebble;

            _toggleConnectionCommand = new RelayCommand(OnToggleConnect);
        }
Esempio n. 20
0
 /// <summary>
 /// Reset the UI to the disconnected state.  To be called through Invoke.
 /// </summary>
 private void DisconnectUIUpdate()
 {
     WatchfacePic.Image = Properties.Resources.watchface_off;
     pebbleNameToolStripMenuItem.Text    = "Disconnected";
     disconnectToolStripMenuItem.Enabled = false;
     notifyIcon.Text = "Disconnected";
     ResetVersionInfo();
     pebble = null;
     DisEnableControls();
 }
Esempio n. 21
0
        static void AddApp(Pebble pebble, string watch = null, bool removeFirst = false)
        {
            string watchdir = null;

            if (String.IsNullOrEmpty(watch))
            {
                watchdir = ConfigurationManager.AppSettings["watch-dir"];
                if (watchdir == null)
                {
                    Console.WriteLine("Missing .config entry for 'watch-dir'");
                    return;
                }
                if (!Directory.Exists(watchdir))
                {
                    Console.WriteLine("watch-dir not found: {0}", watchdir);
                    return;
                }
            }
            var appbank = pebble.GetAppbankContents().AppBank;
            var applist = appbank.Apps;

            if (applist.Count == appbank.Size)
            {
                Console.WriteLine("All {0} banks are full", appbank.Size);
                return;
            }
            try
            {
                if (String.IsNullOrEmpty(watch))
                {
                    Console.WriteLine("Choose an app to install");
                    var watches = Directory.GetFiles(watchdir, "*.pbw");
                    watch = SharpMenu <string> .WriteAndPrompt(watches);

                    watch = Path.Combine(watchdir, watch);
                }
                if (removeFirst)
                {
                    PebbleBundle pb         = new PebbleBundle(watch);
                    var          app2remove = applist.Find(delegate(AppBank.App app) { return(app.Name == pb.Application.AppName); });
                    if (app2remove.Name != null)
                    {
                        Console.WriteLine("Removing existing...");
                        pebble.RemoveApp(app2remove);
                        Thread.Sleep(2000); // let things settle
                    }
                }
                Console.WriteLine("Installing...");
                pebble.InstallApp(watch, applist.Count);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Esempio n. 22
0
        static async Task DeleteApp(Pebble pebble)
        {
            var applist = (await pebble.GetAppbankContentsAsync()).AppBank.Apps;

            Console.WriteLine("Choose an app to remove");
            AppBank.App result = SharpMenu <AppBank.App> .WriteAndPrompt(applist);

            AppbankInstallResponse ev = await pebble.RemoveAppAsync(result);

            Console.WriteLine(ev.MsgType);
        }
Esempio n. 23
0
        public async Task SetPebbleAsync(Pebble pebble)
        {
            if (pebble == null) throw new ArgumentNullException("pebble");
            if (pebble.IsAlive == false)
            {
                await pebble.ConnectAsync();
            }

            Info.Pebble = Apps.Pebble = pebble;
            await Info.RefreshAsync();
            await Apps.RefreshAsync();
        }
Esempio n. 24
0
 /// <summary>
 /// Background task for Pebble autodetect.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void listUpdateWorker_DoWork(object sender, DoWorkEventArgs e)
 {
     try
     {
         List <Pebble> peblist = Pebble.DetectPebbles();
         e.Result = peblist;
     }
     catch (PlatformNotSupportedException)
     {
         MessageBox.Show("Failed to connect: make sure your Bluetooth adapter is connected and enabled.");
         pebble = null;
     }
 }
Esempio n. 25
0
 private void Connect_Click(object sender, EventArgs e)
 {
     if (pebble != null)
     {
         pebble.Disconnect();
         pebble = null;
     }
     else
     {
         ConnectToSelectedPebble();
     }
     DisEnableControls();
 }
Esempio n. 26
0
        public async Task ScanForPairedDevicesAsync()
        {
            _pebbles.Clear();
            foreach (var pebble in await PebbleWinRT.DetectPebbles())
            {
                _pebbles.Add(pebble);
            }

            if (_pebbles.Count >= 1)
            {
                SelectedPebble = _pebbles[0];
            }
        }
Esempio n. 27
0
        private async Task LoadAppsAsync()
        {
            var appBankContents = await Pebble.GetAppbankContentsAsync();

            Apps.Clear();
            if (appBankContents != null && appBankContents.AppBank != null && appBankContents.AppBank.Apps != null)
            {
                foreach (var app in appBankContents.AppBank.Apps)
                {
                    Apps.Add(app);
                }
            }
        }
Esempio n. 28
0
        private async void OnUninstallApp(PebbleApp?app)
        {
            if (app == null)
            {
                return;
            }

            var response = await Pebble.RemoveAppAsync(app.Value);

            if (response.Success)
            {
                await LoadAppsAsync();
            }
        }
Esempio n. 29
0
        static void DeleteApp(Pebble pebble)
        {
            var applist = pebble.GetAppbankContents().AppBank.Apps;

            Console.WriteLine("Choose an app to remove");
            AppBank.App result = SharpMenu <AppBank.App> .WriteAndPrompt(applist);

            AppbankInstallMessageEventArgs ev = pebble.RemoveApp(result);

            if (ev != null)
            {
                Console.WriteLine(ev.MsgType);
            }
        }
Esempio n. 30
0
        public async Task SetPebbleAsync(Pebble pebble)
        {
            if (pebble == null)
            {
                throw new ArgumentNullException("pebble");
            }
            if (pebble.IsAlive == false)
            {
                await pebble.ConnectAsync();
            }

            Info.Pebble = Apps.Pebble = pebble;
            await Info.RefreshAsync();

            await Apps.RefreshAsync();
        }
Esempio n. 31
0
        private static void SendAppMessage(Pebble pebble)
        {
            string uuidAppPath = SelectApp();

            if (!string.IsNullOrEmpty(uuidAppPath) && File.Exists(uuidAppPath))
            {
                using (var stream = new FileStream(uuidAppPath, FileMode.Open))
                {
                    using (var zip = new Zip())
                    {
                        zip.Open(stream);
                        var bundle = new AppBundle();
                        stream.Position = 0;
                        bundle.Load(zip, pebble.Firmware.HardwarePlatform.GetSoftwarePlatform());

                        System.Console.Write("Enter Message:");
                        var messageText = System.Console.ReadLine();

                        //format a message
                        var rand = new Random().Next();
                        AppMessagePacket message = new AppMessagePacket();
                        message.Command = (byte)Command.Push;
                        message.Values.Add(new AppMessageUInt32()
                        {
                            Key = 0, Value = (uint)rand
                        });
                        message.Values.Add(new AppMessageString()
                        {
                            Key = 1, Value = messageText
                        });
                        message.ApplicationId = bundle.AppMetadata.UUID;
                        message.TransactionId = 255;


                        //send it
                        Console.WriteLine("Sending Status " + rand + " to " + bundle.AppMetadata.UUID.ToString());
                        var task = pebble.SendApplicationMessage(message);
                        task.Wait();
                        Console.WriteLine("Response received");
                    }
                }
            }
            else
            {
                Console.WriteLine("No .pbw");
            }
        }
Esempio n. 32
0
        private static void ShowMediaCommands(Pebble pebble)
        {
            Console.WriteLine("Listening for media commands");
            pebble.RegisterCallback <MusicControlResponse>(result =>
                                                           DisplayResult(result, x => string.Format("Media Control Response " + x.Command)));

            var menu = new Menu("Return to menu");

            while (true)
            {
                switch (menu.ShowMenu())
                {
                case 0:
                    return;
                }
            }
        }
Esempio n. 33
0
        /// <summary>
        /// Write a message direct to the Pebble. Message is described as a string (00:01:02 etc)
        /// </summary>
        /// <param name="Message"></param>
        /// <returns></returns>
        public async Task WriteMessage(String Message)
        {
            String[] StringBytes = Message.Split(":".ToCharArray());
            Byte[]   Bytes       = new Byte[StringBytes.Count()];
            int      index       = 0;

            foreach (String Byte in StringBytes)
            {
                Bytes[index] = byte.Parse(Byte, System.Globalization.NumberStyles.HexNumber);
                index++;
            }

            System.Diagnostics.Debug.WriteLine("<< PAYLOAD: " + Message);

            Pebble.Writer().WriteBytes(Bytes);
            await Pebble.Writer().StoreAsync().AsTask();
        }
Esempio n. 34
0
        public async Task InstallFirmwareAsyncTest()
        {
            var bundle        = new Mock <FirmwareBundle>();
            var firmwareBytes = new byte[16];
            var resourceBytes = new byte[4];

            bundle.SetupGet(x => x.HasResources).Returns(true);
            bundle.SetupGet(x => x.Resources).Returns(resourceBytes);
            bundle.SetupGet(x => x.Firmware).Returns(firmwareBytes);

            var bluetoothConnection = new Mock <IBluetoothConnection>(MockBehavior.Strict);

            //Resource and firmware headers
            bluetoothConnection.Setup(x => x.Write(It.Is <byte[]>(b => b.Length == 11)))
            .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
            .Verifiable();
            //Resource data
            bluetoothConnection.Setup(x => x.Write(It.Is <byte[]>(b => b.Length == 13)))
            .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
            .Verifiable();
            //Firmware data
            bluetoothConnection.Setup(x => x.Write(It.Is <byte[]>(b => b.Length == 25)))
            .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
            .Verifiable();
            //Resource and Firmware CRC
            bluetoothConnection.Setup(x => x.Write(It.Is <byte[]>(b => b.Length == 9)))
            .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
            .Verifiable();
            //Put bytes complete message
            bluetoothConnection.Setup(x => x.Write(It.Is <byte[]>(b => b.Length == 5)))
            .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
            .Verifiable();
            //Send and complete firmware system messages
            bluetoothConnection.Setup(x => x.Write(It.Is <byte[]>(b => b.Length == 6)))
            .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.SystemMessage))
            .Verifiable();

            var pebble = new Pebble(bluetoothConnection.Object, TEST_PEBBLE_ID);

            bool success = await pebble.InstallFirmwareAsync(bundle.Object);

            Assert.IsTrue(success);
            bluetoothConnection.Verify();
        }
Esempio n. 35
0
        /// <summary>
        /// UI update after the Pebble autodetect has finished.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listUpdateWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            Pebble autocon = null;
            var    pebbles = e.Result as List <Pebble>;

            if (pebbles != null && pebbles.Count > 0)
            {
                // Found some Pebbles, let's add them to the combobox
                foreach (Pebble peb in pebbles)
                {
                    PebbleList.Items.Add(peb);
                    if (peb.PebbleID == Properties.Settings.Default.LastKnownPebble &&
                        peb.Port == Properties.Settings.Default.LastKnownPebblePort)
                    {
                        autocon = peb;
                    }
                }

                PebbleList.SelectedIndex = 0;

                if (autocon != null &&
                    Properties.Settings.Default.Autoconnect)
                {
                    // Autoconnect possible and desired, so let's
                    PebbleList.SelectedItem = autocon;
                    for (int i = 0; i < 5; i++)
                    {
                        try
                        {
                            // Serial comms is awesome.  Try connecting a bunch of times with delays.
                            ConnectToSelectedPebble();
                            Thread.Sleep(1500);
                            break;
                        }
                        catch (IOException)
                        {
                        }
                    }
                }
            }
            DisEnableControls();
        }
Esempio n. 36
0
        public async Task InstallFirmwareAsyncTest()
        {
            var bundle = new Mock<FirmwareBundle>();
            var firmwareBytes = new byte[16];
            var resourceBytes = new byte[4];
            bundle.SetupGet(x => x.HasResources).Returns(true);
            bundle.SetupGet(x => x.Resources).Returns(resourceBytes);
            bundle.SetupGet(x => x.Firmware).Returns(firmwareBytes);

            var bluetoothConnection = new Mock<IBluetoothConnection>(MockBehavior.Strict);

            //Resource and firmware headers
            bluetoothConnection.Setup(x => x.Write(It.Is<byte[]>(b => b.Length == 11)))
                .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
                .Verifiable();
            //Resource data
            bluetoothConnection.Setup(x => x.Write(It.Is<byte[]>(b => b.Length == 13)))
                .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
                .Verifiable();
            //Firmware data
            bluetoothConnection.Setup(x => x.Write(It.Is<byte[]>(b => b.Length == 25)))
                .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
                .Verifiable();
            //Resource and Firmware CRC
            bluetoothConnection.Setup(x => x.Write(It.Is<byte[]>(b => b.Length == 9)))
                .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
                .Verifiable(); 
            //Put bytes complete message
            bluetoothConnection.Setup(x => x.Write(It.Is<byte[]>(b => b.Length == 5)))
                .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.PutBytes))
                .Verifiable();
            //Send and complete firmware system messages
            bluetoothConnection.Setup(x => x.Write(It.Is<byte[]>(b => b.Length == 6)))
                .Raises(x => x.DataReceived += null, bluetoothConnection, ResponseGenerator.GetBytesReceivedResponse(Endpoint.SystemMessage))
                .Verifiable();

            var pebble = new Pebble(bluetoothConnection.Object, TEST_PEBBLE_ID);

            bool success = await pebble.InstallFirmwareAsync(bundle.Object);
            Assert.IsTrue(success);
            bluetoothConnection.Verify();
        }
Esempio n. 37
0
        public async Task SelectFace(Guid ID)
        {
            //Connect to the watch
            try
            {
                //_ConnectionToken = await Connect(_ConnectionToken);

                if (!IsConnected)
                {
                    throw new Exception("No connection with Pebble Time");
                }

                Guid CurrentWatchFace = Pebble.CurrentWatchFace;
                //Get current ID

                /*WatchFaceMessage _wfm = new WatchFaceMessage();
                 * Guid CurrentWatchFace = await Pebble.RequestWatchFaceMessageAsync(_wfm);
                 */
                if (CurrentWatchFace != Guid.Empty)
                {
                    //Set new ID
                    WatchFaceSelectMessage _wfsm = new WatchFaceSelectMessage(CurrentWatchFace, ID);
                    await Pebble.WriteWatchFaceSelectMessageAsync(_wfsm);
                }
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine("Select WatchFace: " + e.Message);
            }

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

            localSettings.Values["CurrentWatchFace"] = ID;

            //Pebble._protocol.StartRun();
            //SetDisconnectTimer(60, _ConnectionToken);
            //Pebble.ItemSend += Pebble_ItemSend;

            //if (_pc.IsConnected) _pc.Disconnect();
        }
Esempio n. 38
0
 private void pebble_OnConnect(object sender, EventArgs e)
 {
     // Dirtyfix for when things get out of sync for reasons yet to be found
     if (pebble == null)
     {
         return;
     }
     WatchfacePic.Image = Properties.Resources.watchface;
     Connect.Text       = "Dis&connect";
     PebbleList.Enabled = false;
     try
     {
         pebble.GetVersion();
         Scan.Enabled = false;
         SetVersionInfo();
         Properties.Settings.Default.LastKnownPebble     = pebble.PebbleID;
         Properties.Settings.Default.LastKnownPebblePort = pebble.Port;
         // Don't really like saving *all* settings here
         Properties.Settings.Default.Save();
         pebbleNameToolStripMenuItem.Text    = pebble.ToString();
         disconnectToolStripMenuItem.Enabled = true;
         notifyIcon.Text = "Connected (" + pebble.PebbleID + ")";
     }
     // Some stuff that can go wrong while connecting...
     catch (TimeoutException err)
     {
         pebble.Disconnect();
         MessageBox.Show(err.Message, "Connection timeout",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         pebble = null;
     }
     catch (InvalidOperationException err)
     {
         pebble.Disconnect();
         MessageBox.Show(err.Message + "\nTry scanning again.", "Connection failed",
                         MessageBoxButtons.OK, MessageBoxIcon.Error);
         pebble = null;
     }
 }
Esempio n. 39
0
        private static void SetTime(Pebble pebble)
        {
            Console.WriteLine("Enter time <current>:");
            var time = Console.ReadLine();

            if (String.IsNullOrEmpty(time))
            {
                pebble.SetTime(DateTime.Now);
            }
            else
            {
                DateTime result;
                if (DateTime.TryParse(time, out result))
                {
                    pebble.SetTime(result);
                }
                else
                {
                    Console.WriteLine("invalid time");
                }
            }
        }
Esempio n. 40
0
 public PebbleConnected( Pebble pebble )
 {
     if (pebble == null) throw new ArgumentNullException("pebble");
     _pebble = pebble;
 }
Esempio n. 41
0
 private void OnConnect( Pebble pebble )
 {
     Frame.Navigate( typeof( MainPage ), pebble );
 }
Esempio n. 42
0
    private void checkInput()
    {
        // these are false unless one of keys is pressed
        isLeft = false;
        isRight = false;
        isJump = false;
        isGoDown = false;

        movingDir = moving.None;

        #region Pebble (F)
        if (Input.GetKeyDown(KeyCode.F)) { //OnPress -> set pebble power to 0 and create powerBar
            if(!pebble) { //Only if not already existing (can't have 2 pebbles at the same time)
                powerPebble = 0f; //
                setPebbleBarPos();
                pebbleBar.transform.localScale = new Vector3(0f,1f,1f);
                preparePebble = specialCast = true;
            }
        }
        if (Input.GetKey(KeyCode.F)) { //Hold F to add power
            if(powerPebble <= pebbleMaxStrengh && !pebble) { //Pebble max strenght
                preparePebble = specialCast = true;
                powerPebble += 0.2f;
                pebbleBar.transform.localScale = new Vector3(powerPebble,0.3f,1f); //Resize powerBar
                setPebbleBarPos();
            }
        }
        if (Input.GetKeyUp(KeyCode.F)) { //RELEASE THE PEBBLE !!
            if(!pebble) { //If no pebble already existing
                preparePebble = false;
                launchPebble = true;
                GOpebble = Instantiate(Resources.Load("Prefabs/04Gameplay/Pebble")) as GameObject;
                pebble = GOpebble.GetComponent<Pebble>(); //Create Pebble
                pebble.setPosition((transform.position.x-transform.localScale.x/2),(transform.position.y+transform.localScale.y/2), -6f); //Pebble ini position
                pebble.setCallerObject(thisTransform);
                pebbleDirection = (facingDir == facing.Right) ? 1 : -1;	//Direction of the pebble
                pebble.throwPebble(powerPebble, pebbleDirection); //Throw pebble function
                powerPebble = 0f; //reset power
                pebbleBar.transform.localScale = new Vector3(powerPebble,0.3f,1f); //reset power bar
                pebbleBar.transform.position = new Vector3((powerPebble/2)+thisTransform.position.x,thisTransform.position.y+2f,-30f);
            }
        }
        if (Input.GetKeyDown(KeyCode.KeypadPlus))
        {
            pebbleCount += 1;
        }
        if (Input.GetKeyDown(KeyCode.KeypadMinus))
        {
            pebbleCount -= 1;
        }
        #endregion
        #region TEMPORARY MUST NOT BE IN FINAL VERSION (Y) & (T) -> Destroy current circles
        if (Input.GetKeyDown(KeyCode.Y))
        {
            soundInstru2.destroyCircle();
        }
        if (Input.GetKeyDown(KeyCode.T))
        {
            soundInstru1.destroyCircle();
        }
        #endregion
        #region Instru Skill (R)
        if (Input.GetKeyDown(KeyCode.R)  && grounded && !specialCast) {
            playSoundInstru();
            StartCoroutine("specialCircleCast");
        }
        #endregion
        #region Sprint management (LeftShift)
        if(Input.GetKeyDown("left shift")) {//OnPress
            moveVel = moveVelSprint; //Increase Player Speed
            //footStepDelay = footStepDelaySprint; //Decrease FootStep Delay
            isSprint = true;
        }
        if(Input.GetKeyUp("left shift")) {//OnRelease
            moveVel = moveVelINI; //Decrease Player Speed
            //footStepDelay = footStepDelayINI; //Increase FootStep Delay
            isSprint = false;
        }
        if(Input.GetKeyDown("left shift")) {//LeftShift input
            toSprint=true;
        }
        else if(Input.GetKeyUp("left shift")) {//NO LeftShift input
            toWalk=true;
        }
        /*if(!blockCoroutine) {*/
        if(toSprint && grounded) {
            StopCoroutine("queueWaveState");
            StartCoroutine(queueWaveState("ToSprint",soundEmitt1));
            StartCoroutine(queueWaveState("ToSprint",soundEmitt2));
            StartCoroutine(queueWaveState("ToSprint",soundEmitt3));
        //				/*if(soundEmitt1.getAlpha() <= 0f)*/ soundEmitt1.circleWalkToSprint();
        //			/*if(soundEmitt2.getAlpha() <= 0f)*/ soundEmitt2.circleWalkToSprint();
        //			/*if(soundEmitt3.getAlpha() <= 0f)*/ soundEmitt3.circleWalkToSprint();
                toSprint=false;
            footStepDelay = footStepDelaySprint;
            }
        else if (toWalk && grounded) {
            StopCoroutine("queueWaveState");
            StartCoroutine(queueWaveState("ToWalk",soundEmitt1));
            StartCoroutine(queueWaveState("ToWalk",soundEmitt2));
            StartCoroutine(queueWaveState("ToWalk",soundEmitt3));
        //			/*if(soundEmitt1.getAlpha() <= 0f)*/ soundEmitt1.circleSprintToWalk();
        //			/*if(soundEmitt2.getAlpha() <= 0f)*/ soundEmitt2.circleSprintToWalk();
        //			/*if(soundEmitt3.getAlpha() <= 0f)*/ soundEmitt3.circleSprintToWalk();
            toWalk=false;
            footStepDelay = footStepDelayINI;
        }
        /*}*/
        #endregion
        #region Movement (Left), (Right), (Up), (Down), (Space)
        if((Input.GetKey("left") || Input.GetKey(KeyCode.Q)) && !specialCast) { //If input left & not casting instru
            isLeft = true;
            shootLeft = true;
            facingDir = facing.Left;
            if(!blockCoroutine && grounded) StartCoroutine("waitB4FootStep");
        }
        if(((Input.GetKeyUp("left") || Input.GetKeyUp(KeyCode.Q)) && !specialCast) || ((Input.GetKeyUp("right") || Input.GetKeyUp(KeyCode.D)) && !isLeft && !specialCast)) {
            StopCoroutine("footStep");
            StopCoroutine("waitB4FootStep");
            blockCoroutine = false;
        }
        if(((Input.GetKeyDown("left") || Input.GetKeyDown(KeyCode.Q)) && !specialCast) || ((Input.GetKeyDown("right") || Input.GetKeyDown(KeyCode.D)) && !isLeft && !specialCast)) {
            StopCoroutine("waitB4FootStep");
            StopCoroutine("footStep");
            blockCoroutine = false;
        }
        if ((Input.GetKey("right") || Input.GetKey(KeyCode.D)) && !isLeft && !specialCast) { //If input right & not casting instru
            isRight = true;
            facingDir = facing.Right;
            shootLeft = false;
            if(!blockCoroutine && grounded) StartCoroutine("waitB4FootStep");
        }
        if ((Input.GetKeyDown("down") || Input.GetKeyDown(KeyCode.S)) && !specialCast && (grounded || isGrab)) {

            if(isGrab) {checkingGrabPosition = false;StopCoroutine("checkGrabberPosition");isGrab = false;}
            else {
                if ( onEnvironment != null && onEnvironment.typeList == Environment.types.wood)
                {
                    onEnvironment.GetComponent<BoxCollider>().enabled = false;
                    StartCoroutine(EnableCollider(onEnvironment.GetComponent<BoxCollider>()));
                }
            }
        }
        if ((Input.GetKeyDown("up") || Input.GetKeyDown(KeyCode.Z)) && !specialCast && (grounded || isGrab)) {
            if(isGrab) {checkingGrabPosition = false;StopCoroutine("checkGrabberPosition");isGrab = false;}
            isJump = true;
            grounded = false;
        }
        #endregion
        #region Alpha (1), (2), (3)
        if (Input.GetKeyDown(KeyCode.Alpha1)) {
            //skill_axe.useSkill(Skills.SkillList.Axe);
        }
        if (Input.GetKeyDown(KeyCode.Alpha2)) {

        }
        if (Input.GetKeyDown(KeyCode.Alpha3)) {

        }
        #endregion
        #region (Escape)
        if (Input.GetKeyDown(KeyCode.Escape)) {
            if (GameEventManager.state != GameEventManager.GameState.Pause) GameEventManager.TriggerGamePause();
            else if (GameEventManager.state == GameEventManager.GameState.Pause) GameEventManager.TriggerGameUnpause();
        }
        #endregion
        if(grounded && checkingGrabPosition) {checkingGrabPosition = false;StopCoroutine("checkGrabberPosition");}

        if(grounded) {
            if(!firstGrounded) {
                //print("BEGIN BEING GROUNDED");
                firstGrounded = true;
                firstFalling = false;
                //StopCoroutine("footStep");
                playSoundFall();
                //cptWave = 1;
                if(fallFast) {
                    fallFast = false;
                    //soundEmitt3.circleWalkToSprint();
                    soundEmitt3.resetCircle(transform.localScale.x/1.5f,playerDirLeft, true);
                }
        //				soundEmitt1.circleFallToGrounded();
        //				soundEmitt2.circleFallToGrounded();
                //				soundEmitt3.circleFallToGrounded();
                StopCoroutine("footStep");
                StopCoroutine("waitB4FootStep");
                StopCoroutine("waitB4FallWave");
                blockFallWavesCorout = blockCoroutine = false;

                StopCoroutine("queueWaveState");
                if(isSprint) {
                    footStepDelay = footStepDelaySprint;
                    StartCoroutine(queueWaveState("ToSprint",soundEmitt1));
                    StartCoroutine(queueWaveState("ToSprint",soundEmitt2));
                    StartCoroutine(queueWaveState("ToSprint",soundEmitt3));
                }
                else {
                    footStepDelay=footStepDelayINI;
                    StartCoroutine(queueWaveState("ToGround",soundEmitt1));
                    StartCoroutine(queueWaveState("ToGround",soundEmitt2));
                    StartCoroutine(queueWaveState("ToGround",soundEmitt3));
                }
            }
        }
        else {
            if(!firstFalling) {
                //print("BEGIN FALLING");
                StopCoroutine("footStep");
                StopCoroutine("waitB4FootStep");
                blockCoroutine = false;
                footStepDelay=footStepDelayFall;
                firstFalling = true;
                delayB4FallWaves = 0.7f;
                firstGrounded = false;
        //				soundEmitt1.circleGroundedToFall();
        //				soundEmitt2.circleGroundedToFall();
        //				soundEmitt3.circleGroundedToFall();
                StopCoroutine("queueWaveState");
                StartCoroutine(queueWaveState("ToFall",soundEmitt1));
                StartCoroutine(queueWaveState("ToFall",soundEmitt2));
                StartCoroutine(queueWaveState("ToFall",soundEmitt3));
            }
            if(!blockCoroutine && !blockFallWavesCorout && !isGrab) {/*StopCoroutine("waitB4FallWave");*/StartCoroutine("waitB4FallWave");}
        }
        //		print (vectorMove.y);
        //		if(!grounded && !blockCoroutine) {/*footStepDelay=footStepDelayFall;StartCoroutine("waitB4FallWave");*/}
        //		else if (grounded && !blockCoroutine) {
        //			/**/
        //		}
    }
Esempio n. 43
0
 protected virtual void OnPebbleConnected( PebbleConnected pebbleConnected )
 {
     _pebble = pebbleConnected.Pebble;
 }