Add a color (2 colors can be now defined for a machine).
[temp2RGB.git] / src / timer.rs
1 use std::time::Duration;
2
3 use windows::Win32::{Foundation::HANDLE, System::Threading::*};
4
5 pub struct Sleep {
6 timer_handle: HANDLE,
7 }
8
9 impl Sleep {
10 pub fn new() -> Self {
11 unsafe {
12 Sleep {
13 timer_handle: CreateWaitableTimerExW(
14 None,
15 windows::core::PCWSTR::null(),
16 CREATE_WAITABLE_TIMER_MANUAL_RESET | CREATE_WAITABLE_TIMER_HIGH_RESOLUTION,
17 TIMER_ALL_ACCESS.0,
18 )
19 .unwrap(),
20 }
21 }
22 }
23
24 pub fn wait(&self, d: Duration) {
25 let time = d.as_micros() as i64 * -10;
26 unsafe {
27 SetWaitableTimer(self.timer_handle, &time, 0, None, None, false).unwrap();
28 WaitForSingleObject(self.timer_handle, INFINITE);
29 }
30 }
31 }