~ruther/map-led-strip

b7e43afe1dd99a6454be3c355d038bd228571ba2 — František Boháček 1 year, 9 months ago 6327e31
feat: add map clear
3 files changed, 10 insertions(+), 2 deletions(-)

M src/commands/command_data.rs
M src/commands/set_command.rs
M src/map.rs
M src/commands/command_data.rs => src/commands/command_data.rs +1 -1
@@ 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)
    }


M src/commands/set_command.rs => src/commands/set_command.rs +1 -1
@@ 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.");

M src/map.rs => src/map.rs +8 -0
@@ 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<RGB8> {
        return self.data.iter();
    }

Do not follow this link