use autocxx::c_int;
use depthai_sys::depthai;
use crate::error::{clear_error_flag, last_error, take_error_if_any, Result};
use crate::host_node::Buffer;
#[crate::native_node_wrapper(
native = "dai::node::Gate",
inputs(input, inputControl),
outputs(output)
)]
pub struct GateNode {
node: crate::pipeline::Node,
}
impl GateNode {
pub fn set_run_on_host(&self, run_on_host: bool) -> Result<()> {
clear_error_flag();
unsafe { depthai::dai_gate_set_run_on_host(self.node.handle(), run_on_host) };
if let Some(err) = take_error_if_any("failed to set gate run-on-host") {
return Err(err);
}
Ok(())
}
pub fn run_on_host(&self) -> Result<bool> {
clear_error_flag();
let v = unsafe { depthai::dai_gate_run_on_host(self.node.handle()) };
if let Some(err) = take_error_if_any("failed to get gate run-on-host") {
return Err(err);
}
Ok(v)
}
}
pub struct GateControl {
buffer: Buffer,
}
impl GateControl {
pub fn open_all() -> Result<Self> {
clear_error_flag();
let handle = unsafe { depthai::dai_gate_control_open_all() };
if handle.is_null() {
Err(last_error("failed to create GateControl::openGate()"))
} else {
Ok(Self { buffer: Buffer::from_handle(handle) })
}
}
pub fn close() -> Result<Self> {
clear_error_flag();
let handle = unsafe { depthai::dai_gate_control_close() };
if handle.is_null() {
Err(last_error("failed to create GateControl::closeGate()"))
} else {
Ok(Self { buffer: Buffer::from_handle(handle) })
}
}
pub fn open_n(num_messages: i32, fps: i32) -> Result<Self> {
clear_error_flag();
let handle = unsafe { depthai::dai_gate_control_open_n(c_int(num_messages), c_int(fps)) };
if handle.is_null() {
Err(last_error("failed to create GateControl::openGate(n, fps)"))
} else {
Ok(Self { buffer: Buffer::from_handle(handle) })
}
}
pub fn as_buffer(&self) -> &Buffer {
&self.buffer
}
}
impl std::ops::Deref for GateControl {
type Target = Buffer;
fn deref(&self) -> &Self::Target {
&self.buffer
}
}