Пример #1
0
        /// <summary>
        /// Connect to a MoveHub at specified MAC address
        /// </summary>
        /// <param name="address">The MAC address</param>
        /// <param name="timeout">The scan will stop after the period</param>
        /// <returns>MoveHub instance if the device is successfully found and connected</returns>
        public new static async Task <MoveHub?> Connect(string address, TimeSpan?timeout = null)
        {
            var device = await ScanAndConnectInternal(new ScanFilter(address), timeout);

            if (device == null)
            {
                return(null);
            }
            var ret = new MoveHub(device);
            await ret.Initialize();

            return(ret);
        }
Пример #2
0
        /// <summary>
        /// Scan and connect to a MoveHub
        /// </summary>
        /// <param name="timeout">The scan will stop after the period</param>
        /// <returns>MoveHub instance if the device is successfully found and connected</returns>
        public static async Task <MoveHub?> ScanAndConnect(TimeSpan?timeout = null)
        {
            var device = await ScanAndConnectInternal(new ScanFilter(name : "LEGO Move Hub"), timeout);

            if (device == null)
            {
                return(null);
            }
            var ret = new MoveHub(device);
            await ret.Initialize();

            return(ret);
        }
Пример #3
0
        private static async Task <LPF2Hub?> CreateHubInstance(IDevice1 dev)
        {
            var data = await dev.GetManufacturerDataAsync();

            if (!data.ContainsKey(0x0397))
            {
                // Not a LEGO product
                return(null);
            }

            var     typeId = ((byte[])data[0x0397])[1];
            LPF2Hub?ret    = null;

            switch (typeId)
            {
            case 32:     // Duplo Train Base
                // TODO:
                break;

            case 64:     // LEGO Boost MoveHub
                ret = new MoveHub(dev);
                break;

            case 65:     // Powered Up Hub
                // TODO:
                break;

            case 66:     // Remote Controller
                // TODO:
                break;

            case 128:     // Technic Medium Hub
                ret = new TechnicMediumHub(dev);
                break;
            }

            if (ret == null)
            {
                // Unknown LEGO Hub
                return(null);
            }

            await ret.Initialize();

            return(ret);
        }