Bargraph

Struct 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>,

Source

pub fn new<L>(i2c: I2C, i2c_address: u8, logger: L) -> Self
where L: Into<Option<Logger>>,

Create a Bargraph for display.

§Arguments
  • device - A connected HT16K33 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);
Source

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();
Source

pub fn clear(&mut self) -> Result<(), E>

Clear the Bargraph display.

§Examples

let mut bargraph = Bargraph::new(i2c, address, None);
bargraph.clear().unwrap();
Source

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 from 0.
  • range - Total number of values to display.
§Examples

let mut bargraph = Bargraph::new(i2c, address, None);
bargraph.update(5, 6, false).unwrap();

Enable/Disable continuous blinking of the Bargraph display.

§Arguments
  • enabled - Whether to enabled blinking or not.
§Examples

let mut bargraph = Bargraph::new(i2c, address, None);
bargraph.set_blink(true).unwrap();
Source

pub fn show(&mut self) -> Result<(), E>

Show the current bargraph display on-screen.

§Examples

let mut bargraph = Bargraph::new(i2c, address, None);
bargraph.show().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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<T> SendSyncUnwindSafe for T
where T: Send + Sync + UnwindSafe + ?Sized,