Skip to content

Commit ab6ece1

Browse files
authored
Merge pull request #9 from bitcraze/evoggy/nrf-pm-commands
Added STM32 power on/off and system off commands
2 parents c28f957 + b32d1aa commit ab6ece1

4 files changed

Lines changed: 79 additions & 3 deletions

File tree

cflib2/_rust.pyi

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,37 @@ class Crazyflie:
320320
Returns:
321321
Connected Crazyflie instance
322322
"""
323+
@staticmethod
324+
async def power_off_stm32_domain(
325+
link_context: LinkContext, uri: builtins.str
326+
) -> None:
327+
r"""
328+
Power off the STM32 and deck subsystem
329+
330+
Cuts power to the STM32 and decks while keeping the nRF51 powered.
331+
The Crazyflie can be powered on again using `power_on_stm32_domain()`.
332+
This does not require a full connection.
333+
"""
334+
@staticmethod
335+
async def power_on_stm32_domain(
336+
link_context: LinkContext, uri: builtins.str
337+
) -> None:
338+
r"""
339+
Power on the STM32 and deck subsystem
340+
341+
Powers the STM32 and decks back on after a `power_off_stm32_domain()`.
342+
This does not require a full connection.
343+
"""
344+
@staticmethod
345+
async def power_off_all(link_context: LinkContext, uri: builtins.str) -> None:
346+
r"""
347+
Power off the Crazyflie completely
348+
349+
Powers off the nRF51, STM32, and deck subsystem. Equivalent to
350+
pressing the power button. The Crazyflie cannot be woken up via
351+
radio after this.
352+
This does not require a full connection.
353+
"""
323354
async def disconnect(self) -> None:
324355
r"""
325356
Disconnect from the Crazyflie

rust/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ extension-module = ["pyo3/extension-module"]
1414
[dependencies]
1515
pyo3 = { version = "0.26" }
1616
pyo3-async-runtimes = { version = "0.26", features = ["tokio-runtime"] }
17-
crazyflie-lib = "0.6.0"
17+
crazyflie-lib = "0.7.1"
1818
crazyflie-link = "0.4.2"
1919
tokio = { version = "1.48", features = ["full"] }
2020
futures = "0.3.31"

rust/src/crazyflie.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,51 @@ impl Crazyflie {
124124
})
125125
}
126126

127+
/// Power off the STM32 and deck subsystem
128+
///
129+
/// Cuts power to the STM32 and decks while keeping the nRF51 powered.
130+
/// The Crazyflie can be powered on again using `power_on_stm32_domain()`.
131+
/// This does not require a full connection.
132+
#[staticmethod]
133+
#[gen_stub(override_return_type(type_repr = "collections.abc.Coroutine[typing.Any, typing.Any, None]"))]
134+
fn power_off_stm32_domain<'py>(py: Python<'py>, link_context: &LinkContext, uri: String) -> PyResult<Bound<'py, PyAny>> {
135+
let inner = link_context.inner.clone();
136+
pyo3_async_runtimes::tokio::future_into_py(py, async move {
137+
crazyflie_lib::Crazyflie::power_off_stm32_domain(&inner, &uri).await.map_err(to_pyerr)?;
138+
Ok(())
139+
})
140+
}
141+
142+
/// Power on the STM32 and deck subsystem
143+
///
144+
/// Powers the STM32 and decks back on after a `power_off_stm32_domain()`.
145+
/// This does not require a full connection.
146+
#[staticmethod]
147+
#[gen_stub(override_return_type(type_repr = "collections.abc.Coroutine[typing.Any, typing.Any, None]"))]
148+
fn power_on_stm32_domain<'py>(py: Python<'py>, link_context: &LinkContext, uri: String) -> PyResult<Bound<'py, PyAny>> {
149+
let inner = link_context.inner.clone();
150+
pyo3_async_runtimes::tokio::future_into_py(py, async move {
151+
crazyflie_lib::Crazyflie::power_on_stm32_domain(&inner, &uri).await.map_err(to_pyerr)?;
152+
Ok(())
153+
})
154+
}
155+
156+
/// Power off the Crazyflie completely
157+
///
158+
/// Powers off the nRF51, STM32, and deck subsystem. Equivalent to
159+
/// pressing the power button. The Crazyflie cannot be woken up via
160+
/// radio after this.
161+
/// This does not require a full connection.
162+
#[staticmethod]
163+
#[gen_stub(override_return_type(type_repr = "collections.abc.Coroutine[typing.Any, typing.Any, None]"))]
164+
fn power_off_all<'py>(py: Python<'py>, link_context: &LinkContext, uri: String) -> PyResult<Bound<'py, PyAny>> {
165+
let inner = link_context.inner.clone();
166+
pyo3_async_runtimes::tokio::future_into_py(py, async move {
167+
crazyflie_lib::Crazyflie::power_off_all(&inner, &uri).await.map_err(to_pyerr)?;
168+
Ok(())
169+
})
170+
}
171+
127172
/// Disconnect from the Crazyflie
128173
#[gen_stub(override_return_type(type_repr = "collections.abc.Coroutine[typing.Any, typing.Any, None]"))]
129174
fn disconnect<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {

0 commit comments

Comments
 (0)