Device: Allow skipping of device state refreshing on call to open

This commit is contained in:
Max Brombach
2026-11-03 11:20:04 -05:00
committed by Kyle Schwarz
parent dffb0bcefb
commit 645549193d
21 changed files with 124 additions and 166 deletions
@@ -1,6 +1,7 @@
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
#include <pybind11/functional.h>
#include <pybind11/native_enum.h>
#include "icsneo/device/extensions/bootloader/api.h"
#include "icsneo/device/extensions/bootloader/parser/fwloader.h"
@@ -19,16 +20,21 @@ void init_bootloader(pybind11::module_& m) {
pybind11::classh<Bootloader::FWLoader>(bootloader, "FWLoader")
.def_static("load", &Bootloader::FWLoader::Load, pybind11::arg("path"), pybind11::call_guard<pybind11::gil_scoped_release>());
pybind11::native_enum<Bootloader::StatusType>(bootloader, "StatusType", "enum.IntEnum")
.value("Progress", Bootloader::StatusType::Progress)
.value("Failed", Bootloader::StatusType::Failed)
.finalize();
bootloader.def_static("update",
[](Device& device, const Bootloader::FWRepo& fw, Bootloader::Logger logger, bool alreadyInBootloader, bool forceFlash) {
if(!logger) {
logger = [](Device::OpenStatusType, const std::string&, std::optional<double>) { return Device::OpenDirective::Continue; };
[](Device& device, const Bootloader::FWRepo& fw, Bootloader::StatusHandler statusHandler, bool alreadyInBootloader, bool forceFlash) {
if(!statusHandler) {
statusHandler = [](Bootloader::StatusType, const std::string&, std::optional<double>) {};
}
return Bootloader::update(device, fw, logger, alreadyInBootloader, forceFlash);
return Bootloader::update(device, fw, statusHandler, alreadyInBootloader, forceFlash);
},
pybind11::arg("device"),
pybind11::arg("fw"),
pybind11::arg("logger") = pybind11::none(),
pybind11::arg("statusHandler") = pybind11::none(),
pybind11::arg("already_in_bootloader") = false,
pybind11::arg("force_flash") = false,
pybind11::call_guard<pybind11::gil_scoped_release>());
@@ -15,19 +15,6 @@ namespace icsneo {
void init_device(pybind11::module_& m) {
pybind11::classh<Device> device(m, "Device");
pybind11::native_enum<Device::OpenDirective>(device, "OpenDirective", "enum.IntEnum")
.value("Continue", Device::OpenDirective::Continue)
.value("Cancel", Device::OpenDirective::Cancel)
.value("Skip", Device::OpenDirective::Skip)
.finalize();
pybind11::native_enum<Device::OpenStatusType>(device, "OpenStatusType", "enum.IntEnum")
.value("QuestionContinueSkipCancel", Device::OpenStatusType::QuestionContinueSkipCancel)
.value("QuestionContinueCancel", Device::OpenStatusType::QuestionContinueCancel)
.value("Progress", Device::OpenStatusType::Progress)
.value("Failed", Device::OpenStatusType::Failed)
.finalize();
device
.def("__repr__", &Device::describe)
.def("add_message_callback", &Device::addMessageCallback, pybind11::call_guard<pybind11::gil_scoped_release>())