pub struct Bargraph<I2C> { /* private fields */ }Expand description
The bargraph state.
Implementations§
Source§impl<I2C, E> Bargraph<I2C>
impl<I2C, E> Bargraph<I2C>
Sourcepub fn new<L>(i2c: I2C, i2c_address: u8, logger: L) -> Self
pub fn new<L>(i2c: I2C, i2c_address: u8, logger: L) -> Self
Create a Bargraph for display.
§Arguments
device- A connectedHT16K33device that drives the display.logger- A logging instance.
§Notes
logger = None will log to the slog-stdlog drain. This makes the
library effectively work the same as if it was just using log instead
of slog.
§Examples
// NOTE: `None is used for the Logger in these examples for convenience,
// in practice using an actual logger in preferred.
extern crate ht16k33;
extern crate led_bargraph;
use ht16k33::i2c_mock::I2cMock;
use led_bargraph::Bargraph;
// Create an I2C device.
let mut i2c = I2cMock::new(None);
// The I2C device address.
let address: u8 = 0;
let mut bargraph = Bargraph::new(i2c, address, None);
Sourcepub fn initialize(&mut self) -> Result<(), E>
pub fn initialize(&mut self) -> Result<(), E>
Initialize the Bargraph display & the connected HT16K33 device.
§Examples
let mut bargraph = Bargraph::new(i2c, address, None);
bargraph.initialize().unwrap();
Sourcepub fn clear(&mut self) -> Result<(), E>
pub fn clear(&mut self) -> Result<(), E>
Clear the Bargraph display.
§Examples
let mut bargraph = Bargraph::new(i2c, address, None);
bargraph.clear().unwrap();
Sourcepub fn update(&mut self, value: u8, range: u8, show: bool) -> Result<(), E>
pub fn update(&mut self, value: u8, range: u8, show: bool) -> Result<(), E>
Update the Bargraph display, showing range total values with all values
from 0 to value filled.
If value is greater than range, then all bars are filled and will blink;
automatic re-scaling of the range does not happen because:
- The bargraph can only scale to a maximum resolution.
- Users are already familiar with viewing the current range, and dynamically changing the range makes it hard for users to see what’s happening at a glance.
§Arguments
value- How many values to fill, starting from0.range- Total number of values to display.
§Examples
let mut bargraph = Bargraph::new(i2c, address, None);
bargraph.update(5, 6, false).unwrap();
Auto Trait Implementations§
impl<I2C> Freeze for Bargraph<I2C>where
I2C: Freeze,
impl<I2C> RefUnwindSafe for Bargraph<I2C>where
I2C: RefUnwindSafe,
impl<I2C> Send for Bargraph<I2C>where
I2C: Send,
impl<I2C> Sync for Bargraph<I2C>where
I2C: Sync,
impl<I2C> Unpin for Bargraph<I2C>where
I2C: Unpin,
impl<I2C> UnwindSafe for Bargraph<I2C>where
I2C: UnwindSafe,
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