mirror of
https://github.com/OpenBluetoothToolbox/SimpleBLE
synced 2025-10-14 02:08:22 +08:00
Python Fixes
This commit is contained in:
@@ -18,15 +18,15 @@ The format is based on `Keep a Changelog`_, and this project adheres to `Semanti
|
||||
|
||||
**Changed**
|
||||
|
||||
-
|
||||
- (SimpleDBus) Interface creation is now done via a registry.
|
||||
|
||||
**Fixed**
|
||||
|
||||
-
|
||||
- (Python) Fixed GIL issues introduced in v0.10.2.
|
||||
|
||||
**Removed**
|
||||
|
||||
-
|
||||
-
|
||||
|
||||
|
||||
[0.10.2] - 2025-06-20
|
||||
|
@@ -143,7 +143,9 @@ void wrap_peripheral(py::module& m) {
|
||||
.def(
|
||||
"read",
|
||||
[](SimpleBLE::Peripheral& p, std::string const& service, std::string const& characteristic) {
|
||||
return py::bytes(p.read(service, characteristic));
|
||||
SimpleBLE::ByteArray cpp_payload = p.read(service, characteristic);
|
||||
py::gil_scoped_acquire gil;
|
||||
return py::bytes(cpp_payload);
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
kDocsPeripheralReadCharacteristic)
|
||||
@@ -155,7 +157,6 @@ void wrap_peripheral(py::module& m) {
|
||||
py::gil_scoped_release release;
|
||||
p.write_request(service, characteristic, cpp_payload);
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
kDocsPeripheralWriteRequest)
|
||||
.def(
|
||||
"write_command",
|
||||
@@ -165,7 +166,6 @@ void wrap_peripheral(py::module& m) {
|
||||
py::gil_scoped_release release;
|
||||
p.write_command(service, characteristic, cpp_payload);
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
kDocsPeripheralWriteCommand)
|
||||
.def(
|
||||
"notify",
|
||||
@@ -192,7 +192,9 @@ void wrap_peripheral(py::module& m) {
|
||||
.def(
|
||||
"descriptor_read",
|
||||
[](SimpleBLE::Peripheral& p, std::string const& service, std::string const& characteristic, std::string const& descriptor) {
|
||||
return py::bytes(p.read(service, characteristic, descriptor));
|
||||
SimpleBLE::ByteArray cpp_payload = p.read(service, characteristic, descriptor);
|
||||
py::gil_scoped_acquire gil;
|
||||
return py::bytes(cpp_payload);
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
kDocsPeripheralDescriptorRead)
|
||||
@@ -200,13 +202,14 @@ void wrap_peripheral(py::module& m) {
|
||||
"descriptor_write",
|
||||
[](SimpleBLE::Peripheral& p, std::string service, std::string characteristic, std::string const& descriptor, py::bytes payload) {
|
||||
// Note py::bytes implicitly converts to std::string
|
||||
p.write(service, characteristic, descriptor, SimpleBLE::ByteArray(payload));
|
||||
SimpleBLE::ByteArray cpp_payload(payload);
|
||||
py::gil_scoped_release release;
|
||||
p.write(service, characteristic, descriptor, cpp_payload);
|
||||
},
|
||||
py::call_guard<py::gil_scoped_release>(),
|
||||
kDocsPeripheralDescriptorWrite)
|
||||
|
||||
.def("set_callback_on_connected", &SimpleBLE::Peripheral::set_callback_on_connected, py::keep_alive<1, 2>(),
|
||||
kDocsPeripheralSetCallbackOnConnected)
|
||||
.def("set_callback_on_connected", &SimpleBLE::Peripheral::set_callback_on_connected,
|
||||
py::keep_alive<1, 2>(), kDocsPeripheralSetCallbackOnConnected)
|
||||
.def("set_callback_on_disconnected", &SimpleBLE::Peripheral::set_callback_on_disconnected,
|
||||
py::keep_alive<1, 2>(), kDocsPeripheralSetCallbackOnDisconnected);
|
||||
}
|
||||
|
Reference in New Issue
Block a user