private static void UpdateGroupName(LifxNetwork network, BulbGroup group, IBulb bulb) { var command = (SetTagLabels)PacketFactory.GetCommand(CommandType.SetTagLabels); command.Init(group.Bitmask, Encoding.UTF8.GetBytes(group.Name)); network.SendCommand(bulb, command); }
/// <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); }
private static void SetGroups(LifxNetwork network, IBulb bulb, IEnumerable <BulbGroup> groups) { var command = (SetTags)PacketFactory.GetCommand(CommandType.SetTags); command.Init(GetBitmask(groups)); network.SendCommand(bulb, command); }
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); }
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; }
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)); }
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; }
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)); }
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; }
/// <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); }
private void HandleBulbGroupsPacket(IBulb bulb, AnswerPacketBase packet) { var lightStatus = packet as LightStatus; var tags = packet as Tags; if (tags != null || lightStatus != null) { var bitmask = lightStatus != null ? lightStatus.Bitmask : tags.Bitmask; var groupBitmasks = bitmask.GetGroupTags().ToList(); foreach (var groupBitmask in groupBitmasks) { BulbGroup group; if (!_groups.TryGetValue(groupBitmask, out group)) { lock (_groupCollectionLock) { if (!_groups.TryGetValue(groupBitmask, out group)) { group = CreateGroup(groupBitmask); } } } group.Add(bulb); if (string.IsNullOrEmpty(group.Name)) { var getTagLabels = (GetTagLabels)PacketFactory.GetCommand(CommandType.GetTagLabels); getTagLabels.Init(groupBitmask); SendCommand(bulb, getTagLabels); } } } }
/// <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); }