Skip to content

Commit

Permalink
Make VirtualLed copyable
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Aug 30, 2023
1 parent 27cce02 commit f09b9ff
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,37 +257,29 @@ impl BlinkingLedsTicker {
/// Virtual LED
///
/// For displaying virtual LEDs or illuminated buttons in the UI.
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct VirtualLed {
pub state: LedState,
pub output: LedOutput,
}

impl VirtualLed {
#[must_use]
pub const fn new() -> Self {
Self {
state: LedState::Off,
output: LedOutput::Off,
}
}
}

impl Default for VirtualLed {
fn default() -> Self {
Self::new()
}
}
pub const OFF: Self = Self::initial_state(LedState::Off);

impl VirtualLed {
pub fn update_state(&mut self, new_state: LedState) {
let Self { state, output } = self;
*state = new_state;
*output = new_state.initial_output();
#[must_use]
pub const fn initial_state(state: LedState) -> Self {
let output = state.initial_output();
Self { state, output }
}

pub fn update_blinking_output(&mut self, blinking_leds_output: BlinkingLedsOutput) {
let Self { state, output } = self;
*output = state.output(blinking_leds_output);
}
}

impl Default for VirtualLed {
fn default() -> Self {
Self::OFF
}
}

0 comments on commit f09b9ff

Please sign in to comment.