Struct led_bargraph::Bargraph
source · pub struct Bargraph<I2C> { /* private fields */ }
Expand description
The bargraph state.
Implementations§
source§impl<I2C, E> Bargraph<I2C>where
I2C: Write<Error = E> + WriteRead<Error = E>,
impl<I2C, E> Bargraph<I2C>where
I2C: Write<Error = E> + WriteRead<Error = E>,
sourcepub fn new<L>(i2c: I2C, i2c_address: u8, logger: L) -> Selfwhere
L: Into<Option<Logger>>,
pub fn new<L>(i2c: I2C, i2c_address: u8, logger: L) -> Selfwhere
L: Into<Option<Logger>>,
Create a Bargraph for display.
Arguments
device
- A connectedHT16K33
device 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();