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); } }
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); }
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); } }
static void Main(string[] args) { 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(() => pebble.SetTime(DateTime.Now), "Sync 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(() => 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(); } }
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(); } } }