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],
);