コード例 #1
0
        /// <summary>
        /// Get all access points of a specific gateway bulb.
        /// </summary>
        public static void ScanAccessPoints(this ILifxNetwork network, string ipAddress)
        {
            var command = PacketFactory.GetCommand(CommandType.GetAccessPoints);
            var gateway = new Gateway(new byte[6], ipAddress);

            ((LifxNetwork)network).SendCommand(gateway, command);
        }
コード例 #2
0
        public static IBulbGroup AddGroup(this ILifxNetwork network, string name)
        {
            var n     = (LifxNetwork)network;
            var group = n.CreateGroup();

            group.Name = name;
            return(group);
        }
コード例 #3
0
        private static void SetPowerState(ILifxNetwork network, IBulb bulb, bool isPowerOn)
        {
            var command = (SetPowerState)PacketFactory.GetCommand(CommandType.SetPowerState);

            command.Init(isPowerOn);

            ((LifxNetwork)network).SendCommand(bulb, command);

            ((Bulb)bulb).IsPowerOn = isPowerOn;
        }
コード例 #4
0
        private static void Waveform(this ILifxNetwork network, IBulb bulb, IColor color, double cycleDurationInSeconds, float cycles, WaveformType waveform)
        {
            var command = (SetWaveForm)PacketFactory.GetCommand(CommandType.SetWaveform);
            var c       = color.ToHsv();
            var period  = (uint)cycleDurationInSeconds * 1000;

            command.Init((ushort)c.Hue, (ushort)(c.Saturation * 100), (ushort)(c.Brightness * 255), (ushort)c.Kelvin, period, cycles, 0, waveform);

            ((LifxNetwork)network).SendCommand(bulb, command);
        }
コード例 #5
0
 public static void ReadBulbInfo(this ILifxNetwork network, IBulb bulb)
 {
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetInfo));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetMeshFirmware));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetMeshInfo));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetTime));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetVersion));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetWifiFirmwareState));
     ((LifxNetwork)network).SendCommand(bulb, PacketFactory.GetCommand(CommandType.GetWifiInfo));
 }
コード例 #6
0
        public static void RenameBulb(this ILifxNetwork network, IBulb bulb, string name)
        {
            var command = (SetBulbLabel)PacketFactory.GetCommand(CommandType.SetBulbLabel);

            command.Init(name);

            ((LifxNetwork)network).SendCommand(bulb, command);

            ((Bulb)bulb).Name = name;
        }
コード例 #7
0
        public static void RemoveBulbFromGroup(this ILifxNetwork network, IBulbGroup bulbGroup, IBulb bulb)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            group.Remove(bulb);

            var groups = n.Groups.Where(g => g.Contains(bulb)).ToList();

            SetGroups(n, bulb, groups);
        }
コード例 #8
0
        public static void ChangeColor(this ILifxNetwork network, IBulb bulb, IColor color, double fadeTimeInSeconds)
        {
            var command = (SetLightColor)PacketFactory.GetCommand(CommandType.SetLightColor);
            var c       = color.ToHsv();

            command.Init((ushort)c.Hue, (ushort)(c.Saturation * 100), (ushort)(c.Brightness * 255), (ushort)color.Kelvin, (uint)(fadeTimeInSeconds * 1000));

            ((LifxNetwork)network).SendCommand(bulb, command);

            ((Bulb)bulb).Color = c;
        }
コード例 #9
0
        public static void SetAccessPoint(this ILifxNetwork network, IGateway gateway, IAccessPoint accessPoint, string password)
        {
            var n       = (LifxNetwork)network;
            var command = (SetAccessPoint)PacketFactory.GetCommand(CommandType.SetAccessPoint);
            var ap      = (AccessPoint)accessPoint;

            command.Init(ap.Packet, password);

            n.SendCommand(gateway, command);
            n.SendCommand(gateway, PacketFactory.GetCommand(CommandType.GetWifiState));
        }
コード例 #10
0
        public static void RenameGroup(this ILifxNetwork network, IBulbGroup bulbGroup, string name)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            group.Name = name;

            foreach (var bulb in group.GetBulbs())
            {
                UpdateGroupName(n, group, bulb);
            }
        }
コード例 #11
0
        /// <summary>
        /// Search for gateways. If a new gateway is found, it will be scanned for new bulbs.
        /// </summary>
        public static void ScanNetwork(this ILifxNetwork network, string ipAddress)
        {
            var gateways = GatewayService.Get();

            foreach (var g in gateways)
            {
                ScanGateway(network, g);
            }

            var command = PacketFactory.GetCommand(CommandType.GetPanGateway);
            var gateway = new Gateway(new byte[6], ipAddress);

            ((LifxNetwork)network).SendCommand(gateway, command);
        }
コード例 #12
0
        public static void RemoveGroup(this ILifxNetwork network, IBulbGroup bulbGroup)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            n.Remove(group);

            var allGroups = n.Groups.ToList();

            foreach (var bulb in group.GetBulbs())
            {
                var groups = allGroups.Where(g => g.Contains(bulb) && !Equals(g, group)).ToList();
                SetGroups(n, bulb, groups);
            }
        }
コード例 #13
0
        public static void AddBulbToGroup(this ILifxNetwork network, IBulbGroup bulbGroup, IBulb bulb)
        {
            var n     = (LifxNetwork)network;
            var group = (BulbGroup)bulbGroup;

            if (group.Contains(bulb))
            {
                return;
            }

            group.Add(bulb);

            var groups = n.Groups.Where(g => g.Contains(bulb)).ToList();

            SetGroups(n, bulb, groups);

            UpdateGroupName(n, group, bulb);
        }
コード例 #14
0
 public static void SwitchOn(this ILifxNetwork network, IBulb bulb)
 {
     SetPowerState(network, bulb, true);
 }
コード例 #15
0
        /// <summary>
        /// Search for bulbs within the mesh network of the given gateway.
        /// </summary>
        public static void ScanGateway(this ILifxNetwork network, IGateway gateway)
        {
            var command = PacketFactory.GetCommand(CommandType.GetLightState);

            ((LifxNetwork)network).SendCommand(gateway, command);
        }
コード例 #16
0
 public static void Pulse(this ILifxNetwork network, IBulb bulb, IColor color, double cycleDurationInSeconds, float cycles)
 {
     network.Waveform(bulb, color, cycleDurationInSeconds, cycles, WaveformType.Pulse);
 }
コード例 #17
0
 public static void SwitchOff(this ILifxNetwork network, IBulb bulb)
 {
     SetPowerState(network, bulb, false);
 }