Beispiel #1
0
        private async void runController()
        {
            while (!isDisposed && Auth_token == null)
            {
                await Task.Delay(1000);
            }

            UpdateInfos(await Communication.GetAllPanelInfo(IP, PORT, Auth_token));
            externalControlInfo = await Communication.SetExternalControlStreaming(IP, PORT, Auth_token, DeviceType);

            Communication.StaticOnLayoutEvent += Communication_StaticOnLayoutEvent;
            Communication.StartEventListener(IP, PORT, Auth_token);
            while (!isDisposed)
            {
                try
                {
                    UpdateInfos(await Communication.GetAllPanelInfo(IP, PORT, Auth_token));
                    await Task.Delay(5000);
                }
                catch (Exception e)
                {
                    NanoleafPlugin.Log.ErrorOrDebug(string.Empty, e);
                }
            }
        }
        public static async Task <ExternalControlConnectionInfo> SetExternalControlStreaming(string ip, string port, string auth_token, EDeviceType deviceType)
        {
            ExternalControlConnectionInfo result = null;
            string address       = $"http://{ip}:{port}/api/v1/{auth_token}/effects";
            string contentString = "{\"write\": {\"command\": \"display\", \"animType\": \"extControl\", \"extControlVersion\": \"v2\"}}";

            var response = await put(address, contentString);

            switch (deviceType)
            {
            case EDeviceType.LightPanles:
                result = JsonConvert.DeserializeObject <ExternalControlConnectionInfo>(response.Content);
                break;

            case EDeviceType.Shapes:
            case EDeviceType.Canvas:
            case EDeviceType.Elements:
            case EDeviceType.Lines:
            case EDeviceType.Essentials:
            default:
                result = new ExternalControlConnectionInfo()
                {
                    StreamIPAddress = ip, StreamPort = 60222, StreamProtocol = "udp"
                };
                break;
            }
            return(result);
        }
        public static void SendUDPCommand(ExternalControlConnectionInfo _externalControlConnectionInfo, params byte[] data)
        {
            if (_externalControlConnectionInfo == null)
            {
                return;
            }
            var socket   = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            var endpoint = new IPEndPoint(IPAddress.Parse(_externalControlConnectionInfo.StreamIPAddress), _externalControlConnectionInfo.StreamPort);

            socket.SendTo(data, endpoint);
            socket.Close();
        }