PyPhoenixClockBackend  1.0.1
Binding for PhoenixClock library
Loading...
Searching...
No Matches
Timer_binding.cpp
Go to the documentation of this file.
1/***************************************
2 Auteur : Thibaut Oprinsen
3 Mail : thibaut.oprinsen@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#include "PTimer.h"
8#include <ctime>
9#include <nanobind/nanobind.h>
10#include <nanobind/stl/string.h>
11#include <nanobind/stl/chrono.h>
12
13namespace nb = nanobind;
14
15NB_MODULE(timer, m) {
16 m.doc() = "Nanobind bindings for Timer class";
17 nb::class_<PTimer>(m, "PTimer")
18
19 // Attribute
20 .def_prop_rw("ellapsedTime",
21 [](PTimer &timer) { return timer.getEllapsedTime(); },
22 [](PTimer &timer, time_t value) { timer.setEllapsedTime(value); },
23 "Get or set the ellapsed time between timer triggers")
24
25 // Constructors
26 .def(nb::init<time_t>(),
27 nb::arg("ellapsedTime") = 1lu,
28 "Constructor with custom ellapsedTime")
29
30 .def(nb::init<const PTimer &>(),
31 nb::arg("other"),
32 "Copy constructor")
33
34 // Timer configuration methods
35 .def("setStartTime", [](PTimer &timer, time_t startTime) {
36 timer.setStartTime(startTime);
37 },
38 "Set the start time for the timer")
39
40 // Timer checking methods
41 .def("isTime", [](PTimer &timer, time_t currentTime) -> bool {
42 return timer.isTime(currentTime);
43 },
44 "Check if the elapsed time has passed since start time")
45
46 .def("isTimeWithEllapsed", [](PTimer &timer, time_t ellapsedTime, time_t currentTime) -> bool {
47 return timer.isTime(ellapsedTime, currentTime);
48 },
49 "Check if time has elapsed and return (bool, elapsed_time_ns) tuple");
50}
NB_MODULE(timer, m)