Skip to main content

Crate ql_sleep

Crate ql_sleep 

Expand description

Pure Rust wake locks and autosleep control for the Quectel AG35.

This replaces the sleep part of Quectel’s libql_common_api (Ql_SLP_WakeLock_* and Ql_Autosleep_Enable).

A WakeLock is a file descriptor of /proc/quec_wakelock. Locking and unlocking are ioctls on it. Autosleep writes to /sys/power/autosleep.

§Example

use ql_sleep::{Autosleep, WakeLock, WakeLockName};

let wake_lock = WakeLock::new(WakeLockName::new("my-app")?)?;
wake_lock.lock()?;
Autosleep::new().enable()?;
// The system stays awake until the lock is released.
wake_lock.unlock()?;

§Dropping a wake lock

Dropping a WakeLock closes the file descriptor. When the last reference to the open file is gone, the kernel releases and deletes the lock and turns autosleep off for the whole system. This happens when any process drops any wake lock, even one that didn’t enable autosleep. It keeps the system awake after a process exits.

A duplicated descriptor or one that a child inherited through fork keeps the lock alive until it is closed too. The descriptor is close-on-exec, so programs started with exec don’t keep it.

Like a write to the autosleep file, the last close can block until the kernel has aborted a running suspend attempt. Other wake lock calls wait until it finishes.

Create one wake lock before enabling autosleep and keep it for as long as autosleep must stay enabled. Use WakeLock::lock and WakeLock::unlock instead of creating short-lived wake locks. Enable autosleep again after any wake lock was dropped.

Modules§

autosleep 🔒
error 🔒
wake_lock 🔒

Structs§

Autosleep
Control of the kernel’s autosleep feature.
WakeLock
A kernel wake lock that keeps the system awake while locked.
WakeLockName
A validated wake lock name.

Enums§

Error
Error returned by sleep operations.
NameError
Error returned for an invalid wake lock name.