From 0600d433a79498b13d5cc06a189f283f58dcd714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franti=C5=A1ek=20Boh=C3=A1=C4=8Dek?= Date: Wed, 21 Jun 2023 12:13:17 +0200 Subject: [PATCH] feat: add reset command --- src/commands/reset_command.rs | 25 +++++++++++++++++++++++++ src/main.rs | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 src/commands/reset_command.rs diff --git a/src/commands/reset_command.rs b/src/commands/reset_command.rs new file mode 100644 index 0000000000000000000000000000000000000000..7f7d9311c52c80e209481bf51f0dc6476efba33c --- /dev/null +++ b/src/commands/reset_command.rs @@ -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 diff --git a/src/main.rs b/src/main.rs index f4041eb420e53c93da7eed4ecd8d9cd624e7c5e0..9447073764610803f1a8542587c959f2efd96e4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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], );