Exemple #1
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;
            }
        }
Exemple #2
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;
                }
            }
        }
        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;
                }
            }
        }
        public async Task CanGetCurrentTime()
        {
            TimeResponse response = await _Pebble.GetTimeAsync();

            AssertSuccessfulResult(response);
        }