From 0cadb24e3172388a8f621dd4ff5aeefe046fe471 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sun, 16 May 2021 01:44:52 +0200 Subject: [PATCH 01/29] WIP: Device configuration --- depthai-core | 2 +- examples/01_rgb_preview.py | 2 +- src/DeviceBindings.cpp | 110 +++++++++++++++++++----------- src/DeviceBootloaderBindings.cpp | 14 ++-- src/pipeline/CommonBindings.cpp | 19 ++++-- src/pipeline/PipelineBindings.cpp | 1 + src/py_bindings.cpp | 2 +- 7 files changed, 101 insertions(+), 49 deletions(-) diff --git a/depthai-core b/depthai-core index be20e5ee0..3634db32a 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit be20e5ee04e483ffb3463d87ef0e9286a4333dab +Subproject commit 3634db32aeffb0a92ddb5572b2238db2ade429a8 diff --git a/examples/01_rgb_preview.py b/examples/01_rgb_preview.py index 80057a6ce..9ea96a04f 100755 --- a/examples/01_rgb_preview.py +++ b/examples/01_rgb_preview.py @@ -18,7 +18,7 @@ camRgb.preview.link(xoutRgb.input) # Connect to the device -with dai.Device() as device: +with dai.Device(dai.OpenVINO.VERSION_2021_2, usb2Mode=True) as device: # Print out available cameras print('Connected cameras: ', device.getConnectedCameras()) # Start pipeline diff --git a/src/DeviceBindings.cpp b/src/DeviceBindings.cpp index a24f8c8b6..0f534db44 100644 --- a/src/DeviceBindings.cpp +++ b/src/DeviceBindings.cpp @@ -10,9 +10,10 @@ // hedley #include + // Searches for available devices (as Device constructor) // but pooling, to check for python interrupts, and releases GIL in between -static std::unique_ptr deviceConstructorHelper(const dai::Pipeline& pipeline, const std::string& pathToCmd = "", bool usb2Mode = false){ +static dai::DeviceInfo deviceSearchHelper(){ auto startTime = std::chrono::steady_clock::now(); bool found; dai::DeviceInfo deviceInfo = {}; @@ -40,6 +41,13 @@ static std::unique_ptr deviceConstructorHelper(const dai::Pipeline& // if no devices found, then throw if(!found) throw std::runtime_error("No available devices"); + return deviceInfo; +} + +static std::unique_ptr deviceConstructorHelper(const dai::Pipeline& pipeline, const std::string& pathToCmd = "", bool usb2Mode = false){ + // Find device + dai::DeviceInfo deviceInfo = deviceSearchHelper(); + // Check if pathToCmd supplied if(pathToCmd.empty()){ return std::unique_ptr(new dai::Device(pipeline, deviceInfo, usb2Mode)); @@ -49,35 +57,9 @@ static std::unique_ptr deviceConstructorHelper(const dai::Pipeline& return nullptr; } -// Searches for available devices (as Device constructor) -// but pooling, to check for python interrupts, and releases GIL in between static std::unique_ptr deviceConstructorHelper(dai::OpenVINO::Version version, const std::string& pathToCmd = "", bool usb2Mode = false){ - auto startTime = std::chrono::steady_clock::now(); - bool found; - dai::DeviceInfo deviceInfo = {}; - do { - { - // releases python GIL - py::gil_scoped_release release; - std::tie(found, deviceInfo) = dai::Device::getFirstAvailableDevice(); - // Check if found - if(found){ - break; - } else { - // block for 100ms - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } - } - // reacquires python GIL for PyErr_CheckSignals call - // check if interrupt triggered in between - if (PyErr_CheckSignals() != 0) throw py::error_already_set(); - } while(std::chrono::steady_clock::now() - startTime < dai::Device::DEFAULT_SEARCH_TIME); - - // If neither UNBOOTED nor BOOTLOADER were found (after 'DEFAULT_SEARCH_TIME'), try BOOTED - if(!found) std::tie(found, deviceInfo) = dai::XLinkConnection::getFirstDevice(X_LINK_BOOTED); - - // if no devices found, then throw - if(!found) throw std::runtime_error("No available devices"); + // Find device + dai::DeviceInfo deviceInfo = deviceSearchHelper(); // Check if pathToCmd supplied if(pathToCmd.empty()){ @@ -116,9 +98,27 @@ void DeviceBindings::bind(pybind11::module& m){ using namespace dai; + // Bind preboot config + py::class_(m, "PrebootConfig", DOC(dai, PrebootConfig)) + .def(py::init<>()) + .def_readwrite("vid", &PrebootConfig::vid) + .def_readwrite("pid", &PrebootConfig::pid) + .def_readwrite("flashBootedVid", &PrebootConfig::flashBootedVid) + .def_readwrite("flashBootedPid", &PrebootConfig::flashBootedPid) + .def_readwrite("maxUsbSpeed", &PrebootConfig::maxUsbSpeed) + ; + // Bind Device, using DeviceWrapper to be able to destruct the object by calling close() - py::class_(m, "Device", DOC(dai, Device)) + py::class_ device(m, "Device", DOC(dai, Device)); + + py::class_(device, "Config", DOC(dai, Device, Config)) + .def(py::init<>()) + .def_readwrite("version", &Device::Config::version) + .def_readwrite("preboot", &Device::Config::preboot) + ; + + device // Python only methods .def("__enter__", [](py::object obj){ return obj; }) .def("__exit__", [](Device& d, py::object type, py::object value, py::object traceback) { d.close(); }) @@ -141,38 +141,71 @@ void DeviceBindings::bind(pybind11::module& m){ // Blocking constructor return deviceConstructorHelper(pipeline, std::string(""), usb2Mode); }), py::arg("pipeline"), py::arg("usb2Mode"), DOC(dai, Device, Device, 2)) + + .def(py::init([](const Pipeline& pipeline, UsbSpeed maxUsbSpeed){ + auto dev = deviceSearchHelper(); + // Blocking constructor + return std::make_unique(pipeline, dev, maxUsbSpeed); + }), py::arg("pipeline"), py::arg("maxUsbSpeed"), DOC(dai, Device, Device, 2)) + .def(py::init([](const Pipeline& pipeline, const std::string& pathToCmd){ // Blocking constructor return deviceConstructorHelper(pipeline, pathToCmd); - }), py::arg("pipeline"), py::arg("pathToCmd"), DOC(dai, Device, Device, 3)) + }), py::arg("pipeline"), py::arg("pathToCmd"), DOC(dai, Device, Device, 4)) .def(py::init([](const Pipeline& pipeline, const DeviceInfo& deviceInfo, bool usb2Mode){ // Non blocking constructor return std::unique_ptr(new Device(pipeline, deviceInfo, usb2Mode)); - }), py::arg("pipeline"), py::arg("deviceDesc"), py::arg("usb2Mode") = false, DOC(dai, Device, Device, 4)) + }), py::arg("pipeline"), py::arg("deviceInfo"), py::arg("usb2Mode") = false, DOC(dai, Device, Device, 5)) + + .def(py::init([](const Pipeline& pipeline, const DeviceInfo& deviceInfo, UsbSpeed maxUsbSpeed){ + // Non blocking constructor + return std::make_unique(pipeline, deviceInfo, maxUsbSpeed); + }), py::arg("pipeline"), py::arg("deviceInfo"), py::arg("maxUsbSpeed"), DOC(dai, Device, Device, 6)) + .def(py::init([](const Pipeline& pipeline, const DeviceInfo& deviceInfo, std::string pathToCmd){ // Non blocking constructor return std::unique_ptr(new Device(pipeline, deviceInfo, pathToCmd)); - }), py::arg("pipeline"), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, Device, Device, 5)) + }), py::arg("pipeline"), py::arg("deviceInfo"), py::arg("pathToCmd"), DOC(dai, Device, Device, 7)) // Device constructor - OpenVINO version - .def(py::init([](OpenVINO::Version version){ return deviceConstructorHelper(version); }), py::arg("version") = Pipeline::DEFAULT_OPENVINO_VERSION, DOC(dai, Device, Device, 6)) + .def(py::init([](OpenVINO::Version version){ return deviceConstructorHelper(version); }), py::arg("version") = Pipeline::DEFAULT_OPENVINO_VERSION, DOC(dai, Device, Device, 8)) + .def(py::init([](OpenVINO::Version version, bool usb2Mode){ // Blocking constructor return deviceConstructorHelper(version, std::string(""), usb2Mode); - }), py::arg("version"), py::arg("usb2Mode"), DOC(dai, Device, Device, 7)) + }), py::arg("version"), py::arg("usb2Mode"), DOC(dai, Device, Device, 9)) + + .def(py::init([](OpenVINO::Version version, UsbSpeed maxUsbSpeed){ + auto dev = deviceSearchHelper(); + // Non blocking constructor + return std::make_unique(version, dev, maxUsbSpeed); + }), py::arg("version"), py::arg("maxUsbSpeed"), DOC(dai, Device, Device, 10)) + .def(py::init([](OpenVINO::Version version, const std::string& pathToCmd){ // Blocking constructor return deviceConstructorHelper(version, pathToCmd); - }), py::arg("version"), py::arg("pathToCmd"), DOC(dai, Device, Device, 8)) + }), py::arg("version"), py::arg("pathToCmd"), DOC(dai, Device, Device, 11)) .def(py::init([](OpenVINO::Version version, const DeviceInfo& deviceInfo, bool usb2Mode){ // Non blocking constructor return std::unique_ptr(new Device(version, deviceInfo, usb2Mode)); - }), py::arg("version"), py::arg("deviceDesc"), py::arg("usb2Mode") = false, DOC(dai, Device, Device, 9)) + }), py::arg("version"), py::arg("deviceInfo"), py::arg("usb2Mode") = false, DOC(dai, Device, Device, 12)) + + .def(py::init([](OpenVINO::Version version, const DeviceInfo& deviceInfo, UsbSpeed maxUsbSpeed){ + // Non blocking constructor + return std::unique_ptr(new Device(version, deviceInfo, maxUsbSpeed)); + }), py::arg("version"), py::arg("deviceInfo"), py::arg("maxUsbSpeed") = false, DOC(dai, Device, Device, 13)) + + .def(py::init([](OpenVINO::Version version, const DeviceInfo& deviceInfo, std::string pathToCmd){ // Non blocking constructor return std::unique_ptr(new Device(version, deviceInfo, pathToCmd)); - }), py::arg("version"), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, Device, Device, 10)) + }), py::arg("version"), py::arg("deviceInfo"), py::arg("pathToCmd"), DOC(dai, Device, Device, 14)) + + .def(py::init([](const DeviceInfo& deviceInfo, Device::Config config){ + // Non blocking constructor + return std::make_unique(deviceInfo, config); + }), py::arg("deviceInfo"), py::arg("config"), DOC(dai, Device, Device, 15)) .def("isPipelineRunning", &Device::isPipelineRunning, DOC(dai, Device, isPipelineRunning)) .def("startPipeline", [](Device& d){ @@ -234,6 +267,7 @@ void DeviceBindings::bind(pybind11::module& m){ .def("getChipTemperature", &Device::getChipTemperature, DOC(dai, Device, getChipTemperature)) .def("getLeonCssCpuUsage", &Device::getLeonCssCpuUsage, DOC(dai, Device, getLeonCssCpuUsage)) .def("getLeonMssCpuUsage", &Device::getLeonMssCpuUsage, DOC(dai, Device, getLeonMssCpuUsage)) + .def("getUsbSpeed", &Device::getLeonMssCpuUsage, DOC(dai, Device, getUsbSpeed)) .def("setLogOutputLevel", &Device::setLogOutputLevel, py::arg("level"), DOC(dai, Device, setLogOutputLevel)) .def("getLogOutputLevel", &Device::getLogOutputLevel, DOC(dai, Device, getLogOutputLevel)) .def("addLogCallback", &Device::addLogCallback, py::arg("callback"), DOC(dai, Device, addLogCallback)) diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index e8fb23d87..37db35741 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -10,6 +10,12 @@ void DeviceBootloaderBindings::bind(pybind11::module& m){ // Bind DeviceBootloader py::class_ deviceBootloader(m, "DeviceBootloader", DOC(dai, DeviceBootloader)); + // DeviceBootloader::Config + py::class_(deviceBootloader, "Config", DOC(dai, DeviceBootloader, Config)) + .def(py::init<>()) + .def_readwrite("timeout", &DeviceBootloader::Config::timeout) + ; + py::class_(deviceBootloader, "Version", DOC(dai, DeviceBootloader, Version)) .def(py::init(), py::arg("v"), DOC(dai, DeviceBootloader, Version, Version)) .def(py::init(), py::arg("major"), py::arg("minor"), py::arg("patch"), DOC(dai, DeviceBootloader, Version, Version, 2)) @@ -27,16 +33,16 @@ void DeviceBootloaderBindings::bind(pybind11::module& m){ .def_static("getFirstAvailableDevice", &DeviceBootloader::getFirstAvailableDevice, DOC(dai, DeviceBootloader, getFirstAvailableDevice)) .def_static("getAllAvailableDevices", &DeviceBootloader::getAllAvailableDevices, DOC(dai, DeviceBootloader, getAllAvailableDevices)) - .def_static("saveDepthaiApplicationPackage", &DeviceBootloader::saveDepthaiApplicationPackage, py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) - .def_static("createDepthaiApplicationPackage", &DeviceBootloader::createDepthaiApplicationPackage, py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) + .def_static("saveDepthaiApplicationPackage", &DeviceBootloader::saveDepthaiApplicationPackage, py::arg("path"), py::arg("pipeline"), py::arg("maxUsbSpeed") = Device::DEFAULT_USB_SPEED, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) + .def_static("createDepthaiApplicationPackage", &DeviceBootloader::createDepthaiApplicationPackage, py::arg("pipeline"), py::arg("maxUsbSpeed") = Device::DEFAULT_USB_SPEED, DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) .def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion, DOC(dai, DeviceBootloader, getEmbeddedBootloaderVersion)) - .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) + .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, py::arg("config"), DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) .def(py::init(), py::arg("deviceDesc"), DOC(dai, DeviceBootloader, DeviceBootloader)) .def(py::init(), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, DeviceBootloader, DeviceBootloader, 2)) .def("flash", &DeviceBootloader::flash, py::arg("progressCallback"), py::arg("pipeline"), DOC(dai, DeviceBootloader, flash)) .def("flashDepthaiApplicationPackage", &DeviceBootloader::flashDepthaiApplicationPackage, py::arg("progressCallback"), py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage)) - .def("flashBootloader", &DeviceBootloader::flashBootloader, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader)) + .def("flashBootloader", &DeviceBootloader::flashBootloader, py::arg("progressCallback"), py::arg("config") = DeviceBootloader::Config{}, DOC(dai, DeviceBootloader, flashBootloader)) .def("getVersion", &DeviceBootloader::getVersion, DOC(dai, DeviceBootloader, getVersion)) .def("isEmbeddedVersion", &DeviceBootloader::isEmbeddedVersion, DOC(dai, DeviceBootloader, isEmbeddedVersion)) ; diff --git a/src/pipeline/CommonBindings.cpp b/src/pipeline/CommonBindings.cpp index c5041ad1d..0a24d7098 100644 --- a/src/pipeline/CommonBindings.cpp +++ b/src/pipeline/CommonBindings.cpp @@ -6,11 +6,12 @@ #include "depthai-shared/common/MemoryInfo.hpp" #include "depthai-shared/common/ChipTemperature.hpp" #include "depthai-shared/common/CpuUsage.hpp" +#include "depthai-shared/common/UsbSpeed.hpp" void CommonBindings::bind(pybind11::module& m){ using namespace dai; - + // CameraBoardSocket enum bindings py::enum_(m, "CameraBoardSocket", DOC(dai, CameraBoardSocket)) .value("AUTO", CameraBoardSocket::AUTO) @@ -18,7 +19,7 @@ void CommonBindings::bind(pybind11::module& m){ .value("LEFT", CameraBoardSocket::LEFT) .value("RIGHT", CameraBoardSocket::RIGHT) ; - + // CameraImageOrientation enum bindings py::enum_(m, "CameraImageOrientation", DOC(dai, CameraImageOrientation)) .value("AUTO", CameraImageOrientation::AUTO) @@ -35,7 +36,7 @@ void CommonBindings::bind(pybind11::module& m){ .def_readwrite("used", &MemoryInfo::used) .def_readwrite("total", &MemoryInfo::total) ; - + // ChipTemperature py::class_(m, "ChipTemperature", DOC(dai, ChipTemperature)) .def(py::init<>()) @@ -45,7 +46,7 @@ void CommonBindings::bind(pybind11::module& m){ .def_readwrite("dss", &ChipTemperature::dss) .def_readwrite("average", &ChipTemperature::average) ; - + // CpuUsage py::class_(m, "CpuUsage", DOC(dai, CpuUsage)) .def(py::init<>()) @@ -53,4 +54,14 @@ void CommonBindings::bind(pybind11::module& m){ .def_readwrite("msTime", &CpuUsage::msTime) ; + // UsbSpeed + py::enum_(m, "UsbSpeed", DOC(dai, UsbSpeed)) + .value("UNKNOWN", UsbSpeed::UNKNOWN) + .value("LOW", UsbSpeed::LOW) + .value("FULL", UsbSpeed::FULL) + .value("HIGH", UsbSpeed::HIGH) + .value("SUPER", UsbSpeed::SUPER) + .value("SUPER_PLUS", UsbSpeed::SUPER_PLUS) + ; + } diff --git a/src/pipeline/PipelineBindings.cpp b/src/pipeline/PipelineBindings.cpp index 01b97b551..cfb010409 100644 --- a/src/pipeline/PipelineBindings.cpp +++ b/src/pipeline/PipelineBindings.cpp @@ -60,6 +60,7 @@ void PipelineBindings::bind(pybind11::module& m){ .def("getAssetManager", static_cast(&Pipeline::getAssetManager), py::return_value_policy::reference_internal, DOC(dai, Pipeline, getAssetManager)) .def("setOpenVINOVersion", &Pipeline::setOpenVINOVersion, py::arg("version") = Pipeline::DEFAULT_OPENVINO_VERSION, DOC(dai, Pipeline, setOpenVINOVersion)) .def("getOpenVINOVersion", &Pipeline::getOpenVINOVersion, DOC(dai, Pipeline, getOpenVINOVersion)) + .def("getRequiredOpenVINOVersion", &Pipeline::getRequiredOpenVINOVersion, DOC(dai, Pipeline, getRequiredOpenVINOVersion)) .def("setCameraTuningBlobPath", &Pipeline::setCameraTuningBlobPath, py::arg("path"), DOC(dai, Pipeline, setCameraTuningBlobPath)) // templated create function diff --git a/src/py_bindings.cpp b/src/py_bindings.cpp index 9686d406e..18fb21f42 100644 --- a/src/py_bindings.cpp +++ b/src/py_bindings.cpp @@ -39,6 +39,7 @@ PYBIND11_MODULE(depthai,m) // Add bindings + CommonBindings::bind(m); OpenVINOBindings::bind(m); AssetManagerBindings::bind(m); NodeBindings::bind(m); @@ -46,7 +47,6 @@ PYBIND11_MODULE(depthai,m) XLinkConnectionBindings::bind(m); DeviceBindings::bind(m); DeviceBootloaderBindings::bind(m); - CommonBindings::bind(m); DatatypeBindings::bind(m); DataQueueBindings::bind(m); LogBindings::bind(m); From 2325f8021041373b05fe4719ba0d66fb3b284b6e Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sun, 16 May 2021 02:54:44 +0200 Subject: [PATCH 02/29] Fixed wrong bindings --- src/DeviceBindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DeviceBindings.cpp b/src/DeviceBindings.cpp index 0f534db44..454e3e743 100644 --- a/src/DeviceBindings.cpp +++ b/src/DeviceBindings.cpp @@ -267,7 +267,7 @@ void DeviceBindings::bind(pybind11::module& m){ .def("getChipTemperature", &Device::getChipTemperature, DOC(dai, Device, getChipTemperature)) .def("getLeonCssCpuUsage", &Device::getLeonCssCpuUsage, DOC(dai, Device, getLeonCssCpuUsage)) .def("getLeonMssCpuUsage", &Device::getLeonMssCpuUsage, DOC(dai, Device, getLeonMssCpuUsage)) - .def("getUsbSpeed", &Device::getLeonMssCpuUsage, DOC(dai, Device, getUsbSpeed)) + .def("getUsbSpeed", &Device::getUsbSpeed, DOC(dai, Device, getUsbSpeed)) .def("setLogOutputLevel", &Device::setLogOutputLevel, py::arg("level"), DOC(dai, Device, setLogOutputLevel)) .def("getLogOutputLevel", &Device::getLogOutputLevel, DOC(dai, Device, getLogOutputLevel)) .def("addLogCallback", &Device::addLogCallback, py::arg("callback"), DOC(dai, Device, addLogCallback)) From cf3599ba6794fae6cb9a149f541cf509e33dcab3 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 20 May 2021 15:34:32 +0200 Subject: [PATCH 03/29] Updated example to showcase UsbSpeed settings --- depthai-core | 2 +- examples/01_rgb_preview.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/depthai-core b/depthai-core index 30f3ce8a9..ab8388573 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 30f3ce8a99c19f98cfba50a1c1adde4f872acc67 +Subproject commit ab838857383c86b4e27c96dab34ec9a76e04922c diff --git a/examples/01_rgb_preview.py b/examples/01_rgb_preview.py index f8fbe4377..7750137e9 100755 --- a/examples/01_rgb_preview.py +++ b/examples/01_rgb_preview.py @@ -18,7 +18,7 @@ camRgb.preview.link(xoutRgb.input) # Connect to the device -with dai.Device(dai.OpenVINO.VERSION_2021_2, usb2Mode=True) as device: +with dai.Device(dai.OpenVINO.VERSION_2021_3, dai.UsbSpeed.SUPER) as device: # Print out available cameras print('Connected cameras: ', device.getConnectedCameras()) # Print out usb speed From a219530774384cda6efaf5fa775b344713094b32 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 21 May 2021 02:24:08 +0200 Subject: [PATCH 04/29] Removed bootloader configuration --- depthai-core | 2 +- src/DeviceBootloaderBindings.cpp | 14 ++++---------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/depthai-core b/depthai-core index ab8388573..dc02c430e 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit ab838857383c86b4e27c96dab34ec9a76e04922c +Subproject commit dc02c430e63cd988c9f3534a813e5813a02625a3 diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index 37db35741..e8fb23d87 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -10,12 +10,6 @@ void DeviceBootloaderBindings::bind(pybind11::module& m){ // Bind DeviceBootloader py::class_ deviceBootloader(m, "DeviceBootloader", DOC(dai, DeviceBootloader)); - // DeviceBootloader::Config - py::class_(deviceBootloader, "Config", DOC(dai, DeviceBootloader, Config)) - .def(py::init<>()) - .def_readwrite("timeout", &DeviceBootloader::Config::timeout) - ; - py::class_(deviceBootloader, "Version", DOC(dai, DeviceBootloader, Version)) .def(py::init(), py::arg("v"), DOC(dai, DeviceBootloader, Version, Version)) .def(py::init(), py::arg("major"), py::arg("minor"), py::arg("patch"), DOC(dai, DeviceBootloader, Version, Version, 2)) @@ -33,16 +27,16 @@ void DeviceBootloaderBindings::bind(pybind11::module& m){ .def_static("getFirstAvailableDevice", &DeviceBootloader::getFirstAvailableDevice, DOC(dai, DeviceBootloader, getFirstAvailableDevice)) .def_static("getAllAvailableDevices", &DeviceBootloader::getAllAvailableDevices, DOC(dai, DeviceBootloader, getAllAvailableDevices)) - .def_static("saveDepthaiApplicationPackage", &DeviceBootloader::saveDepthaiApplicationPackage, py::arg("path"), py::arg("pipeline"), py::arg("maxUsbSpeed") = Device::DEFAULT_USB_SPEED, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) - .def_static("createDepthaiApplicationPackage", &DeviceBootloader::createDepthaiApplicationPackage, py::arg("pipeline"), py::arg("maxUsbSpeed") = Device::DEFAULT_USB_SPEED, DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) + .def_static("saveDepthaiApplicationPackage", &DeviceBootloader::saveDepthaiApplicationPackage, py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) + .def_static("createDepthaiApplicationPackage", &DeviceBootloader::createDepthaiApplicationPackage, py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) .def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion, DOC(dai, DeviceBootloader, getEmbeddedBootloaderVersion)) - .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, py::arg("config"), DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) + .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) .def(py::init(), py::arg("deviceDesc"), DOC(dai, DeviceBootloader, DeviceBootloader)) .def(py::init(), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, DeviceBootloader, DeviceBootloader, 2)) .def("flash", &DeviceBootloader::flash, py::arg("progressCallback"), py::arg("pipeline"), DOC(dai, DeviceBootloader, flash)) .def("flashDepthaiApplicationPackage", &DeviceBootloader::flashDepthaiApplicationPackage, py::arg("progressCallback"), py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage)) - .def("flashBootloader", &DeviceBootloader::flashBootloader, py::arg("progressCallback"), py::arg("config") = DeviceBootloader::Config{}, DOC(dai, DeviceBootloader, flashBootloader)) + .def("flashBootloader", &DeviceBootloader::flashBootloader, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader)) .def("getVersion", &DeviceBootloader::getVersion, DOC(dai, DeviceBootloader, getVersion)) .def("isEmbeddedVersion", &DeviceBootloader::isEmbeddedVersion, DOC(dai, DeviceBootloader, isEmbeddedVersion)) ; From 0d9e38dd4a07e86f0ec0bc9f043a8e63ff6f7b2f Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Fri, 28 May 2021 14:48:09 +0200 Subject: [PATCH 05/29] Updated rgb_preview example --- depthai-core | 2 +- examples/rgb_preview.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/depthai-core b/depthai-core index 2f8ba370a..7dd586a30 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 2f8ba370a86e5ff627a4e884f12e45b55a387f3f +Subproject commit 7dd586a30d337bf0041bb30d0add37d31e550961 diff --git a/examples/rgb_preview.py b/examples/rgb_preview.py index 37e27d80f..8484547a9 100755 --- a/examples/rgb_preview.py +++ b/examples/rgb_preview.py @@ -21,7 +21,7 @@ camRgb.preview.link(xoutRgb.input) # Connect to the device -with dai.Device(dai.OpenVINO.VERSION_2021_3, dai.UsbSpeed.SUPER) as device: +with dai.Device(pipeline, dai.UsbSpeed.SUPER) as device: # Print out available cameras print('Connected cameras: ', device.getConnectedCameras()) # Print out usb speed @@ -31,7 +31,7 @@ qRgb = device.getOutputQueue(name="rgb", maxSize=4, blocking=False) while True: - inRgb = qRgb.get() # blocking call, will wait until a new data has arrived + inRgb = qRgb.get() # blocking call, will wait until a new data has arrived # Retrieve 'bgr' (opencv format) frame cv2.imshow("rgb", inRgb.getCvFrame()) From 147162688ed6418d9518a9d6cfcd99d1ce6c07a0 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 22 Jul 2021 13:49:59 +0200 Subject: [PATCH 06/29] Updated bindings for PrebootConfig --- depthai-core | 2 +- src/DeviceBindings.cpp | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/depthai-core b/depthai-core index 64f1aba87..d6d95e25d 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 64f1aba871829c1cb49ae78e887f793c360b417a +Subproject commit d6d95e25d0188c1029be97cc59725fdcd455d021 diff --git a/src/DeviceBindings.cpp b/src/DeviceBindings.cpp index 26c871dd1..a51501fa8 100644 --- a/src/DeviceBindings.cpp +++ b/src/DeviceBindings.cpp @@ -98,14 +98,24 @@ void DeviceBindings::bind(pybind11::module& m){ using namespace dai; - // Bind preboot config - py::class_(m, "PrebootConfig", DOC(dai, PrebootConfig)) + + // Bind PrebootConfig + py::class_ prebootConfig(m, "PrebootConfig", DOC(dai, PrebootConfig)); + + // Bind PrebootConfig::USB + py::class_(prebootConfig, "USB", DOC(dai, PrebootConfig, USB)) + .def(py::init<>()) + .def_readwrite("vid", &PrebootConfig::USB::vid) + .def_readwrite("pid", &PrebootConfig::USB::pid) + .def_readwrite("flashBootedVid", &PrebootConfig::USB::flashBootedVid) + .def_readwrite("flashBootedPid", &PrebootConfig::USB::flashBootedPid) + .def_readwrite("maxSpeed", &PrebootConfig::USB::maxSpeed) + ; + + prebootConfig .def(py::init<>()) - .def_readwrite("vid", &PrebootConfig::vid) - .def_readwrite("pid", &PrebootConfig::pid) - .def_readwrite("flashBootedVid", &PrebootConfig::flashBootedVid) - .def_readwrite("flashBootedPid", &PrebootConfig::flashBootedPid) - .def_readwrite("maxUsbSpeed", &PrebootConfig::maxUsbSpeed) + .def_readwrite("usb", &PrebootConfig::usb) + .def_readwrite("watchdogTimeoutMs", &PrebootConfig::watchdogTimeoutMs) ; From c195c80ddd99ec6104b1c8bf3d2b9f314b21f9f6 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 24 Jul 2021 22:39:16 +0200 Subject: [PATCH 07/29] Added missing bindings --- depthai-core | 2 +- src/pipeline/PipelineBindings.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index cec733af3..23319c3a2 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit cec733af3cb7015b7024a36b835787e2e5c38e8a +Subproject commit 23319c3a25cd7d5cc43541b81d41b0c1922d429d diff --git a/src/pipeline/PipelineBindings.cpp b/src/pipeline/PipelineBindings.cpp index 8e94aea10..c62f80066 100644 --- a/src/pipeline/PipelineBindings.cpp +++ b/src/pipeline/PipelineBindings.cpp @@ -97,6 +97,7 @@ void PipelineBindings::bind(pybind11::module& m, void* pCallstack){ .def("setCameraTuningBlobPath", &Pipeline::setCameraTuningBlobPath, py::arg("path"), DOC(dai, Pipeline, setCameraTuningBlobPath)) .def("setCalibrationData", &Pipeline::setCalibrationData, py::arg("calibrationDataHandler"), DOC(dai, Pipeline, setCalibrationData)) .def("getCalibrationData", &Pipeline::getCalibrationData, DOC(dai, Pipeline, getCalibrationData)) + .def("getDeviceConfig", &Pipeline::getDeviceConfig, DOC(dai, Pipeline, getDeviceConfig)) // 'Template' create function .def("create", [](dai::Pipeline& p, py::object class_) { auto node = createNode(p, class_); From 8ffab27c66bdacfb22a59a2fdadb71dbfd558fed Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Tue, 27 Jul 2021 03:36:35 +0200 Subject: [PATCH 08/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 3df1e1319..c5c3c2c07 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 3df1e13199f72dd830fa46d5e2147bda6de3fea1 +Subproject commit c5c3c2c07c1fd805cc0bef1845c7388fe089730f From acad905ea2be31aadbc28e32a90edfc826778a26 Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Fri, 23 Jul 2021 18:59:16 +0300 Subject: [PATCH 09/29] Partially revert f6173f9, add back flash_bootloader.py --- depthai-core | 2 +- examples/flash_bootloader.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100755 examples/flash_bootloader.py diff --git a/depthai-core b/depthai-core index 3df1e1319..7ce7614ec 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 3df1e13199f72dd830fa46d5e2147bda6de3fea1 +Subproject commit 7ce7614ece441d1f03b64d85976fc946b7bc51fa diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py new file mode 100755 index 000000000..59b5a8499 --- /dev/null +++ b/examples/flash_bootloader.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import depthai as dai +import sys +import time + +blType = dai.DeviceBootloader.Type.USB + +if len(sys.argv) > 1: + if sys.argv[1] == 'usb': + blType = dai.DeviceBootloader.Type.USB + elif sys.argv[1] == 'eth': + blType = dai.DeviceBootloader.Type.NETWORK + else: + print("Specify either 'usb' or 'eth' bootloader type") + quit() + +(res, info) = dai.DeviceBootloader.getFirstAvailableDevice() + +bl = dai.DeviceBootloader(info) +progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') + +print("=== Flashing", blType.name, "bootloader...") +startTime = time.monotonic() +(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) +if res: + print("Flashing successful. Took", time.monotonic() - startTime, "seconds") +else: + print("Flashing failed:", message) From b0410e916bc92656765313ea809670e4cab7e4ae Mon Sep 17 00:00:00 2001 From: alex-luxonis Date: Wed, 28 Jul 2021 20:51:03 +0300 Subject: [PATCH 10/29] Update core/bootloader --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 7ce7614ec..92a5c0dca 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 7ce7614ece441d1f03b64d85976fc946b7bc51fa +Subproject commit 92a5c0dca19a24619f9513e29bb625be29951844 From 147a2df73c54ecd68fa65065df75cd474bde8713 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Thu, 29 Jul 2021 05:00:25 +0200 Subject: [PATCH 11/29] Updated flash_bootloader example --- depthai-core | 2 +- examples/flash_bootloader.py | 49 +++++++++++++++++++++++--------- src/DeviceBootloaderBindings.cpp | 6 ++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/depthai-core b/depthai-core index 92a5c0dca..9eedc3531 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 92a5c0dca19a24619f9513e29bb625be29951844 +Subproject commit 9eedc3531d14832e98d8c1ea336e5f38dad819b9 diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index 59b5a8499..ef4689ca2 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -5,25 +5,46 @@ import time blType = dai.DeviceBootloader.Type.USB - if len(sys.argv) > 1: if sys.argv[1] == 'usb': blType = dai.DeviceBootloader.Type.USB - elif sys.argv[1] == 'eth': + elif sys.argv[1] == 'network': blType = dai.DeviceBootloader.Type.NETWORK else: - print("Specify either 'usb' or 'eth' bootloader type") - quit() + print("Specify either 'usb' or 'network' bootloader type") + exit() + +print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") +print("Do not unplug your device in while the bootloader is flashing.") +print("Type 'y' and press enter to proceed, otherwise exits: ") +if input() != 'y': + print("Prompt declined, exiting...") + exit(-1) + +(found, info) = dai.DeviceBootloader.getFirstAvailableDevice() +if not found: + print("No device found to flash. Exiting.") + exit(-1) -(res, info) = dai.DeviceBootloader.getFirstAvailableDevice() +# Open DeviceBootloader and allow flashing bootloader +with dai.DeviceBootloader(info, allowFlashingBootloader=True) as bl: + currentBlType = bl.getType() -bl = dai.DeviceBootloader(info) -progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') + # Check if bootloader type is the same + if currentBlType != blType: + print(f"Are you sure you want to flash '{blType.name}' bootloader over current '{currentBlType.name}' bootloader?") + print(f"Type 'y' and press enter to proceed, otherwise exits: ") + if input() != 'y': + print("Prompt declined, exiting...") + exit(-1); -print("=== Flashing", blType.name, "bootloader...") -startTime = time.monotonic() -(res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) -if res: - print("Flashing successful. Took", time.monotonic() - startTime, "seconds") -else: - print("Flashing failed:", message) + # Create a progress callback lambda + progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') + + print(f"Flashing {blType.name} bootloader...") + startTime = time.monotonic() + (res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) + if res: + print("Flashing successful. Took", time.monotonic() - startTime, "seconds") + else: + print("Flashing failed:", message) diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index 890364a30..50c7ccf5c 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -66,8 +66,8 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion, DOC(dai, DeviceBootloader, getEmbeddedBootloaderVersion)) .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) - .def(py::init(), py::arg("deviceDesc"), DOC(dai, DeviceBootloader, DeviceBootloader)) - .def(py::init(), py::arg("deviceDesc"), py::arg("pathToCmd"), DOC(dai, DeviceBootloader, DeviceBootloader, 2)) + .def(py::init(), py::arg("devInfo"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader)) + .def(py::init(), py::arg("devInfo"), py::arg("pathToCmd"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader, 2)) .def("flash", [](DeviceBootloader& db, std::function progressCallback, Pipeline& pipeline) { py::gil_scoped_release release; return db.flash(progressCallback, pipeline); }, py::arg("progressCallback"), py::arg("pipeline"), DOC(dai, DeviceBootloader, flash)) .def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::function progressCallback, std::vector package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(progressCallback, package); }, py::arg("progressCallback"), py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage)) .def("flashBootloader", [](DeviceBootloader& db, std::function progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(progressCallback, path); }, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader)) @@ -76,6 +76,8 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def("getVersion", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.getVersion(); }, DOC(dai, DeviceBootloader, getVersion)) .def("isEmbeddedVersion", &DeviceBootloader::isEmbeddedVersion, DOC(dai, DeviceBootloader, isEmbeddedVersion)) + .def("getType", &DeviceBootloader::getType, DOC(dai, DeviceBootloader, getType)) + .def("isAllowedFlashingBootloader", &DeviceBootloader::isAllowedFlashingBootloader, DOC(dai, DeviceBootloader, isAllowedFlashingBootloader)) ; } From 9420ab7785d343ee9bcdf7a7efb1a0c239c84de3 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Thu, 29 Jul 2021 15:16:24 +0200 Subject: [PATCH 12/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 9eedc3531..08e6ad7f0 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 9eedc3531d14832e98d8c1ea336e5f38dad819b9 +Subproject commit 08e6ad7f0765340e07a0bbb846a72b4b02cb2ca7 From ab1b6a608d12e3535ecd1e7d4e32977cb0703005 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Fri, 30 Jul 2021 02:31:08 +0200 Subject: [PATCH 13/29] Added documentation of new Script GPIO API --- docs/source/components/nodes/script.rst | 31 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/docs/source/components/nodes/script.rst b/docs/source/components/nodes/script.rst index 1e8bc1f0a..a5b5123e2 100644 --- a/docs/source/components/nodes/script.rst +++ b/docs/source/components/nodes/script.rst @@ -91,15 +91,34 @@ Usage Interfacing with GPIOs ###################### -In the script node you can interface with GPIOs of the VPU. Currently supported functions are: +In the script node you can interface with GPIOs of the VPU using module GPIO. Currently supported functions are: .. code-block:: python - import GPIO # module - GPIO.read(pin) - GPIO.write(pin, value) - GPIO.setPwm(pin, highCount, lowCount, repeat=0) # repeat == 0 means indefinite - GPIO.enablePwm(pin, enable) + # Module + import GPIO + + # General + GPIO.setup(gpio, dir, pud, exclusive) + GPIO.release(gpio) + GPIO.write(gpio, value) + GPIO.read(gpio) + + # Interrupts + GPIO.waitInterruptEvent(gpio = -1) # blocks until any interrupt or interrupt by specified gpio is fired. Interrupts with callbacks are ignored here + GPIO.hasInterruptEvent(gpio = -1) # returns whether interrupt happened on any or specfied gpio. Interrupts with callbacks are ignored here + GPIO.setInterrupt(gpio, edge, priority, callback = None) # adds interrupt to specified pin + GPIO.clearInterrupt(gpio) # clears interrupt of specified pin + + # PWM + GPIO.setPwm(gpio, highCount, lowCount, repeat=0) # repeat == 0 means indefinite + GPIO.enablePwm(gpio, enable) + + # Enumerations + GPIO.Direction: GPIO.IN, GPIO.OUT + GPIO.State: GPIO.LOW, GPIO.HIGH + GPIO.PullDownUp: GPIO.PULL_NONE, GPIO.PULL_DOWN, GPIO.PULL_UP + GPIO.Edge: GPIO.RISING, GPIO.FALLING, GPIO.LEVEL_HIGH, GPIO.LEVEL_LOW Using DepthAI :ref:`Messages ` ################################################### From c31e9f817405e462e6aaa315c75ddbbb460b7009 Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Fri, 30 Jul 2021 16:47:02 +0200 Subject: [PATCH 14/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 081940b4c..51b9079ad 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 081940b4c2f1ca97d363e718ffa36fe63133d6ea +Subproject commit 51b9079ad1c6c97c9b2c0563cea0d228dfb1a7b9 From 3fff9f2b6e3751492d6559d074c98499c63cd4cd Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Tue, 3 Aug 2021 11:36:14 +0200 Subject: [PATCH 15/29] Updated core with SPI speed improvements --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 51b9079ad..d846a0b68 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 51b9079ad1c6c97c9b2c0563cea0d228dfb1a7b9 +Subproject commit d846a0b68323104a0fc658720be2bf913bbff3c4 From 5992be8988a5fbd133834db0740d6101fb9dccae Mon Sep 17 00:00:00 2001 From: Martin Peterlin Date: Wed, 4 Aug 2021 19:58:32 +0200 Subject: [PATCH 16/29] Updated core and flash_bootloader example typo --- depthai-core | 2 +- examples/flash_bootloader.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/depthai-core b/depthai-core index 154203bbb..819e9e221 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 154203bbbd66cf567d2485fce4048c97c4b91dbc +Subproject commit 819e9e2211041113ed8f30f203d9ca12ba03b2cd diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index ef4689ca2..17ebf4797 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -15,7 +15,7 @@ exit() print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") -print("Do not unplug your device in while the bootloader is flashing.") +print("Do not unplug your device while the bootloader is flashing.") print("Type 'y' and press enter to proceed, otherwise exits: ") if input() != 'y': print("Prompt declined, exiting...") From dbd7e48aa19c46c0560aff060b756fdde18c8b84 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Tue, 17 Aug 2021 10:57:37 +0200 Subject: [PATCH 17/29] Updated flash_bootloader.py example --- depthai-core | 2 +- examples/flash_bootloader.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index f7711f909..5dc961ab5 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit f7711f9091998871e4c07d2efe7f13fab9a0e94f +Subproject commit 5dc961ab5eb8ec4feb6e351760c6f647c69f235b diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index 17ebf4797..d84ef1e4d 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -13,6 +13,9 @@ else: print("Specify either 'usb' or 'network' bootloader type") exit() +else: + print(f"Usage: {sys.argv[0]} ") + exit() print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") print("Do not unplug your device while the bootloader is flashing.") From e53ca51234798217ea92ecfd7480bdc2be820b2d Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 21 Aug 2021 22:35:30 +0200 Subject: [PATCH 18/29] Added bindings for DeviceBootloader Config --- CMakeLists.txt | 1 + depthai-core | 2 +- examples/bootloader_configuration.py | 53 +++++ external/CMakeLists.txt | 4 +- external/pybind11_json/CMakeLists.txt | 3 + .../include/pybind11_json/pybind11_json.hpp | 223 ++++++++++++++++++ src/DeviceBootloaderBindings.cpp | 73 +++++- src/pybind11_common.hpp | 1 + 8 files changed, 355 insertions(+), 5 deletions(-) create mode 100755 examples/bootloader_configuration.py create mode 100644 external/pybind11_json/CMakeLists.txt create mode 100644 external/pybind11_json/include/pybind11_json/pybind11_json.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index ad1730e14..1ebca983b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,7 @@ target_link_libraries(${TARGET_NAME} pybind11::pybind11 depthai::core # Use non-opencv target as we use opencv-python in bindings hedley + pybind11_json ) # Find Git diff --git a/depthai-core b/depthai-core index 5dc961ab5..93df9978e 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 5dc961ab5eb8ec4feb6e351760c6f647c69f235b +Subproject commit 93df9978e301265229ca8a613a47397cf5f3dc47 diff --git a/examples/bootloader_configuration.py b/examples/bootloader_configuration.py new file mode 100755 index 000000000..17c7d0d24 --- /dev/null +++ b/examples/bootloader_configuration.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import depthai as dai +import sys + +usage = False +read = True +clear = False +path = '' +if len(sys.argv) >= 2: + op = sys.argv[1] + if op == 'read': + read = True + elif op == 'flash': + read = False + if len(sys.argv) >= 3: + path = sys.argv[2] + elif op == 'clear': + clear = True + read = False + else: + usage = True +else: + usage = True + +if usage: + print(f'Usage: {sys.argv[0]} [read/flash/clear] [flash: path/to/config/json]') + exit(-1) + +(res, info) = dai.DeviceBootloader.getFirstAvailableDevice() + +if res: + print(f'Found device with name: {info.desc.name}'); + with dai.DeviceBootloader(info) as bl: + if read: + print('Current flashed configuration') + print(f'{bl.readConfigData()}') + else: + success = None + error = None + if clear: + (success, error) = bl.flashConfigClear() + else: + if path == '': + (success, error) = bl.flashConfig(dai.DeviceBootloader.Config()) + else: + (success, error) = bl.flashConfigFile(path) + if success: + print('Successfully flashed bootloader configuration') + else: + print(f'Error flashing bootloader configuration: {error}') +else: + print('No devices found') diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index ebc46f957..c0e240707 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -1,2 +1,4 @@ # Add 'hedley' library -add_subdirectory(hedley) \ No newline at end of file +add_subdirectory(hedley) +# Add 'pybind11_json' library +add_subdirectory(pybind11_json) \ No newline at end of file diff --git a/external/pybind11_json/CMakeLists.txt b/external/pybind11_json/CMakeLists.txt new file mode 100644 index 000000000..1e2842c70 --- /dev/null +++ b/external/pybind11_json/CMakeLists.txt @@ -0,0 +1,3 @@ +# pybind11_json library +add_library(pybind11_json INTERFACE) +target_include_directories(pybind11_json INTERFACE "${CMAKE_CURRENT_LIST_DIR}/include") diff --git a/external/pybind11_json/include/pybind11_json/pybind11_json.hpp b/external/pybind11_json/include/pybind11_json/pybind11_json.hpp new file mode 100644 index 000000000..773a30cf4 --- /dev/null +++ b/external/pybind11_json/include/pybind11_json/pybind11_json.hpp @@ -0,0 +1,223 @@ +/*************************************************************************** +* Copyright (c) 2019, Martin Renou * +* * +* Distributed under the terms of the BSD 3-Clause License. * +* * +* The full license is in the file LICENSE, distributed with this software. * +****************************************************************************/ + +#ifndef PYBIND11_JSON_HPP +#define PYBIND11_JSON_HPP + +#include +#include + +#include "nlohmann/json.hpp" + +#include "pybind11/pybind11.h" + +namespace py = pybind11; +namespace nl = nlohmann; + +namespace pyjson +{ + inline py::object from_json(const nl::json& j) + { + if (j.is_null()) + { + return py::none(); + } + else if (j.is_boolean()) + { + return py::bool_(j.get()); + } + else if (j.is_number_integer()) + { + return py::int_(j.get()); + } + else if (j.is_number_unsigned()) + { + return py::int_(j.get()); + } + else if (j.is_number_float()) + { + return py::float_(j.get()); + } + else if (j.is_string()) + { + return py::str(j.get()); + } + else if (j.is_array()) + { + py::list obj; + for (const auto& el : j) + { + obj.append(from_json(el)); + } + return std::move(obj); + } + else // Object + { + py::dict obj; + for (nl::json::const_iterator it = j.cbegin(); it != j.cend(); ++it) + { + obj[py::str(it.key())] = from_json(it.value()); + } + return std::move(obj); + } + } + + inline nl::json to_json(const py::handle& obj) + { + if (obj.ptr() == nullptr || obj.is_none()) + { + return nullptr; + } + if (py::isinstance(obj)) + { + return obj.cast(); + } + if (py::isinstance(obj)) + { + try + { + nl::json::number_integer_t s = obj.cast(); + if (py::int_(s).equal(obj)) + { + return s; + } + } + catch (...) + { + } + try + { + nl::json::number_unsigned_t u = obj.cast(); + if (py::int_(u).equal(obj)) + { + return u; + } + } + catch (...) + { + } + throw std::runtime_error("to_json received an integer out of range for both nl::json::number_integer_t and nl::json::number_unsigned_t type: " + py::repr(obj).cast()); + } + if (py::isinstance(obj)) + { + return obj.cast(); + } + if (py::isinstance(obj)) + { + py::module base64 = py::module::import("base64"); + return base64.attr("b64encode")(obj).attr("decode")("utf-8").cast(); + } + if (py::isinstance(obj)) + { + return obj.cast(); + } + if (py::isinstance(obj) || py::isinstance(obj)) + { + auto out = nl::json::array(); + for (const py::handle value : obj) + { + out.push_back(to_json(value)); + } + return out; + } + if (py::isinstance(obj)) + { + auto out = nl::json::object(); + for (const py::handle key : obj) + { + out[py::str(key).cast()] = to_json(obj[key]); + } + return out; + } + throw std::runtime_error("to_json not implemented for this type of object: " + py::repr(obj).cast()); + } +} + +// nlohmann_json serializers +namespace nlohmann +{ + #define MAKE_NLJSON_SERIALIZER_DESERIALIZER(T) \ + template <> \ + struct adl_serializer \ + { \ + inline static void to_json(json& j, const T& obj) \ + { \ + j = pyjson::to_json(obj); \ + } \ + \ + inline static T from_json(const json& j) \ + { \ + return pyjson::from_json(j); \ + } \ + } + + #define MAKE_NLJSON_SERIALIZER_ONLY(T) \ + template <> \ + struct adl_serializer \ + { \ + inline static void to_json(json& j, const T& obj) \ + { \ + j = pyjson::to_json(obj); \ + } \ + } + + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::object); + + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::bool_); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::int_); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::float_); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::str); + + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::list); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::tuple); + MAKE_NLJSON_SERIALIZER_DESERIALIZER(py::dict); + + MAKE_NLJSON_SERIALIZER_ONLY(py::handle); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::item_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::list_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::tuple_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::sequence_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::str_attr_accessor); + MAKE_NLJSON_SERIALIZER_ONLY(py::detail::obj_attr_accessor); + + #undef MAKE_NLJSON_SERIALIZER + #undef MAKE_NLJSON_SERIALIZER_ONLY +} + +// pybind11 caster +namespace pybind11 +{ + namespace detail + { + template <> struct type_caster + { + public: + PYBIND11_TYPE_CASTER(nl::json, _("json")); + + bool load(handle src, bool) + { + try { + value = pyjson::to_json(src); + return true; + } + catch (...) + { + return false; + } + } + + static handle cast(nl::json src, return_value_policy /* policy */, handle /* parent */) + { + object obj = pyjson::from_json(src); + return obj.release(); + } + }; + } +} + +#endif diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index 50c7ccf5c..c9c7d1bea 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -13,6 +13,9 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ py::enum_ deviceBootloaderType(deviceBootloader, "Type"); py::enum_ deviceBootloaderMemory(deviceBootloader, "Memory"); py::enum_ deviceBootloaderSection(deviceBootloader, "Section"); + py::class_ deviceBootlaoderUsbConfig(deviceBootloader, "UsbConfig"); + py::class_ deviceBootlaoderNetworkConfig(deviceBootloader, "NetworkConfig"); + py::class_ deviceBootloderConfig(deviceBootloader, "Config"); /////////////////////////////////////////////////////////////////////// @@ -39,20 +42,72 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ ; deviceBootloaderType + .value("AUTO", DeviceBootloader::Type::AUTO) .value("USB", DeviceBootloader::Type::USB) .value("NETWORK", DeviceBootloader::Type::NETWORK) ; deviceBootloaderMemory + .value("AUTO", DeviceBootloader::Memory::AUTO) .value("FLASH", DeviceBootloader::Memory::FLASH) .value("EMMC", DeviceBootloader::Memory::EMMC) ; deviceBootloaderSection + .value("AUTO", DeviceBootloader::Section::AUTO) .value("HEADER", DeviceBootloader::Section::HEADER) .value("BOOTLOADER", DeviceBootloader::Section::BOOTLOADER) .value("BOOTLOADER_CONFIG", DeviceBootloader::Section::BOOTLOADER_CONFIG) .value("APPLICATION", DeviceBootloader::Section::APPLICATION) ; + deviceBootlaoderUsbConfig + .def(py::init<>()) + .def_readwrite("timeoutMs", &DeviceBootloader::UsbConfig::timeoutMs) + .def_readwrite("maxUsbSpeed", &DeviceBootloader::UsbConfig::maxUsbSpeed) + .def_readwrite("vid", &DeviceBootloader::UsbConfig::vid) + .def_readwrite("pid", &DeviceBootloader::UsbConfig::pid) + ; + deviceBootlaoderNetworkConfig + .def(py::init<>()) + .def_readwrite("timeoutMs", &DeviceBootloader::NetworkConfig::timeoutMs) + .def_readwrite("ipv4", &DeviceBootloader::NetworkConfig::ipv4) + .def_readwrite("ipv4Mask", &DeviceBootloader::NetworkConfig::ipv4Mask) + .def_readwrite("ipv4Gateway", &DeviceBootloader::NetworkConfig::ipv4Gateway) + .def_readwrite("ipv4Dns", &DeviceBootloader::NetworkConfig::ipv4Dns) + .def_readwrite("ipv4DnsAlt", &DeviceBootloader::NetworkConfig::ipv4DnsAlt) + .def_readwrite("staticIpv4", &DeviceBootloader::NetworkConfig::staticIpv4) + .def_readwrite("ipv6", &DeviceBootloader::NetworkConfig::ipv6) + .def_readwrite("ipv6Prefix", &DeviceBootloader::NetworkConfig::ipv6Prefix) + .def_readwrite("ipv6Gateway", &DeviceBootloader::NetworkConfig::ipv6Gateway) + .def_readwrite("ipv6Dns", &DeviceBootloader::NetworkConfig::ipv6Dns) + .def_readwrite("ipv6DnsAlt", &DeviceBootloader::NetworkConfig::ipv6DnsAlt) + .def_readwrite("staticIpv6", &DeviceBootloader::NetworkConfig::staticIpv6) + .def_readwrite("mac", &DeviceBootloader::NetworkConfig::mac) + ; + + deviceBootloderConfig + .def(py::init<>()) + .def_readwrite("appMem", &DeviceBootloader::Config::appMem) + .def_readwrite("usb", &DeviceBootloader::Config::usb) + .def_readwrite("network", &DeviceBootloader::Config::network) + .def("setStaticIPv4", &DeviceBootloader::Config::setStaticIPv4) + .def("setDynamicIPv4", &DeviceBootloader::Config::setDynamicIPv4) + .def("isStaticIPV4", &DeviceBootloader::Config::isStaticIPV4) + .def("getIPv4", &DeviceBootloader::Config::getIPv4) + .def("getIPv4Mask", &DeviceBootloader::Config::getIPv4Mask) + .def("getIPv4Gateway", &DeviceBootloader::Config::getIPv4Gateway) + .def("setDnsIPv4", &DeviceBootloader::Config::setDnsIPv4) + .def("getDnsIPv4", &DeviceBootloader::Config::getDnsIPv4) + .def("getDnsAltIPv4", &DeviceBootloader::Config::getDnsAltIPv4) + .def("setUsbTimeout", &DeviceBootloader::Config::setUsbTimeout) + .def("getUsbTimeout", &DeviceBootloader::Config::getUsbTimeout) + .def("setNetworkTimeout", &DeviceBootloader::Config::setNetworkTimeout) + .def("getNetworkTimeout", &DeviceBootloader::Config::getNetworkTimeout) + .def("setMacAddress", &DeviceBootloader::Config::setMacAddress) + .def("getMacAddress", &DeviceBootloader::Config::getMacAddress) + .def("setUsbMaxSpeed", &DeviceBootloader::Config::setUsbMaxSpeed) + .def("getUsbMaxSpeed", &DeviceBootloader::Config::getUsbMaxSpeed) + ; + deviceBootloader // Python only methods .def("__enter__", [](py::object obj){ return obj; }) @@ -61,17 +116,29 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def_static("getFirstAvailableDevice", &DeviceBootloader::getFirstAvailableDevice, DOC(dai, DeviceBootloader, getFirstAvailableDevice)) .def_static("getAllAvailableDevices", &DeviceBootloader::getAllAvailableDevices, DOC(dai, DeviceBootloader, getAllAvailableDevices)) - .def_static("saveDepthaiApplicationPackage", &DeviceBootloader::saveDepthaiApplicationPackage, py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) - .def_static("createDepthaiApplicationPackage", &DeviceBootloader::createDepthaiApplicationPackage, py::arg("pipeline"), py::arg("pathToCmd") = "", DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) + .def_static("saveDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("pathToCmd") = "", py::arg("compress") = false, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage)) + .def_static("saveDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::saveDepthaiApplicationPackage), py::arg("path"), py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, saveDepthaiApplicationPackage, 2)) + .def_static("createDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::createDepthaiApplicationPackage), py::arg("pipeline"), py::arg("pathToCmd") = "", py::arg("compress") = false, DOC(dai, DeviceBootloader, createDepthaiApplicationPackage)) + .def_static("createDepthaiApplicationPackage", py::overload_cast(&DeviceBootloader::createDepthaiApplicationPackage), py::arg("pipeline"), py::arg("compress"), DOC(dai, DeviceBootloader, createDepthaiApplicationPackage, 2)) .def_static("getEmbeddedBootloaderVersion", &DeviceBootloader::getEmbeddedBootloaderVersion, DOC(dai, DeviceBootloader, getEmbeddedBootloaderVersion)) .def_static("getEmbeddedBootloaderBinary", &DeviceBootloader::getEmbeddedBootloaderBinary, DOC(dai, DeviceBootloader, getEmbeddedBootloaderBinary)) .def(py::init(), py::arg("devInfo"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader)) .def(py::init(), py::arg("devInfo"), py::arg("pathToCmd"), py::arg("allowFlashingBootloader") = false, DOC(dai, DeviceBootloader, DeviceBootloader, 2)) - .def("flash", [](DeviceBootloader& db, std::function progressCallback, Pipeline& pipeline) { py::gil_scoped_release release; return db.flash(progressCallback, pipeline); }, py::arg("progressCallback"), py::arg("pipeline"), DOC(dai, DeviceBootloader, flash)) + .def("flash", [](DeviceBootloader& db, std::function progressCallback, const Pipeline& pipeline, bool compress) { py::gil_scoped_release release; return db.flash(progressCallback, pipeline, compress); }, py::arg("progressCallback"), py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, flash)) + .def("flash", [](DeviceBootloader& db, const Pipeline& pipeline, bool compress) { py::gil_scoped_release release; return db.flash(pipeline, compress); }, py::arg("pipeline"), py::arg("compress") = false, DOC(dai, DeviceBootloader, flash, 2)) .def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::function progressCallback, std::vector package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(progressCallback, package); }, py::arg("progressCallback"), py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage)) + .def("flashDepthaiApplicationPackage", [](DeviceBootloader& db, std::vector package) { py::gil_scoped_release release; return db.flashDepthaiApplicationPackage(package); }, py::arg("package"), DOC(dai, DeviceBootloader, flashDepthaiApplicationPackage, 2)) .def("flashBootloader", [](DeviceBootloader& db, std::function progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(progressCallback, path); }, py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader)) .def("flashBootloader", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type, std::function progressCallback, std::string path) { py::gil_scoped_release release; return db.flashBootloader(memory, type, progressCallback, path); }, py::arg("memory"), py::arg("type"), py::arg("progressCallback"), py::arg("path") = "", DOC(dai, DeviceBootloader, flashBootloader, 2)) + + .def("readConfigData", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfigData(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfigData)) + .def("flashConfigData", [](DeviceBootloader& db, nlohmann::json configData, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigData(configData, memory, type); }, py::arg("configData"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigData)) + .def("flashConfigFile", [](DeviceBootloader& db, std::string configPath, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigFile(configPath, memory, type); }, py::arg("configData"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigFile)) + .def("flashConfigClear", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfigClear(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfigClear)) + .def("readConfig", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfig(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfig)) + .def("flashConfig", [](DeviceBootloader& db, const DeviceBootloader::Config& config, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfig(config, memory, type); }, py::arg("config"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfig)) + //.def("flashCustom", &DeviceBootloader::flashCustom, py::arg("memory"), py::arg("offset"), py::arg("progressCallback"), py::arg("data"), DOC(dai, DeviceBootloader, flashCustom)) .def("getVersion", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.getVersion(); }, DOC(dai, DeviceBootloader, getVersion)) diff --git a/src/pybind11_common.hpp b/src/pybind11_common.hpp index 8fbab8dd8..1669cdf40 100644 --- a/src/pybind11_common.hpp +++ b/src/pybind11_common.hpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include From 39871af4763a2434c091db3cd33c74aaef3816ae Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Sat, 21 Aug 2021 22:35:47 +0200 Subject: [PATCH 19/29] Updated flash_bootloader example --- depthai-core | 2 +- examples/flash_bootloader.py | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/depthai-core b/depthai-core index 93df9978e..6a414d4c0 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 93df9978e301265229ca8a613a47397cf5f3dc47 +Subproject commit 6a414d4c081903a748a3941aed9b6f1c400cb31f diff --git a/examples/flash_bootloader.py b/examples/flash_bootloader.py index d84ef1e4d..3ea3e6077 100755 --- a/examples/flash_bootloader.py +++ b/examples/flash_bootloader.py @@ -4,7 +4,7 @@ import sys import time -blType = dai.DeviceBootloader.Type.USB +blType = dai.DeviceBootloader.Type.AUTO if len(sys.argv) > 1: if sys.argv[1] == 'usb': blType = dai.DeviceBootloader.Type.USB @@ -13,9 +13,6 @@ else: print("Specify either 'usb' or 'network' bootloader type") exit() -else: - print(f"Usage: {sys.argv[0]} ") - exit() print("Warning! Flashing bootloader can potentially soft brick your device and should be done with caution.") print("Do not unplug your device while the bootloader is flashing.") @@ -30,11 +27,12 @@ exit(-1) # Open DeviceBootloader and allow flashing bootloader +print(f"Booting latest bootloader first, will take a tad longer...") with dai.DeviceBootloader(info, allowFlashingBootloader=True) as bl: currentBlType = bl.getType() # Check if bootloader type is the same - if currentBlType != blType: + if blType != dai.DeviceBootloader.Type.AUTO and currentBlType != blType: print(f"Are you sure you want to flash '{blType.name}' bootloader over current '{currentBlType.name}' bootloader?") print(f"Type 'y' and press enter to proceed, otherwise exits: ") if input() != 'y': @@ -44,9 +42,9 @@ # Create a progress callback lambda progress = lambda p : print(f'Flashing progress: {p*100:.1f}%') - print(f"Flashing {blType.name} bootloader...") + print(f"Flashing {currentBlType.name} bootloader...") startTime = time.monotonic() - (res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, blType, progress) + (res, message) = bl.flashBootloader(dai.DeviceBootloader.Memory.FLASH, currentBlType, progress) if res: print("Flashing successful. Took", time.monotonic() - startTime, "seconds") else: From 34d2993e0a371ab3057d7d1878b4a8e3511172ac Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 23 Aug 2021 05:28:44 +0200 Subject: [PATCH 20/29] Updated bindings and example name --- depthai-core | 2 +- examples/{bootloader_configuration.py => bootloader_config.py} | 0 src/DeviceBootloaderBindings.cpp | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) rename examples/{bootloader_configuration.py => bootloader_config.py} (100%) diff --git a/depthai-core b/depthai-core index 6a414d4c0..fb57b8978 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 6a414d4c081903a748a3941aed9b6f1c400cb31f +Subproject commit fb57b897826fb7feeb99522b5c63a2350764dde5 diff --git a/examples/bootloader_configuration.py b/examples/bootloader_config.py similarity index 100% rename from examples/bootloader_configuration.py rename to examples/bootloader_config.py diff --git a/src/DeviceBootloaderBindings.cpp b/src/DeviceBootloaderBindings.cpp index c9c7d1bea..a975bc10b 100644 --- a/src/DeviceBootloaderBindings.cpp +++ b/src/DeviceBootloaderBindings.cpp @@ -139,6 +139,9 @@ void DeviceBootloaderBindings::bind(pybind11::module& m, void* pCallstack){ .def("readConfig", [](DeviceBootloader& db, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.readConfig(memory, type); }, py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, readConfig)) .def("flashConfig", [](DeviceBootloader& db, const DeviceBootloader::Config& config, DeviceBootloader::Memory memory, DeviceBootloader::Type type) { py::gil_scoped_release release; return db.flashConfig(config, memory, type); }, py::arg("config"), py::arg("memory") = DeviceBootloader::Memory::AUTO, py::arg("type") = DeviceBootloader::Type::AUTO, DOC(dai, DeviceBootloader, flashConfig)) + .def("bootMemory", [](DeviceBootloader& db, const std::vector& fw) { py::gil_scoped_release release; return db.bootMemory(fw); }, py::arg("fw"), DOC(dai, DeviceBootloader, bootMemory)) + .def("bootUsbRomBootloader", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.bootUsbRomBootloader(); }, DOC(dai, DeviceBootloader, bootUsbRomBootloader)) + //.def("flashCustom", &DeviceBootloader::flashCustom, py::arg("memory"), py::arg("offset"), py::arg("progressCallback"), py::arg("data"), DOC(dai, DeviceBootloader, flashCustom)) .def("getVersion", [](DeviceBootloader& db) { py::gil_scoped_release release; return db.getVersion(); }, DOC(dai, DeviceBootloader, getVersion)) From dde13ab04e8f26c0ee3cc11920646ba9ea50cded Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 23 Aug 2021 20:38:01 +0200 Subject: [PATCH 21/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 23319c3a2..5dd1ec3e8 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 23319c3a25cd7d5cc43541b81d41b0c1922d429d +Subproject commit 5dd1ec3e8d06c2857bcf03c09650a758467a4599 From cb17db2175f669f13b549d05ef7ab6fbaf051cd3 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 23 Aug 2021 22:36:26 +0200 Subject: [PATCH 22/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 5dd1ec3e8..8071ddb6c 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 5dd1ec3e8d06c2857bcf03c09650a758467a4599 +Subproject commit 8071ddb6c4b2228c48c6eca11d0c400c3b3081d4 From ebabd54a0e9808aa4893c9b1566f1b3df1cd930d Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Wed, 25 Aug 2021 01:51:35 +0200 Subject: [PATCH 23/29] Added bindings for bootBootloader --- depthai-core | 2 +- src/XLinkConnectionBindings.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/depthai-core b/depthai-core index 8460ce791..24499d0c5 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 8460ce791a552616fd331285584c689ef2e77b97 +Subproject commit 24499d0c5e69ec3941a4fb7ea08116b058bc5508 diff --git a/src/XLinkConnectionBindings.cpp b/src/XLinkConnectionBindings.cpp index 07b9d37cf..9a74bd9f6 100644 --- a/src/XLinkConnectionBindings.cpp +++ b/src/XLinkConnectionBindings.cpp @@ -83,7 +83,7 @@ void XLinkConnectionBindings::bind(pybind11::module& m, void* pCallstack){ .def_static("getAllConnectedDevices", &XLinkConnection::getAllConnectedDevices, py::arg("state") = X_LINK_ANY_STATE) .def_static("getFirstDevice", &XLinkConnection::getFirstDevice, py::arg("state") = X_LINK_ANY_STATE) .def_static("getDeviceByMxId", &XLinkConnection::getDeviceByMxId, py::arg("mxId"), py::arg("state") = X_LINK_ANY_STATE) + .def_static("bootBootloader", &XLinkConnection::bootBootloader, py::arg("devInfo")) ; - } \ No newline at end of file From b591e255aec48da0225446b1d177698869d0218c Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 26 Aug 2021 00:31:29 +0200 Subject: [PATCH 24/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 24499d0c5..03bde90ec 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 24499d0c5e69ec3941a4fb7ea08116b058bc5508 +Subproject commit 03bde90ec81b9770ad6a66004633b6ebac4b804a From f9ec223c5396ccc857495ff05d199f040f3e46da Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 26 Aug 2021 16:21:44 +0200 Subject: [PATCH 25/29] Fixed incorrect constructors for DeviceBase --- src/DeviceBindings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DeviceBindings.cpp b/src/DeviceBindings.cpp index 9f616516f..d10b1e94c 100644 --- a/src/DeviceBindings.cpp +++ b/src/DeviceBindings.cpp @@ -208,7 +208,7 @@ void DeviceBindings::bind(pybind11::module& m, void* pCallstack){ ; // Bind constructors - bindConstructors(deviceBase); + bindConstructors(deviceBase); // Bind the rest deviceBase // Python only methods From da57c1b65ef60601baa99542143dc1d85361c5e5 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 26 Aug 2021 17:14:30 +0200 Subject: [PATCH 26/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index 03bde90ec..e9d9eeade 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 03bde90ec81b9770ad6a66004633b6ebac4b804a +Subproject commit e9d9eeade9133230c7e073e2edb7dbde51dc19f8 From 2ace2caf6a09ab513ac33b0513a4c2c0e8ed205a Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 2 Sep 2021 12:42:47 +0200 Subject: [PATCH 27/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index e9d9eeade..8c13909dd 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit e9d9eeade9133230c7e073e2edb7dbde51dc19f8 +Subproject commit 8c13909dd1f9798c2ea0ad467bd9bb0cbd7ec34b From cbee9c3f965011a73198715f2ef5ef21b8e5fdd2 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Thu, 2 Sep 2021 17:24:42 +0200 Subject: [PATCH 28/29] Added capability to not install signal handlers --- depthai-core | 2 +- src/py_bindings.cpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/depthai-core b/depthai-core index 8c13909dd..f375e951e 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit 8c13909dd1f9798c2ea0ad467bd9bb0cbd7ec34b +Subproject commit f375e951e0ce21998bc326845553f191a0013ac5 diff --git a/src/py_bindings.cpp b/src/py_bindings.cpp index 75bcf9ec7..7679692aa 100644 --- a/src/py_bindings.cpp +++ b/src/py_bindings.cpp @@ -59,8 +59,28 @@ PYBIND11_MODULE(depthai,m) // Initial call CommonBindings::bind(m, &callstackAdapter); + // Install signal handler option + bool installSignalHandler = true; + constexpr static const char* signalHandlerKey = "DEPTHAI_INSTALL_SIGNAL_HANDLER"; + try { + auto sysModule = py::module_::import("sys"); + if(py::hasattr(sysModule, signalHandlerKey)){ + installSignalHandler = installSignalHandler && sysModule.attr(signalHandlerKey).cast(); + } + } catch (...) { + // ignore + } + try { + auto builtinsModule = py::module_::import("builtins"); + if(py::hasattr(builtinsModule, signalHandlerKey)){ + installSignalHandler = installSignalHandler && builtinsModule.attr(signalHandlerKey).cast(); + } + } catch (...){ + // ignore + } + // Call dai::initialize on 'import depthai' to initialize asap with additional information to print - dai::initialize(std::string("Python bindings - version: ") + DEPTHAI_PYTHON_VERSION + " from " + DEPTHAI_PYTHON_COMMIT_DATETIME + " build: " + DEPTHAI_PYTHON_BUILD_DATETIME); + dai::initialize(std::string("Python bindings - version: ") + DEPTHAI_PYTHON_VERSION + " from " + DEPTHAI_PYTHON_COMMIT_DATETIME + " build: " + DEPTHAI_PYTHON_BUILD_DATETIME, installSignalHandler); } From 57b0e5bf0e3b97b21aabacd5d81058aebe386b68 Mon Sep 17 00:00:00 2001 From: TheMarpe Date: Mon, 6 Sep 2021 18:57:10 +0200 Subject: [PATCH 29/29] Updated core --- depthai-core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/depthai-core b/depthai-core index f375e951e..35e163a99 160000 --- a/depthai-core +++ b/depthai-core @@ -1 +1 @@ -Subproject commit f375e951e0ce21998bc326845553f191a0013ac5 +Subproject commit 35e163a9951badae16541f012f37bc5e2fe2c02c