示例#1
0
        // simulation
        public async Task <bool> SetBulbTemperature(Guid bulbId, double temperature)
        {
            // get bulb
            BulbState bulb = await _dataService.GetBulbState(bulbId);

            bulb.BulbCurrentState.BulbTemperature = temperature;
            if (bulb.BulbCurrentState.IsOn)
            {
                // check over temperature
                if (!CanSwitchBulbOn(bulb))
                {
                    // fault condition!
                    await Task.WhenAll(_lightDriver.SwitchOffBulb(bulbId)
                                       , _dataService.UpdateBulbStatus(bulb, false, FaultCode.OverTemperature, bulb.BulbCurrentState));

                    return(false);
                }
            }

            // the bulb is off or not over temperature - no worries - log the data
            bulb.BulbCurrentState.BulbTemperature = temperature;

            await _dataService.UpdateBulbStatus(bulb, false, null, bulb.BulbCurrentState); // fire-forget

            return(false);
        }
示例#2
0
 private bool CanSwitchBulbOn(BulbState bulbState)
 {
     if (bulbState.BulbCurrentState.BulbTemperature > bulbState.BulbInformation.MaxTemperature)
     {
         return(false);
     }
     return(true);
 }
        private Task <BulbState> GetTask(BulbState bulbState)
        {
            var task = new Task <BulbState>(() =>
            {
                return(bulbState);
            });

            task.Start();
            return(task);
        }
示例#4
0
 public void PressSwitch()
 {
     if (currentBulbState == BulbState.Off)
     {
         currentBulbState = BulbState.On;
     }
     else if (currentBulbState == BulbState.On)
     {
         currentBulbState = BulbState.Off;
     }
 }
 private bool CanSwitchBulbOn(BulbState bulbState)
 {
     if (bulbState.BulbCurrentState.FaultCondition.HasValue && bulbState.BulbCurrentState.FaultCondition.Value != FaultCode.None)
     {
         return(false);
     }
     if (bulbState.BulbCurrentState.BulbTemperature > bulbState.BulbInformation.MaxTemperature)
     {
         return(false);
     }
     return(true);
 }
        public async Task <bool> SetFault(Guid bulbId, FaultCode fault)
        {
            // get bulb
            BulbState bulb = await _dataService.GetBulbState(bulbId);

            if (fault == FaultCode.None && bulb.BulbCurrentState.BulbTemperature > bulb.BulbInformation.MaxTemperature)
            {
                // for repair, we need to reset bulb temperature if it exceeds the max temperature
                bulb.BulbCurrentState.BulbTemperature = 0;
            }
            await _dataService.UpdateBulbStatus(bulb, fault == FaultCode.None?bulb.BulbCurrentState.IsOn : false, fault, bulb.BulbCurrentState);

            return(true);
        }
示例#7
0
    public override void Interact(PlayerController player)
    {
        // Take bulb sprite from player and place on me
        Transform bulb = player.heldItem.transform;

        bulb.parent        = transform;
        bulb.localPosition = new Vector2(0, -0.56f);
        SpriteRenderer sprite = bulb.gameObject.GetComponent <SpriteRenderer>();

        sprite.sortingLayerName = "Background Item";

        // Remove glow effect so we won't wait for the player to exit the collider
        glow.SetActive(false);

        // Remove the bulb from the player's logic and add to mine
        player.heldItem = null;
        bulbState       = BulbState.Active;

        // Make the generator update changes. Should probably be some kind of event
        generator.updateDistribution();

        // Set text - Not necessary since updateDistribution does this
        //UpdateText();
    }
示例#8
0
 public void PressSwitch()
 {
     BulbState = BulbState == BulbState.On ? BulbState.Off : BulbState.On;
 }