public BaseEvent ProcessEvent(uint data1, uint data2, DateTime time) { EventCategory ec = (EventCategory)(0xFF & (data1 >> 8)); BaseEvent be = null; if (ec == EventCategory.SleepLevel) { SleepEvent ev = new SleepEvent(); ev.EventType = (SleepEventType)(data1 & 0xFF); // data1 encodes the type in the lower 16 bits and... ev.Level = SleepLevel.Awake; ev.WakeUpEvents = (HardwareEvent)data2; ev.Time = time; be = ev; } else if (ec == EventCategory.PowerLevel) { PowerEvent ev = new PowerEvent(); ev.EventType = PowerEventType.PostNotify; ev.Level = (PowerLevel)data2; ev.Time = time; be = ev; } return(be); }
/// <summary> /// The Sleep method puts the device into a sleeps state that is only woken by the events described in the paramter wakeUpEvents. /// Please note that if the event SystemTimer is not used, the system will not be woken up by any managed timers. In addition, /// other threads will not be executed until this sleep call exits. This method raises the OnSleepChange event. /// /// The MaximumTimeToActive property contains the timeout value for this call. /// </summary> /// <param name="level">Determines what level of sleep the system should enter. The behavior of the level is determined /// by the hardware vendor.</param> /// <param name="wakeUpEvents">Determines the events that will cause the system to exit the given sleep level</param> public static void Sleep(SleepLevel level, HardwareEvent wakeUpEvents) { SleepChangeEventHandler h = OnSleepChange; if (h != null) { SleepEvent e = new SleepEvent(); e.EventType = SleepEventType.ChangeRequested; e.Level = level; e.WakeUpEvents = wakeUpEvents; e.Time = DateTime.UtcNow; h(e); } InternalSleep(level, wakeUpEvents); }
//--// void SleepChange(SleepEvent ev) { if (ev.EventType == SleepEventType.ChangeRequested) { _change.Set(); _changeEvent = ev; } else if (ev.EventType == SleepEventType.WakeUp) { _wakeup.Set(); _wakeupEvent = ev; } else { Debug.Assert( false ); } }
public MFTestResults Sleep_3_NoSystemTimerTest() { bool result = true; TimeSpan backup = PowerState.MaximumTimeToActive; try { PowerState.MaximumTimeToActive = new TimeSpan(0,0,0,2); TimeSpan tsTimeout = PowerState.MaximumTimeToActive; PowerState.OnSleepChange += new SleepChangeEventHandler(this.SleepChange); HardwareEvent newEvents = HardwareEvent.OEMReserved1; _timerFired.Reset(); _wakeupEvent = null; Timer t = new Timer(new TimerCallback(this.TimerCallback), null, tsTimeout.Milliseconds / 2, Timeout.Infinite); DateTime dtStart = DateTime.Now; // this will wake up with the max time allowed PowerState.Sleep(SleepLevel.Sleep, newEvents); /// /// When the debugging is enbled on a device the debug port is selected as a wakeup event by default, /// so we ignore this test if we get any events. /// if (_timerFired.WaitOne(1000, false) && (_wakeupEvent == null || _wakeupEvent.WakeUpEvents == 0)) { result = (_timerTime - dtStart) > tsTimeout; } PowerState.OnSleepChange -= new SleepChangeEventHandler(this.SleepChange); } finally { PowerState.MaximumTimeToActive = backup; } return result ? MFTestResults.Pass : MFTestResults.Fail; }
public BaseEvent ProcessEvent(uint data1, uint data2, DateTime time) { EventCategory ec = (EventCategory)(0xFF & (data1 >> 8)); BaseEvent be = null; if (ec == EventCategory.SleepLevel) { SleepEvent ev = new SleepEvent(); ev.EventType = (SleepEventType)(data1 & 0xFF); // data1 encodes the type in the lower 16 bits and... ev.Level = SleepLevel.Awake; ev.WakeUpEvents = (HardwareEvent)data2; ev.Time = time; be = ev; } else if (ec == EventCategory.PowerLevel) { PowerEvent ev = new PowerEvent(); ev.EventType = PowerEventType.PostNotify; ev.Level = (PowerLevel)data2; ev.Time = time; be = ev; } return be; }
/// <summary> /// The Sleep method puts the device into a sleeps state that is only woken by the events described in the paramter wakeUpEvents. /// Please note that if the event SystemTimer is not used, the system will not be woken up by any managed timers. In addition, /// other threads will not be executed until this sleep call exits. This method raises the OnSleepChange event. /// /// The MaximumTimeToActive property contains the timeout value for this call. /// </summary> /// <param name="level">Determines what level of sleep the system should enter. The behavior of the level is determined /// by the hardware vendor.</param> /// <param name="wakeUpEvents">Determines the events that will cause the system to exit the given sleep level</param> public static void Sleep(SleepLevel level, HardwareEvent wakeUpEvents) { SleepChangeEventHandler h = OnSleepChange; if (h != null) { SleepEvent e = new SleepEvent(); e.EventType = SleepEventType.ChangeRequested; e.Level = level; e.WakeUpEvents = wakeUpEvents; e.Time = DateTime.UtcNow; h(e); } InternalSleep(level, wakeUpEvents); }