Ejemplo n.º 1
0
        /// <inheritdoc />
        public void Initialize(PluginConfiguration configuration, Action <Action <ISystemController, IRaceController> > queueCommand)
        {
            _components = new List <IPluginComponent>();

            //scan for pebbles, we rely on MrGibbs.Configuration.BluetoothModule to have done discovery
            var pebbles = _manager.Detect(_btAdapterName, false, true, true);

            _logger.Info("Found " + pebbles.Count + " Pebbles");

            if (pebbles.Any())
            {
                if (!string.IsNullOrEmpty(_pbwPath) && File.Exists(_pbwPath))
                {
                    using (var stream = new FileStream(_pbwPath, FileMode.Open))
                    {
                        using (var zip = new Zip())
                        {
                            zip.Open(stream);
                            foreach (var pebble in pebbles)
                            {
                                stream.Position = 0;
                                InitializeViewer(pebble, zip, queueCommand, configuration);
                            }
                        }
                    }
                }
                else
                {
                    throw new FileNotFoundException("Could not find " + _pbwPath);
                }
            }



            if (!_components.Any())
            {
                _initialized = false;
                if (pebbles.Any())
                {
                    throw new Exception("Failed to connect to any Pebbles");
                }
                else
                {
                    throw new Exception("No Pebbles found");
                }
            }
            else
            {
                _initialized = true;
            }
        }
Ejemplo n.º 2
0
        //static void Main()
        //{
        //ShowPebbles().Wait();
        //}

        //private static async Task ShowPebbles()
        static void Main()
        {
            try
            {
                var manager = new PebbleManager();
                Console.WriteLine("PebbleCmd");
                Console.WriteLine("Discovering and Pairing Pebbles");
                var pebbles = manager.Detect("hci1", true, true, true);
                Console.WriteLine("Select Pebble to connect to:");
                if (pebbles != null && pebbles.Any())
                {
                    int result = 0;

                    if (pebbles.Count > 1)
                    {
                        var options = pebbles.Select(x => x.PebbleID).Union(new[] { "Exit" });
                        var menu    = new Menu(options.ToArray());
                        result = menu.ShowMenu();
                    }

                    if (result >= 0 && result < pebbles.Count)
                    {
                        var selectedPebble = pebbles[result];
                        Console.WriteLine("Connecting to " + selectedPebble.PebbleID);
                        selectedPebble.ConnectAsync().Wait();
                        ShowPebbleMenu(selectedPebble).Wait();
                    }
                }
                else
                {
                    Console.WriteLine("No Pebbles Detected");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " " + ex.StackTrace);
                throw;
            }
        }