Example #1
0
 public override bool UpdateValue(object newValue)
 {
     Panel.RGBW rgbw = new Panel.RGBW();
     if (newValue is Color)
     {
         var color = (Color)newValue;
         rgbw = new Panel.RGBW(color.R, color.G, color.B);
     }
     else if (newValue is LumosColor)
     {
         var lumosColor = (LumosColor)newValue;
         rgbw = new Panel.RGBW((byte)(lumosColor.Red * 255), (byte)(lumosColor.Green * 255), (byte)(lumosColor.Blue * 255));
     }
     else if (newValue is Panel.RGBW)
     {
         rgbw = (Panel.RGBW)newValue;
     }
     else
     {
         return(false);
     }
     try
     {
         var Controler = NanoleafPlugin.getClient(SerialNumber);
         return(Controler.SetPanelColor(Panel.ID, rgbw));
     }
     catch (Exception e)
     {
         NanoleafPlugin.Log.Error(string.Empty, e);
     }
     return(false);
 }
Example #2
0
        public async Task TestStreaming()
        {
            await Task.Delay(500);

            var info = await Communication.GetPanelLayoutLayout(IP, PORT, AUTH_TOKEN);

            var externalControlInfo = await Communication.SetExternalControlStreaming(IP, PORT, AUTH_TOKEN, EDeviceType.Canvas);

            List <Panel> panels = new List <Panel>();
            var          ids    = info.PanelPositions.Select(p => p.PanelId);

            foreach (int id in ids)
            {
                var pp = info.PanelPositions.Single(p => p.PanelId.Equals(id));
                panels.Add(new Panel(IP, pp));
            }

            var  rgbw = new Panel.RGBW(0, 0, 0, 0);
            byte val  = 0;

            do
            {
                rgbw = new Panel.RGBW(val, 0, 0, 0);
                panels.ForEach(p => p.StreamingColor = rgbw);
                Communication.SendUDPCommand(externalControlInfo, Communication.CreateStreamingData(panels));
                if (val % 2 == 0)
                {
                    Task.Delay(1).Wait();
                }
                val++;
            }while (val != 0);

            do
            {
                rgbw = new Panel.RGBW(255, val, val, 0);
                var controlPanel = panels.Where(p => p.Shape == PanelPosition.EShapeType.ControlSquarePrimary).ToList();
                controlPanel.ForEach(p => p.StreamingColor = rgbw);
                Communication.SendUDPCommand(externalControlInfo, Communication.CreateStreamingData(controlPanel));
                if (val % 2 == 0)
                {
                    Task.Delay(1).Wait();
                }
                val++;
            }while (val != 0);
            do
            {
                panels.ForEach(p => p.StreamingColor = new Panel.RGBW((byte)(p.StreamingColor.R - 1), (byte)(p.StreamingColor.G - 1), (byte)(p.StreamingColor.B - 1), 0));
                Communication.SendUDPCommand(externalControlInfo, Communication.CreateStreamingData(panels));
                if (val % 2 == 0)
                {
                    Task.Delay(1).Wait();
                }
                val++;
            }while (panels.First().StreamingColor.R != 0);

            rgbw = new Panel.RGBW(0, 0, 0, 0);
            panels.ForEach(p => p.StreamingColor = rgbw);
            Communication.SendUDPCommand(externalControlInfo, Communication.CreateStreamingData(panels));
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Press Enter 5 times for Shutdown");
            Communication.StartEventListener();
            Communication.DeviceDiscovered     += Communication_DeviceDiscovered;
            Communication.StaticOnTouchEvent   += Communication_StaticOnTouchEvent;
            Communication.StaticOnLayoutEvent  += Communication_StaticOnLayoutEvent;
            Communication.StaticOnGestureEvent += Communication_StaticOnGestureEvent;
            Communication.StaticOnEffectEvent  += Communication_StaticOnEffectEvent;
            Communication.StaticOnStateEvent   += Communication_StaticOnStateEvent;
            controller = new Controller(ip, AUTH_TOKEN);
            bool   alive      = true;
            Thread taskStream = new Thread(() =>
            {
                byte val = 0;
                while (alive)
                {
                    var rgbw = new Panel.RGBW(val, 0, 0, 0);
                    foreach (var p in controller.Panels.ToArray())
                    {
                        p.StreamingColor = rgbw;
                    }
                    Task.Delay(1).Wait();
                    val++;
                }
            });

            taskStream.Start();


            Console.ReadLine();
            controller.SelfDestruction(true);
            Console.WriteLine("User Deleted");
            alive = false;

            Console.ReadLine();
        }