private void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals("InvalidRequest")) { rootPage.NotifyUser("Invalid request!", NotifyType.ErrorMessage); } //new characteristic value received if (e.PropertyName.Equals("Value")) { // switch (sender) ... Debug.WriteLine($"Lightbulb service received value from : {sender}"); String receivedWrite = BLEServices.Helpers.ToHexString(rootPage.Ble.lightBulbService.LightBulbSwitch.Value); rootPage.NotifyUser("WRITE received: " + receivedWrite, NotifyType.StatusMessage); //check if value is 01, otherwise error? if (receivedWrite.Equals("01")) { LightBulb.On(); if (isSolved == false) { isSolved = true; rootPage.NotifyCorrect(scenarioName); Solved.Visibility = Visibility.Visible; } } else if (receivedWrite.Equals("00")) { LightBulb.Off(); } } }
private async static void ToggleBulb(LightBulb target) { var state = await Client.GetLightStateAsync(target); var isOn = state.Brightness != 0; if (isOn) { await Client.SetColorAsync(target, state.Hue, state.Saturation, 0, 9000, TimeSpan.FromMilliseconds(0)); } else { ushort brightness = 3000; if (LastOnLightState == null) { LastOnLightState = state; } if (LastOnLightState.Brightness != 0) { brightness = LastOnLightState.Brightness; } await Client.SetColorAsync(target, state.Hue, state.Saturation, brightness, LastOnLightState.Kelvin, TimeSpan.FromMilliseconds(0)); } }
private static async Task <string> SetPower(LightBulb bulb, string eventid, string powerState) { var taskTimeOut = GetAppSetting("TaskTimeout", TaskTimeoutDefault); var taskTimeOutInc = GetAppSetting("TaskTimeoutInc", TaskTimeoutIncDefault); var commandSends = GetAppSetting("CommandSends", CommandSendsDef); // bulb.State = await _client.GetLightStateAsync(bulb); if (powerState == "toggle") { powerState = bulb.State.IsOn ? "off" : "on"; } for (var count = 0; count < commandSends; ++count) { var rr = taskTimeOut + (taskTimeOutInc * count); var to = GetTS(rr); Log.Bulb($"{eventid} SetPower {bulb.State.Label} {powerState} Try: {count}/{commandSends} TimeOut: {to}"); var res = await _client.SetDevicePowerStateAsync(bulb, powerState == "on").TimeoutAfter(to).ConfigureAwait(true); if (!res) { continue; } count = commandSends + 10; } Log.Bulb($"{eventid} SetPower {bulb.State.Label} {powerState} Done"); return(powerState); }
private void HandleDeviceStateVersion(LIFXProtocolPacket packet, string hostname) { string id = BitConverter.ToString(packet.FrameAddress.Target); var device = Devices.FirstOrDefault(x => x.MacAddressString == id); if (device != null) { device.Hostname = hostname; } else { if (packet.Frame.Source != _discoverSourceID) { return; } device = new LightBulb() { Hostname = hostname, Service = packet.Payload[0], Port = BitConverter.ToUInt32(packet.Payload, 1), MacAddress = packet.FrameAddress.Target }; Devices.Add(device); } }
private void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals("InvalidRequest")) { rootPage.NotifyUser("Invalid request!", NotifyType.ErrorMessage); } //new characteristic value received if (e.PropertyName.Equals("Value")) { byte[] newColor = rootPage.Ble.lightBulbService.LightBulbColor.argb; rootPage.NotifyUser($"New color received: {newColor[0]} {newColor[1]} {newColor[2]} {newColor[3]}", NotifyType.StatusMessage); //initial check already in the characteristic, assuming [A R G B] here lightBulbBrush.Color = Windows.UI.Color.FromArgb(newColor[0], newColor[1], newColor[2], newColor[3]); LightBulb.ARGB(lightBulbBrush); //check if half dim red (FF0000) received if ((newColor[0] > 110) && (newColor[0] < 150) && (newColor[1] == 255) && (newColor[1] == 255) && (newColor[2] == 0) && (newColor[3] == 0)) { rootPage.NotifyCorrect(scenarioName); Solved.Visibility = Visibility.Visible; } } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { // set up BLE advertising for this scenario var ret = await rootPage.Ble.AdvertisingForScenario(scenarioName); if (ret == true && rootPage.Ble.lightBulbService != null) { rootPage.Ble.lightBulbService.LightBulbSwitch.PropertyChanged += Service_PropertyChanged; } else { Debug.WriteLine("Error, lightbulb service is null!"); rootPage.NotifyUser("Problem starting device simulation", NotifyType.ErrorMessage, NotifyButton.RestartDevice); } if (rootPage.isSolved.ContainsKey(scenarioName)) { if (rootPage.isSolved[scenarioName] == true) { Solved.Visibility = Visibility.Visible; } } // turn on if previously set state var currentValue = BLEServices.Helpers.ToHexString(rootPage.Ble.lightBulbService.LightBulbSwitch.Value); if (currentValue == "01") { LightBulb.On(); } }
// Update is called once per frame void Update() { if (_level >= 3) { LightBulb _lb = FindObjectOfType <LightBulb>(); if (!_lb) { return; } if (_lb.Switched() || _lb.Glitched()) { // Debug.Log(" in update LC, switched = " + _lb.Switched() + " glitched = " + _lb.Glitched()); if (!_scoreAdded) { _totalCoins += (int)((float)_centiCoinsThisLevel / 100.0); tc_text.text = "Total Coins: " + _totalCoins; _scoreAdded = true; if (_lb.Glitched()) { glitch_text.color = Color.white; } } } else { if (_centiCoinsThisLevel > 0) { _centiCoinsThisLevel--; } } cc_text.text = "Current Coins: " + (int)((float)_centiCoinsThisLevel / 100.0); } }
public LightBulb createBulb() // this is the doSomething function { LightBulb bulb = factoryMethod(); bulb.toggleState(); return(bulb); }
public Room() { purifier = new AirPurifier(); bulb = new LightBulb(); plug = new Plug(); sensor = new TemperatureHumiditySensor(); tv = new Tv(); }
public void AddLightBulb_AddLightBulbToLightPoint_ShouldIncreaseNumberOfBulbsInLightPoint() { var lightBulb = new LightBulb(_lightBulbId); _lightPoint.AddLightBulb(lightBulb); Assert.Single(_lightPoint.LightBulbs); }
public void Apply() { LightBulb.SetBrightness(Brightness); if (Brightness == 0) { LightBulb.SwitchOff(); } }
public LifxItem(LifxClient client, LightBulb lightBulb) { this.Client = client; this.LightBulb = lightBulb; this.Limiter = new ApiRateLimiter(TimeSpan.FromMilliseconds(50), this.ApiLimiterCallback, TimeSpan.Zero); this.Update().RunAsync(); }
public static async void SetHue(LightBulb target, ushort newHue) { Debug.Log(target.HostName + ".Hue = " + newHue); var last = LastOnLightState; await Client.SetColorAsync(target, newHue, last.Saturation, last.Brightness, last.Kelvin, TimeSpan.FromTicks(0)); LastOnLightState = (await Client.GetLightStateAsync(target)); }
#pragma warning disable RCS1213 // Remove unused member declaration. private static async Task Test4(string[] args) #pragma warning restore RCS1213 // Remove unused member declaration. { SwitchState desiredState = Enum.Parse <SwitchState>(args[0], true); var bulb = new LightBulb(IPAddress.Parse("192.168.1.7")); //await bulb.FetchAsync(); await bulb.TransitionStateAsync(desiredState).ConfigureAwait(false); }
private void Service_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName.Equals("InvalidRequest")) { rootPage.NotifyUser("Invalid request!", NotifyType.ErrorMessage); } else if (e.PropertyName.Equals("InvalidPin")) { rootPage.NotifyUser("Invalid password, access denied!", NotifyType.ErrorMessage); } // process ARGB Value if (e.PropertyName.Equals("Value")) { byte[] newColor = rootPage.Ble.lightBulbService.LightBulbColor.argb; rootPage.NotifyUser($"New color received: {newColor[0]} {newColor[1]} {newColor[2]} {newColor[3]}", NotifyType.StatusMessage); //initial check already in the characteristic, assuming [A R G B] here lightBulbBrush.Color = Windows.UI.Color.FromArgb(newColor[0], newColor[1], newColor[2], newColor[3]); LightBulb.ARGB(lightBulbBrush); } // password protected special scenario received else if (e.PropertyName.Equals("SpecialValue")) { byte specialEffects = rootPage.Ble.lightBulbService.LightBulbColor.specialEffectsScenario; rootPage.NotifyUser($"Correct PIN, new special effects scenario received: {specialEffects}", NotifyType.StatusMessage); //initial check already in the characteristic, assuming [A R G B] here if (specialEffects == 0x01) { //Green lightBulbBrush.Color = Windows.UI.Color.FromArgb(0xFF, 0x00, 0xFF, 0x00); LightBulb.ARGB(lightBulbBrush); //TextToSpeech.AutoPlay = true; VoiceCongrats.SetSource(speechStream, speechStream.ContentType); VoiceCongrats.Play(); // play Rick after the voice congrats finishes VoiceCongrats.MediaEnded += RickRoll; rootPage.NotifyCorrect(scenarioName); Solved.Visibility = Visibility.Visible; ShowValidPin.Visibility = Visibility.Visible; LightBulb.Checked(true); } else { LightBulb.Off(); LightBulb.Checked(false); Rick.Stop(); Rick.Visibility = Visibility.Collapsed; colorTicker.Stop(); } } }
private void SpawnLightBulb(float lifetime) { lightBulb = new LightBulb(lifetime); if (child.PlayerUnderLight) { playersSanitySystem.IncrementSafeZone(); } SetProximityMessage(); monsterCollider.enabled = true; }
private void InsertLightBulb() { lightBulb = playersInventory.RemoveLightBulb(); if (child.PlayerUnderLight) { playersSanitySystem.IncrementSafeZone(); } SetProximityMessage(); monsterCollider.enabled = true; }
private void RickRoll(object Sender, RoutedEventArgs e) { Rick.Visibility = Visibility.Visible; Rick.Play(); LightBulb.Checked(false); colorTicker = new DispatcherTimer(); colorTicker.Tick += UpdateColor; colorTicker.Interval = new TimeSpan(0, 0, 0, 0, 250); // 4 x per second colorTicker.Start(); }
private void RemoveLightBulb() { if (child.PlayerUnderLight) { playersInventory.AddLightBulb(lightBulb); playersSanitySystem.DecrementSafeZone(); } lightBulb = null; SetProximityMessage(); monsterCollider.enabled = false; }
public LifxBulb(LifxData d, LifxClient c) { _captureMode = DataUtil.GetItem <int>("captureMode"); Data = d ?? throw new ArgumentException("Invalid Data"); _client = c; B = new LightBulb(d.HostName, d.MacAddress, d.Service, (uint)d.Port); _targetSector = d.TargetSector - 1; Brightness = d.Brightness; Id = d.Id; IpAddress = d.IpAddress; }
public void ChangeLightBulb(LightController light, LightBulb newBulb) { audioManager.Play("Light Replace"); GameManager.player.SpendMoney(newBulb.cost); light.SetLightBulb(newBulb); gameManager.AdjustDarkness(); gameManager.CloseLight(); }
private static async Task <int> RunLightOff(string deviceSpec) { var parsedSpec = DeviceSpec.Parse(deviceSpec); var bulb = LightBulb.Create(parsedSpec.IPEndPoint, parsedSpec.MacAddress, service: 1); var client = await LifxClient.CreateAsync(new TraceLogger()); await client.TurnBulbOffAsync(bulb, TimeSpan.FromMilliseconds(0)); return(0); }
public void ChangeBulbStatus_ChangeBulbStatusOfSelectedLightBulb_StatusOfSelectedLightBulbShouldBeTrue() { var lightBulb = new LightBulb(_lightBulbId); _lightPoint.AddLightBulb(lightBulb); Assert.Single(_lightPoint.LightBulbs); _lightPoint.ChangeBulbStatus(_lightBulbId, true); Assert.True(_lightPoint.LightBulbs.First().Status); }
public void BreakLightBulb() { audioSource.clip = breakSound; audioSource.Play(); lightBulb = null; if (child.PlayerUnderLight) { playersSanitySystem.DecrementSafeZone(); } SetProximityMessage(); monsterCollider.enabled = false; }
public void Connect(LightBulb other, bool pipe = true) { if (other != null && !_bulbs.Contains(other)) { _bulbs.Add(other); other.Connect(this, false); if (pipe) { Instantiate(ProtoPipe, (transform.position + other.transform.position) / 2, Quaternion.LookRotation((transform.position - other.transform.position), Vector3.up)); } } }
private static async Task SetColor(LightBulb bulb, string eventID, ushort hue, ushort saturation, ushort brightness, ushort kelvin) { var taskTimeOut = GetAppSetting("TaskTimeout", TaskTimeoutDefault); var taskTimeOutInc = GetAppSetting("TaskTimeoutInc", TaskTimeoutIncDefault); var commandSends = GetAppSetting("CommandSends", CommandSendsDef); // bulb.State = await _client.GetLightStateAsync(bulb); var chue = bulb.State.Hue; var csaturation = bulb.State.Saturation; var cbrightness = bulb.State.Brightness; var ckelvin = bulb.State.Kelvin; if (kelvin == ckelvin && hue == chue && saturation == csaturation && brightness == cbrightness) { return; } if (kelvin < KelvinLow) { kelvin = KelvinLow; } if (kelvin > KelvinHigh) { kelvin = KelvinHigh; } for (var count = 0; count < commandSends; ++count) { // var to = new TimeSpan(taskTimeOut + taskTimeOutInc * commandSends); var rr = taskTimeOut + (taskTimeOutInc * count); var to = GetTS(rr); Log.Bulb($"{eventID} SetColor {bulb.State.Label} Try: {count}/{commandSends} TimeOut: {to}"); var res = await _client.SetColorAsync(bulb, hue, saturation, brightness, kelvin, new TimeSpan(0)).TimeoutAfter(to); if (!res) { continue; } count = commandSends + 10; bulb.State.Hue = hue; bulb.State.Saturation = saturation; bulb.State.Brightness = brightness; bulb.State.Kelvin = kelvin; } Log.Bulb($"{eventID} SetColor {bulb.State.Label} Done"); }
private static async Task <int> RunGetDeviceLabel(string deviceSpec) { var parsedSpec = DeviceSpec.Parse(deviceSpec); // TODO: don't assume it's a bulb var device = LightBulb.Create(parsedSpec.IPEndPoint, parsedSpec.MacAddress, service: 1); var client = await LifxClient.CreateAsync(new TraceLogger()); var result = await client.GetDeviceLabelAsync(device); Console.WriteLine(result); return(0); }
void GenerateLightBulbs() { for (int y = 0; y < numRows; ++y) { for (int x = 0; x < numColumns; ++x) { LightBulb newLight = ((GameObject)Instantiate(Bulbs, topLeft + new Vector3(offset * x, offset * y, 0), Quaternion.identity)).GetComponent <LightBulb>(); newLight.Init(new Vector2(x, y)); Debug.Log(newLight.mPosition); mModels[y, x] = newLight; mBulbStates[y, x] = new Light(); } } }
public LifxData(LightBulb b) { if (b == null) { throw new ArgumentException("Invalid bulb data."); } HostName = b.HostName; IpAddress = IpUtil.GetIpFromHost(HostName).ToString(); Id = b.MacAddressName; Service = b.Service; Port = (int)b.Port; MacAddress = b.MacAddress; MacAddressString = b.MacAddressName; }
public LifxData GetBulbInfo(LightBulb b) { var state = _client.GetLightStateAsync(b).Result; var d = new LifxData(b) { Power = _client.GetLightPowerAsync(b).Result, Hue = state.Hue, Saturation = state.Saturation, Brightness = state.Brightness, Kelvin = state.Kelvin, TargetSector = -1 }; return(d); }
private void Awake() { m_hActor = GetComponent<MadMaxActor>(); m_hRigidbody = GetComponent<Rigidbody>(); m_hLight = GetComponentInChildren<Light>(); m_hBulb = new LightBulb(this); inactive = new StateInactive(this); active = new StateActive(this); explode = new StateExplode(this); inactive.Active = active; active.Inactive = inactive; active.Explode = explode; explode.Inactive = inactive; inactive.OnStateEnter(); currentState = inactive; m_hBulb.Reset(); }