From b7e43afe1dd99a6454be3c355d038bd228571ba2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Sun, 25 Jun 2023 20:19:35 +0200 Subject: [PATCH] feat: add map clear --- src/commands/command_data.rs | 2 +- src/commands/set_command.rs | 2 +- src/map.rs | 8 ++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/commands/command_data.rs b/src/commands/command_data.rs index 8d1aff09d9445a110a684b843b1a908e4c2ed2d3..ce6d607155b9ae244ad5b0b73aabd4866ff71007 100644 --- a/src/commands/command_data.rs +++ b/src/commands/command_data.rs @@ -29,7 +29,7 @@ impl<'d, 'a> CommandData<'d, 'a> { self.map } - pub fn deconstruct(self) -> (&'d Command<'d>, &'d mut Map<'a>) { + pub fn deconstruct_map(self) -> (&'d Command<'d>, &'d mut Map<'a>) { (self.command, self.map) } diff --git a/src/commands/set_command.rs b/src/commands/set_command.rs index 54e52e3722b2949098523488bdfe675c3bb088c4..52f6c76ee922d8165736f045b0e94d0e1daf7fe5 100644 --- a/src/commands/set_command.rs +++ b/src/commands/set_command.rs @@ -8,7 +8,7 @@ pub struct SetCommand; impl SpecificCommandHandler for SetCommand { fn handle(&self, command: CommandData) -> Result<(), CommandHandleError> { - let (cmd, map) = command.deconstruct(); + let (cmd, map) = command.deconstruct_map(); if cmd.parsed_arguments().len() < 5 { println!("Less than 5 args."); diff --git a/src/map.rs b/src/map.rs index f7dbb0f865cb0549288c7f95406b2f4cdaa6721f..9bf190af41b88222f74a9df8e76ef35d803efb47 100644 --- a/src/map.rs +++ b/src/map.rs @@ -138,6 +138,14 @@ impl<'d> Map<'d> { self.set_rgb(index, r, g, b) } + pub fn clear(&mut self) { + for led in self.get_map_mut() { + led.r = 0; + led.g = 0; + led.b = 0; + } + } + pub fn get_map(&self) -> Iter { return self.data.iter(); }