/// <summary> /// Sets the power state of the provided IPowerState given that the /// specified BTCmd will be executed next. A null BTCmd indicates that /// there are no more pending BTCmds to be executed from any connection. /// </summary> /// <param name="ips"> /// The IPowerState /// </param> /// <param name="conn"> /// The BTConnection for which the BTCmd is being executed. /// </param> /// <param name="cmd"> /// The next BTCmd to be executed, or null if there are no pending BTCmds. /// </param> public void ApplyPolicy(IPowerState ips, BTConnection conn, BTConnection.BTCmd cmd) { lock (this) { if (null != cmd) { // Dispose of the Timer if it's active, then PARK the chip if (null != m_powerOffTimer) { m_powerOffTimer.Dispose(); m_powerOffTimer = null; } PowerState state = PowerState.Park; while (!ips.SetPowerState(ref state)) { Thread.Sleep(1); } } else { // Then set a Timer that will turn the chip OFF if no new commands in the specified timeout if (null == conn || !conn.Connected) { if (null == m_powerOffTimer) { m_powerOffTimer = new Timer(PowerOffTimerFired, ips, c_powerOffTimeout, Timeout.Infinite); } } } } }
public MainViewModel(IApp app, IPowerState power, INetwork network, IDevice device) { this.App = app; this.Device = device; this.Network = network; this.Power = power; this.ClearApp = new Command(this.AppEvents.Clear); this.ClearPower = new Command(this.BatteryEvents.Clear); this.ClearNetwork = new Command(this.NetworkEvents.Clear); this.ToggleIdleTimer = new Command(() => { this.App.EnableIdleTimer(!this.App.IsIdleTimerEnabled).Subscribe(); this.Raise(nameof(this.IdleTimerText)); }); }
public MetaFactory(IPowerState powerState, ContentManager manager) { //this might not work fyi. consider using pState.GetType() == typeof(SmallState) // as a possible fix. powerUpstate should only be null during avatar initialization if (powerState is SmallState || powerState is null) { localFactory = new SmallMarioFactory(manager); } else if (powerState is SuperState) { localFactory = new SuperMarioFactory(manager); } else if (powerState is FireState) { localFactory = new FireMarioFactory(manager); } }
/// <summary> /// The event handler for the power off Timer firing event. /// </summary> /// <param name="sender"> /// The sending object (i.e. the Timer). /// </param> /// <param name="eargs"> /// The event arguments. /// </param> public void PowerOffTimerFired(object state) { IPowerState ips = (IPowerState)state; lock (this) { if (null != m_powerOffTimer) { m_powerOffTimer.Dispose(); m_powerOffTimer = null; PowerState ps = PowerState.Off; while (!ips.SetPowerState(ref ps)) { Thread.Sleep(1); } } } }
public PlayerContext(int sWidth, int sHeight, Vector2 loc) { //Instantiate power states loc.Y += MarioSpriteFactory.BIG_MARIO_HEIGHT - MarioSpriteFactory.SMALL_MARIO_HEIGHT; Location = loc; fireMario = new FireMario(this); smallMario = new SmallMario(this); superMario = new SuperMario(this); deadMario = new DeadMario(this); //Instantiate action states idleMario = new IdleMario(this); runningMario = new RunningMario(this); jumpingMario = new JumpingMario(this); fallingMario = new FallingMario(this); crouchingMario = new CrouchingMario(this); screenWidth = sWidth; screenHeight = sHeight; //Set initial states PowerState = smallMario; ActionState = idleMario; currentState = MarioState.Small; currentFrame = MarioFrame.Idle; WidthHeight = new Vector2(MarioSpriteFactory.SMALL_MARIO_WIDTH, MarioSpriteFactory.SMALL_MARIO_HEIGHT); Mario = new MarioSprite(Location, sWidth, sHeight, MarioState.Small, MarioColor.Red, MarioFrame.Idle, facingLeft, IsBounded); playerRect = new Rectangle((int)Location.X, (int)Location.Y, MarioSpriteFactory.SMALL_MARIO_WIDTH, MarioSpriteFactory.SMALL_MARIO_HEIGHT); EntityType = TileMapInterpreter.Entities.PLAYER; Velocity = new Vector2(horizontalMovementFactor, verticalMovementFactor); }
public static Task <PowerStatus> ReadPowerStatus(this IPowerState power) => power .WhenPowerStatusChanged() .Take(1) .ToTask();
public static Task <int> ReadPercentage(this IPowerState power) => power .WhenBatteryPercentageChanged() .Take(1) .ToTask();
public StarMario(PlayerContext context, IPowerState returnState) { this.context = context; this.context.returnState = returnState; this.context.timer.Start(); }