コード例 #1
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;
                }
            }
        }
コード例 #2
0
ファイル: Flintlock.cs プロジェクト: R1chChapp3rs/flintlock
 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;
     }
 }
コード例 #3
0
        private async void OnToggleConnect( )
        {
            if (IsConnected)
            {
                _pebble.Disconnect();
                MessengerInstance.Send(new PebbleDisconnected(_pebble));
            }
            else
            {
                await _pebble.ConnectAsync();

                MessengerInstance.Send(new PebbleConnected(_pebble));
            }
            IsConnected = !IsConnected;
        }
コード例 #4
0
        private static async Task ShowPebbleMenu(Pebble pebble)
        {
            //string uuid = "22a27b9a-0b07-47af-ad87-b2c29305bab6";

            var menu = new Menu(
                "Disconnect",
                "Get Time",
                "Set Current Time",
                "Get Firmware Info",
                "Send Ping",
                "Media Commands",
                "Install App",
                "Send App Message",
                "Reset",
                "Send Notification");

            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:
                    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.GetPlatform());
                                var   task = pebble.InstallClient.InstallAppAsync(bundle, progress);
                                await task;
                                if (task.IsFaulted)
                                {
                                    Console.WriteLine("Failed to install");
                                }

                                //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");
                    }
                    break;

                case 7:
                    //read the uuid from the pbw

                    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.GetPlatform());


                                //format a message
                                var rand = new Random().Next();
                                AppMessagePacket message = new AppMessagePacket();
                                message.Values.Add(new AppMessageUInt32()
                                {
                                    Value = (uint)rand
                                });
                                message.Values.Add(new AppMessageString()
                                {
                                    Value = "Hello from .net"
                                });
                                message.ApplicationId = bundle.AppMetadata.UUID;
                                message.TransactionId = 255;


                                //send it
                                Console.WriteLine("Sending Status " + rand + " to " + bundle.AppMetadata.UUID.ToString());
                                var   t = pebble.SendApplicationMessage(message);
                                await t;
                                Console.WriteLine("Response received");
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine("No .pbw");
                    }
                    break;

                case 8:
                    pebble.Reset(ResetCommand.Reset);
                    break;

                case 9:
                    TestNotification(pebble);
                    break;
                }
            }
        }
コード例 #5
0
 public static void Cleanup()
 {
     _Pebble.Disconnect();
 }