/// <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; } }
static void Main(string[] args) { if (args.Length > 0) { p(args); return; } Pebble pebble; SharpMenu <Action> menu; SharpMenu <Pebble> pebblemenu; Console.WriteLine("Welcome to the Flint test environment. " + "Please remain seated and press enter to autodetect paired Pebbles."); Console.ReadLine(); try { List <Pebble> peblist = Pebble.DetectPebbles(); switch (peblist.Count) { case 0: Console.WriteLine("No Pebbles found. Press enter to exit."); Console.ReadLine(); return; case 1: pebble = peblist[0]; break; default: pebblemenu = new SharpMenu <Pebble>(); foreach (Pebble peb in Pebble.DetectPebbles()) { pebblemenu.Add(peb); } pebblemenu.WriteMenu(); pebble = pebblemenu.Prompt(); break; } } catch (PlatformNotSupportedException e) { Console.WriteLine(e.Message); Console.WriteLine("Press enter to exit."); Console.ReadLine(); return; } try { pebble.Connect(); } catch (System.IO.IOException e) { Console.Write("Connection failed: "); Console.WriteLine(e.Message); Console.WriteLine("Press enter to exit."); Console.ReadLine(); return; } Console.WriteLine("Successfully connected!"); Console.WriteLine(pebble); menu = new SharpMenu <Action>(); menu.Add(() => pebble.Ping(235), "Send the Pebble a ping"); menu.Add(() => pebble.NotificationSMS("+3278051200", "It's time."), "Send an SMS notification"); menu.Add(() => pebble.NotificationMail("Your pal", "URGENT NOTICE", "There is a thing you need to do. Urgently."), "Send an email notification"); menu.Add(() => pebble.SetNowPlaying("That dude", "That record", "That track"), "Send some metadata to the music app"); menu.Add(() => pebble.BadPing(), "Send a bad ping to trigger a LOGS response"); menu.Add(() => Console.WriteLine(pebble.GetTime().Time), "Get the time from the Pebble"); menu.Add(() => SetTime(pebble), "Set Pebble time"); menu.Add(() => Console.WriteLine(pebble.GetAppbankContents().AppBank), "Get the contents of the app bank"); menu.Add(() => DeleteApp(pebble), "Delete an app from the Pebble"); menu.Add(() => AddApp(pebble), "Add an app"); menu.Add(() => AddApp(pebble, null, true), "Reinstall an app"); menu.Add(() => pebble.Disconnect(), "Exit"); pebble.OnDisconnect += pebble_OnDisconnect; pebble.MessageReceived += pebble_MessageReceived; // Subscribe to specific events pebble.LogReceived += pebble_LogReceived; pebble.PingReceived += pebble_PingReceived; pebble.MediaControlReceived += pebble_MediaControlReceived; // Subscribe to an event for a particular endpoint pebble.RegisterEndpointCallback(Pebble.Endpoints.PING, pingReceived); pebble.GetVersion(); Console.WriteLine(pebble.Firmware); Console.WriteLine(pebble.RecoveryFirmware); while (pebble.Alive) { menu.WriteMenu(); Action act = menu.Prompt(); // To account for disconnects during the prompt: if (pebble.Alive) { act(); } } }