LowBatteryDetector

Struct LowBatteryDetector 

Source
pub struct LowBatteryDetector { /* private fields */ }
Expand description

Tracks consecutive low-battery samples and emits a PowerIntent::PowerOff once the streak crosses the configured threshold while the device is not USB-powered.

Matches the Meshtastic behavior documented in docs/hardware/t1000e-hardware.md: the T1000-E has no confirmed hardware undervoltage cutoff, so firmware must protect the Li-ion cell by shutting down before the voltage falls too far below the OCV table’s 3.1 V floor.

Implementations§

Source§

impl LowBatteryDetector

Source

pub fn new(threshold_mv: u16, streak_required: u8) -> Self

Create a detector. threshold_mv is the floor (samples strictly below this count toward the streak); streak_required is the number of consecutive low samples while not USB-powered needed to fire.

Source

pub fn t1000e_default() -> Self

Default per the T1000-E plan: 3.1 V floor, 10-sample streak.

Source

pub fn observe( &mut self, sample_mv: u16, usb_powered: bool, ) -> Option<PowerIntent>

Feed one sample. Returns PowerIntent::PowerOff the first time the streak crosses the threshold; subsequent calls return None until reset is called. This lets the power task act on a single fire and ignore further samples while it tears down.

Source

pub fn streak(&self) -> u8

Number of consecutive low-while-on-battery samples seen so far.

Source

pub fn fired(&self) -> bool

True once the detector has fired and is suppressing further events.

Source

pub fn reset(&mut self)

Re-arm the detector (clears the fired flag and the streak).

Trait Implementations§

Source§

impl Debug for LowBatteryDetector

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.