~ruther/map-led-strip

0600d433a79498b13d5cc06a189f283f58dcd714 — František Boháček 1 year, 9 months ago 6c35100
feat: add reset command
2 files changed, 27 insertions(+), 0 deletions(-)

A src/commands/reset_command.rs
M src/main.rs
A src/commands/reset_command.rs => src/commands/reset_command.rs +25 -0
@@ 0,0 1,25 @@
use crate::commands::command_handler::{CommandData, CommandHandleError, SpecificCommandHandler};
use crate::commands::command_handler::CommandHandleError::WrongArguments;

pub struct ResetCommand {}

impl ResetCommand {
    pub fn new() -> Self {
        Self {}
    }
}

impl SpecificCommandHandler for ResetCommand {
    fn handle(&self, command: &mut CommandData) -> Result<(), CommandHandleError> {
        for led in command.map.get_map_mut() {
            led.r = 0;
            led.g = 0;
            led.b = 0;
        }
        Ok(())
    }

    fn help(&self) -> &'static str {
        "- Resets the board, all leds set to 0, 0, 0"
    }
}
\ No newline at end of file

M src/main.rs => src/main.rs +2 -0
@@ 94,10 94,12 @@ fn main() -> ! {

    let world_command = HelloWorldCommand::new();
    let set_command = SetCommand::new();
    let reset_command = ResetCommand::new();
    let mut handler = CommandHandler::new(
        [
            ("HELLO_WORLD", &world_command),
            ("SET", &set_command),
            ("RESET", &reset_command),
        ],
        ['\0'; COMMAND_BUFFER],
    );

Do not follow this link