pub struct BatteryWiring {
pub part: Part,
pub bus: String,
pub address: Option<u8>,
pub empty_volts: f32,
pub full_volts: f32,
}Expand description
The battery the node runs from, read as a voltage to set how often it samples.
A node with none samples at its profile’s active cadence, as on mains power.
Fields§
§part: PartThe power monitor across the battery: ina219 or ina226.
bus: StringThe I2C bus the monitor is on, or sim.
address: Option<u8>The monitor’s I2C address, when it is not the part’s usual one.
empty_volts: f32The voltage the battery reads when it is empty.
full_volts: f32The voltage the battery reads when it is full.
Implementations§
Source§impl BatteryWiring
impl BatteryWiring
Sourcepub fn charge(&self, volts: f32) -> f32
pub fn charge(&self, volts: f32) -> f32
Turns the battery’s voltage into a state of charge.
§Arguments
volts- the voltage the monitor read.
§Returns
The charge from 0 to 1, on a straight line from empty to full; a reading outside the two is held to the nearer end.
§Examples
use pamoja_profile::wiring::{BatteryWiring, Part};
let battery = BatteryWiring {
part: Part::Ina219,
bus: "/dev/i2c-1".to_owned(),
address: None,
empty_volts: 3.3,
full_volts: 4.2,
};
assert!((battery.charge(3.75) - 0.5).abs() < 1e-6);
assert_eq!(battery.charge(5.0), 1.0);Trait Implementations§
Source§impl Clone for BatteryWiring
impl Clone for BatteryWiring
Source§fn clone(&self) -> BatteryWiring
fn clone(&self) -> BatteryWiring
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for BatteryWiring
impl Debug for BatteryWiring
Source§impl<'de> Deserialize<'de> for BatteryWiring
impl<'de> Deserialize<'de> for BatteryWiring
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl PartialEq for BatteryWiring
impl PartialEq for BatteryWiring
Source§impl Serialize for BatteryWiring
impl Serialize for BatteryWiring
impl StructuralPartialEq for BatteryWiring
Auto Trait Implementations§
impl Freeze for BatteryWiring
impl RefUnwindSafe for BatteryWiring
impl Send for BatteryWiring
impl Sync for BatteryWiring
impl Unpin for BatteryWiring
impl UnsafeUnpin for BatteryWiring
impl UnwindSafe for BatteryWiring
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more