Exemplo n.º 1
0
        private void NanoleafDiscovered(object?sender, ServiceInstanceDiscoveryEventArgs e)
        {
            var name  = e.ServiceInstanceName.ToString();
            var nData = new NanoleafData {
                IpAddress = string.Empty
            };

            if (!name.Contains("nanoleafapi", StringComparison.InvariantCulture))
            {
                return;
            }

            var devName = name.Split(".")[0];

            devName    = devName[Math.Max(0, devName.Length - 3)..];
Exemplo n.º 2
0
        /// <summary>
        ///     Use this for sending color data to the panel
        /// </summary>
        /// <param name="n"></param>
        /// <param name="cs"></param>
        public NanoleafDevice(NanoleafData n, ColorService cs) : base(cs)
        {
            _brightness = -1;
            _targets    = new Dictionary <int, int>();
            _data       = n;
            Id          = _data.Id;
            var streamMode     = n.Type is "NL29" or "NL42" ? 2 : 1;
            var controlService = cs.ControlService;
            var host           = n.IpAddress;

            try {
                var ip = IpUtil.GetIpFromHost(n.IpAddress);
                if (ip != null)
                {
                    host = ip.ToString();
                }
                else
                {
                    if (host.Contains(".local"))
                    {
                        host = host.Replace(".local", "");
                        ip   = IpUtil.GetIpFromHost(host);
                    }
                }

                if (ip != null)
                {
                    host = ip.ToString();
                }
            } catch (Exception) {
                //ignored
            }

            try {
                Log.Debug("Creating nano client: " + host);
                _nanoleafClient = new NanoleafClient(host, n.Token);
                Log.Debug("Nano client created.");
                _streamingClient = new NanoleafStreamingClient(host, streamMode, controlService.UdpClient);
            } catch (Exception e) {
                Log.Debug("Exception creating client..." + e.Message);
            }

            _frameWatch = new Stopwatch();
            SetData();
            controlService.RefreshSystemEvent += SetData;
            _disposed = false;
            cs.ColorSendEventAsync += SetColors;
        }