Skip to content

Commit

Permalink
Windows tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
aMarcireau committed Jun 29, 2023
1 parent d79e3ac commit add6408
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 102 deletions.
3 changes: 1 addition & 2 deletions drivers/src/adapters/evt3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ impl Adapter {
}

pub fn current_t(&self) -> u64 {
(((self.previous_lsb_t as u32) | ((self.previous_msb_t as u32) << 12)) as u64)
| ((self.overflows as u64) << 24)
self.t
}

pub fn convert<HandleDvsEvent, HandleTriggerEvent>(
Expand Down
2 changes: 1 addition & 1 deletion drivers/src/devices/prophesee_evk3_hd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ impl Drop for Device {
let _ = UnknownB000 { value: 0x000002D8 }.write(&self.handle);
std::thread::sleep(std::time::Duration::from_micros(300));
let _ = Unknown0070 { value: 0x00400000 }.write(&self.handle);
let _ = Unknown006C { value: 0x0eE47114 }.write(&self.handle);
let _ = Unknown006C { value: 0x0EE47114 }.write(&self.handle);
std::thread::sleep(std::time::Duration::from_micros(500));
let _ = UnknownA00C { value: 0x00000400 }.write(&self.handle);
std::thread::sleep(std::time::Duration::from_micros(500));
Expand Down
1 change: 1 addition & 0 deletions python/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ python/neuromorphic_drivers/generated
src/generated.rs
tests/*.raw
*.so
*.pyd
__pycache__
7 changes: 3 additions & 4 deletions python/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ fn quote_type(
name_to_new_name: &std::collections::HashMap<String, String>,
) -> String {
match format {
reflect::Format::TypeName(name) => {
name_to_new_name.get(name).unwrap_or(name).clone()
}
reflect::Format::TypeName(name) => name_to_new_name.get(name).unwrap_or(name).clone(),
reflect::Format::Unit => "serde.type.unit".into(),
reflect::Format::Bool => "bool".into(),
reflect::Format::I8 => "serde.type.int8".into(),
Expand Down Expand Up @@ -238,7 +236,8 @@ fn generate_dataclasses<Writer: std::io::Write, Structure>(
if let NodeClass::Dataclass {
children,
fields: _,
} = &node.class {
} = &node.class
{
new_nodes_names_to_update.extend(
children
.iter()
Expand Down
159 changes: 65 additions & 94 deletions python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,35 @@ unsafe impl Send for DeviceReference<'_> {}
struct AdapterReference<'a>(pub &'a mut neuromorphic_drivers_rs::Adapter);
unsafe impl Send for AdapterReference<'_> {}

fn next_output(
python: pyo3::Python,
buffer_view: Option<neuromorphic_drivers_rs::usb::BufferView<'_>>,
current_t: Option<u64>,
packet: Option<pyo3::PyObject>,
) -> pyo3::PyObject {
(
std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
buffer_view.map(|buffer_view| {
(
buffer_view
.system_time
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
buffer_view.read,
buffer_view.write_range,
buffer_view.ring_length,
current_t,
)
}),
packet,
)
.into_py(python)
}

#[pyo3::pymethods]
impl Device {
#[new]
Expand Down Expand Up @@ -175,66 +204,32 @@ impl Device {
Some(buffer_view) => {
pyo3::Python::with_gil(|python| -> pyo3::PyResult<pyo3::PyObject> {
match &mut adapter {
Some(adapter) => Ok((
std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
Some((
buffer_view
.system_time
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
buffer_view.read,
buffer_view.write_range,
buffer_view.ring_length,
adapter.0.current_t(),
)),
adapter.0.slice_to_dict(python, buffer_view.slice)?,
)
.into_py(python)),
None => Ok((
std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
Some((
buffer_view
.system_time
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
buffer_view.read,
buffer_view.write_range,
buffer_view.ring_length,
None::<u64>,
)),
pyo3::types::PyBytes::new(python, buffer_view.slice),
)
.into_py(python)),
Some(adapter) => {
let packet =
adapter.0.slice_to_dict(python, buffer_view.slice)?;
Ok(next_output(
python,
Some(buffer_view),
Some(adapter.0.current_t()),
Some(packet),
))
}
None => {
let packet =
pyo3::types::PyBytes::new(python, buffer_view.slice).into();
Ok(next_output(python, Some(buffer_view), None, Some(packet)))
}
}
})
}
None => pyo3::Python::with_gil(|python| match &mut adapter {
Some(_) => Ok((
std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
None::<(f64, usize, (usize, usize), usize, u64)>,
pyo3::types::PyDict::new(python),
)
.into_py(python)),
None => Ok((
std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
None::<(f64, usize, (usize, usize), usize, u64)>,
None::<&pyo3::types::PyBytes>,
)
.into_py(python)),
Some(_) => Ok(next_output(
python,
None,
None,
Some(pyo3::types::PyDict::new(python).into()),
)),
None => Ok(next_output(python, None, None, None)),
}),
})
.map(Some)
Expand All @@ -250,44 +245,20 @@ impl Device {
.next_with_timeout(&std::time::Duration::from_millis(100))
{
return pyo3::Python::with_gil(|python| match adapter {
Some(adapter) => Ok((
std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
Some((
buffer_view
.system_time
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
buffer_view.read,
buffer_view.write_range,
buffer_view.ring_length,
adapter.0.current_t(),
)),
adapter.0.slice_to_dict(python, buffer_view.slice)?,
)
.into_py(python)),
None => Ok((
std::time::SystemTime::now()
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
Some((
buffer_view
.system_time
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.unwrap_or(std::time::Duration::from_secs(0))
.as_secs_f64(),
buffer_view.read,
buffer_view.write_range,
buffer_view.ring_length,
None::<u64>,
)),
pyo3::types::PyBytes::new(python, buffer_view.slice),
)
.into_py(python)),
Some(adapter) => {
let packet = adapter.0.slice_to_dict(python, buffer_view.slice)?;
Ok(next_output(
python,
Some(buffer_view),
Some(adapter.0.current_t()),
Some(packet),
))
}
None => {
let packet =
pyo3::types::PyBytes::new(python, buffer_view.slice).into();
Ok(next_output(python, Some(buffer_view), None, Some(packet)))
}
})
.map(Some);
}
Expand Down
3 changes: 2 additions & 1 deletion python/tests/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def push(
current_t: int,
):
self.current_t = current_t
print(current_t, dvs_events["t"][-1], current_t - dvs_events["t"][-1])
self.ts_and_ons[dvs_events["x"], dvs_events["y"]] = dvs_events["t"].astype(
numpy.float32
) * (dvs_events["on"].astype(numpy.float32) * 2.0 - 1.0)
Expand All @@ -150,7 +151,7 @@ def update_t(self, current_t: int):
if __name__ == "__main__":
neuromorphic_drivers.print_device_list()
camera_thread: typing.Optional[threading.Thread] = None
with neuromorphic_drivers.open(iterator_timeout=FRAME_DURATION) as device:
with neuromorphic_drivers.open() as device:
print(device.serial(), device.properties())
canvas = Canvas(
sensor_width=int(device.properties().width),
Expand Down

0 comments on commit add6408

Please sign in to comment.