tm1637_embedded_hal/options/circles/
default_options.rsuse crate::{
maybe_flipped::MaybeFlipped,
options::{repeat::RepeatDisplayOptions, scroll::Scroller, DisplayOptions},
TM1637,
};
use super::{bits::RotatingCircleBits, RotatingDirection};
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct RotatingCircleOptions<'d, const N: usize, T, CLK, DIO, DELAY, M> {
device: &'d mut TM1637<N, T, CLK, DIO, DELAY>,
position: usize,
delay_ms: u32,
direction: RotatingDirection,
_flip: M,
}
impl<'d, const N: usize, T, CLK, DIO, DELAY, M>
RotatingCircleOptions<'d, N, T, CLK, DIO, DELAY, M>
{
pub fn new(
device: &'d mut TM1637<N, T, CLK, DIO, DELAY>,
position: usize,
delay_ms: u32,
direction: RotatingDirection,
flip: M,
) -> Self {
Self {
device,
position,
delay_ms,
direction,
_flip: flip,
}
}
pub fn new_with_defaults(device: &'d mut TM1637<N, T, CLK, DIO, DELAY>, flip: M) -> Self {
Self::new(device, 0, 500, RotatingDirection::Clockwise, flip)
}
pub const fn position(mut self, position: usize) -> Self {
self.position = position;
self
}
pub const fn delay_ms(mut self, delay_ms: u32) -> Self {
self.delay_ms = delay_ms;
self
}
pub const fn direction(mut self, direction: RotatingDirection) -> Self {
self.direction = direction;
self
}
pub fn flip(self) -> RotatingCircleOptions<'d, N, T, CLK, DIO, DELAY, impl MaybeFlipped<N>>
where
M: MaybeFlipped<N>,
{
RotatingCircleOptions {
device: self.device,
position: self.position,
delay_ms: self.delay_ms,
direction: self.direction,
_flip: M::flip(),
}
}
pub fn finish(
self,
) -> Scroller<
'd,
N,
T,
CLK,
DIO,
DELAY,
impl Iterator<Item = impl DoubleEndedIterator<Item = u8> + ExactSizeIterator>,
M,
> {
let bytes = match self.direction {
RotatingDirection::Clockwise => RotatingCircleBits::all_u8_reversed(),
RotatingDirection::CounterClockwise => RotatingCircleBits::all_u8(),
};
RepeatDisplayOptions::new(
DisplayOptions {
device: self.device,
position: self.position,
iter: bytes.into_iter(),
_flip: self._flip,
},
self.delay_ms,
)
.finish()
}
}