~ruther/map-led-strip

4fd54179cb610352ddd5b07ea9742994cc65aee8 — František Boháček 1 year, 9 months ago 8ae60cc
feat: add hello world command
2 files changed, 35 insertions(+), 0 deletions(-)

A src/commands/hello_world_command.rs
M src/main.rs
A src/commands/hello_world_command.rs => src/commands/hello_world_command.rs +32 -0
@@ 0,0 1,32 @@
use embedded_hal::serial::{Read, Write};
use esp_println::{print, println};
use crate::command_handler::{CommandData, CommandHandleError, SpecificCommandHandler};
use crate::map::Map;

pub struct HelloWorldCommand {

}

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

impl SpecificCommandHandler for HelloWorldCommand
{
    fn handle(&self, command: &mut CommandData) -> Result<(), CommandHandleError>
    {
        print!("Hello world!");
        for c in &command.command.full[command.command.parsed_arguments[0].data.len()..] {
            print!("{}", c);
        }
        println!("\r");

        Ok(())
    }

    fn help(&self) -> &'static str {
        "<x> - prints Hello world! <x>"
    }
}
\ No newline at end of file

M src/main.rs => src/main.rs +3 -0
@@ 91,8 91,11 @@ fn main() -> ! {

    let mut rgb_data: [RGB8; 72] = [RGB8 { r: 0, g: 0, b: 0 }; 72];
    let mut map = map::Map::new(&map::INDEX_MAP, &mut rgb_data);

    let world_command = HelloWorldCommand::new();
    let mut handler = CommandHandler::new(
        [
            ("HELLO_WORLD", &world_command),
        ],
        ['\0'; COMMAND_BUFFER],
    );

Do not follow this link