Skip to content

Commit 94c7edd

Browse files
committed
Added DeviceBootloader bindings
1 parent 68a2790 commit 94c7edd

File tree

7 files changed

+64
-7
lines changed

7 files changed

+64
-7
lines changed

CMakeLists.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,9 @@ find_package(pybind11 CONFIG REQUIRED)
3838
# Add files for python module
3939
pybind11_add_module(${TARGET_NAME}
4040
src/py_bindings.cpp
41-
#src/host_data_packet_bindings.cpp
42-
#src/nnet_packet_bindings.cpp
43-
#src/py_tensor_entry_container_iterator.cpp
44-
#src/device_bindings.cpp
4541
src/XLinkConnectionBindings.cpp
4642
src/DeviceBindings.cpp
43+
src/DeviceBootloaderBindings.cpp
4744
src/DatatypeBindings.cpp
4845
src/DataQueueBindings.cpp
4946
src/pipeline/PipelineBindings.cpp

src/DeviceBindings.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,18 @@ void DeviceBindings::bind(pybind11::module& m){
77

88
using namespace dai;
99

10+
1011
// Bind global properties
1112
py::class_<Device>(m, "Device")
13+
.def_static("getFirstAvailableDevice", &Device::getFirstAvailableDevice)
14+
.def_static("getAllAvailableDevices", &Device::getAllAvailableDevices)
15+
.def_static("getEmbeddedDeviceBinary", &Device::getEmbeddedDeviceBinary)
1216
.def(py::init<>())
17+
.def(py::init<bool>(), py::arg("usb2Mode"))
18+
.def(py::init<const char*>(), py::arg("pathToCmd"))
19+
.def(py::init<const std::string&>(), py::arg("pathToCmd"))
20+
.def(py::init<const DeviceInfo&, bool>(), py::arg("deviceDesc"), py::arg("usb2Mode") = false)
21+
.def(py::init<const DeviceInfo&, std::string>(), py::arg("deviceDesc"), py::arg("pathToCmd"))
1322
.def(py::init<const DeviceInfo&, bool>(), py::arg("deviceDesc"), py::arg("usb2Mode") = false)
1423
.def(py::init<const DeviceInfo&, std::string>(), py::arg("deviceDesc"), py::arg("pathToCmd"))
1524
.def("isPipelineRunning", &Device::isPipelineRunning)

src/DeviceBootloaderBindings.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#include "DeviceBootloaderBindings.hpp"
2+
3+
// depthai
4+
#include "depthai/DeviceBootloader.hpp"
5+
6+
// pybind for functions
7+
#include "pybind11/functional.h"
8+
9+
void DeviceBootloaderBindings::bind(pybind11::module& m){
10+
11+
using namespace dai;
12+
13+
// Bind DeviceBootloader
14+
py::class_<DeviceBootloader> deviceBootloader(m, "DeviceBootloader");
15+
16+
py::class_<DeviceBootloader::Version>(deviceBootloader, "Version")
17+
.def(py::init<const std::string&>())
18+
.def(py::init<unsigned, unsigned, unsigned>())
19+
.def("__str__", &DeviceBootloader::Version::toString)
20+
.def("__eq__", &DeviceBootloader::Version::operator==)
21+
.def("__lt__", &DeviceBootloader::Version::operator<)
22+
.def("__gt__", &DeviceBootloader::Version::operator>)
23+
;
24+
25+
deviceBootloader
26+
.def_static("getFirstAvailableDevice", &DeviceBootloader::getFirstAvailableDevice)
27+
.def_static("getAllAvailableDevices", &DeviceBootloader::getAllAvailableDevices)
28+
.def_static("createDepthaiApplicationPackage", &DeviceBootloader::createDepthaiApplicationPackage)
29+
.def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion)
30+
.def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary)
31+
.def(py::init<const DeviceInfo&>(), py::arg("deviceDesc"))
32+
.def(py::init<const DeviceInfo&, const char*>(), py::arg("deviceDesc"), py::arg("pathToCmd"))
33+
.def(py::init<const DeviceInfo&, std::string>(), py::arg("deviceDesc"), py::arg("pathToCmd"))
34+
.def("flash", &DeviceBootloader::flash, py::arg("progressCallback"), py::arg("pipeline"))
35+
.def("flashDepthaiApplicationPackage", &DeviceBootloader::flashDepthaiApplicationPackage, py::arg("progressCallback"), py::arg("package"))
36+
.def("flashBootloader", &DeviceBootloader::flashBootloader, py::arg("progressCallback"), py::arg("path") = "")
37+
.def("getVersion", &DeviceBootloader::getVersion)
38+
.def("isEmbeddedVersion", &DeviceBootloader::isEmbeddedVersion)
39+
;
40+
41+
}

src/DeviceBootloaderBindings.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
// pybind
4+
#include "pybind11_common.hpp"
5+
6+
struct DeviceBootloaderBindings {
7+
static void bind(pybind11::module& m);
8+
};

src/XLinkConnectionBindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ void XLinkConnectionBindings::bind(pybind11::module& m){
2323
[](deviceDesc_t& o){return std::string(o.name);},
2424
[](deviceDesc_t& o, std::string n){ std::strncpy(o.name, n.c_str(), std::min(XLINK_MAX_NAME_SIZE,(int) n.size()));}
2525
)
26-
2726
;
2827

2928
py::enum_<XLinkDeviceState_t>(m, "XLinkDeviceState")
3029
.value("X_LINK_ANY_STATE", X_LINK_ANY_STATE)
3130
.value("X_LINK_BOOTED", X_LINK_BOOTED)
3231
.value("X_LINK_UNBOOTED", X_LINK_UNBOOTED)
32+
.value("X_LINK_BOOTLOADER", X_LINK_BOOTLOADER)
3333
.export_values();
3434
;
3535

@@ -55,7 +55,7 @@ void XLinkConnectionBindings::bind(pybind11::module& m){
5555
.def(py::init<const DeviceInfo&, std::vector<std::uint8_t>>())
5656
.def(py::init<const DeviceInfo&, std::string>())
5757
.def(py::init<const DeviceInfo&>())
58-
.def_static("getAllConnectedDevices", &XLinkConnection::getAllConnectedDevices)
58+
.def_static("getAllConnectedDevices", &XLinkConnection::getAllConnectedDevices, py::arg("state") = X_LINK_ANY_STATE)
5959
.def_static("getFirstDevice", &XLinkConnection::getFirstDevice)
6060
;
6161

src/py_bindings.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "pipeline/NodeBindings.hpp"
2626
#include "XLinkConnectionBindings.hpp"
2727
#include "DeviceBindings.hpp"
28+
#include "DeviceBootloaderBindings.hpp"
2829
#include "DatatypeBindings.hpp"
2930
#include "DataQueueBindings.hpp"
3031

@@ -48,6 +49,7 @@ PYBIND11_MODULE(depthai,m)
4849
PipelineBindings::bind(m);
4950
XLinkConnectionBindings::bind(m);
5051
DeviceBindings::bind(m);
52+
DeviceBootloaderBindings::bind(m);
5153
DatatypeBindings::bind(m);
5254
DataQueueBindings::bind(m);
5355

0 commit comments

Comments
 (0)