Skip to content

Commit 501439d

Browse files
committed
WIP Timer callback implementation.
Signed-off-by: Agustin Alba Chicar <[email protected]>
1 parent e46224f commit 501439d

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

rclrs/src/timer.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ use crate::{
44
use std::sync::{Arc, Mutex};
55

66

7+
8+
pub trait TimerCallback {
9+
fn call(time_since_last_callback_ns: i64);
10+
}
11+
712
#[derive(Debug)]
813
pub struct Timer {
914
rcl_timer: Arc<Mutex<rcl_timer_t>>,
10-
}
11-
12-
unsafe extern "C" fn timer_callback(_: *mut rcl_timer_t, time_since_last_callback_ns: i64) {
13-
println!("timer_callback, time_since_last_callback_ns {0}", time_since_last_callback_ns);
15+
// callback: Option<T>,
1416
}
1517

1618
impl Timer {
@@ -22,7 +24,7 @@ impl Timer {
2224
let allocator = rcutils_get_default_allocator();
2325
let mut rcl_clock = clock.rcl_clock.lock().unwrap();
2426
let mut rcl_context = context.handle.rcl_context.lock().unwrap();
25-
let callback: rcl_timer_callback_t = Some(timer_callback);
27+
let callback: rcl_timer_callback_t = None;
2628
// Function will return Err(_) only if there isn't enough memory to allocate a clock
2729
// object.
2830
rcl_timer_init(
@@ -36,7 +38,8 @@ impl Timer {
3638
};
3739
to_rclrs_result(timer_init_result).map(|_| {
3840
Timer {
39-
rcl_timer: Arc::new(Mutex::new(rcl_timer))
41+
rcl_timer: Arc::new(Mutex::new(rcl_timer)),
42+
// callback: None
4043
}
4144
})
4245
}

0 commit comments

Comments
 (0)