tool: API and CLI for LED matrix mode

This commit is contained in:
Ian Douglas Scott 2021-02-25 14:41:58 -08:00 committed by Jeremy Soller
parent 73a5d8b8a1
commit b11bc64bba
5 changed files with 61 additions and 2 deletions

2
ecsim

@ -1 +1 @@
Subproject commit 19e16b1ce3e175b14665073a47ef8a446cb988d6
Subproject commit 3fd9b10bc7da755e9aa7507f37bfdb4fa6a532bb

2
ecspy

@ -1 +1 @@
Subproject commit 4be3d5169f627539875252b124a83038c63e911d
Subproject commit b3bde0a1be6a8e3e473f56f9bc94028a34ee8289

View File

@ -34,6 +34,10 @@ enum Command {
CMD_LED_GET_COLOR = 13,
// Set LED color by index
CMD_LED_SET_COLOR = 14,
// Get LED matrix mode and speed
CMD_LED_GET_MODE = 15,
// Set LED matrix mode and speed
CMD_LED_SET_MODE = 16,
//TODO
};

View File

@ -31,6 +31,8 @@ enum Cmd {
LedSetValue = 12,
LedGetColor = 13,
LedSetColor = 14,
LedGetMode = 15,
LedSetMode = 16,
}
const CMD_SPI_FLAG_READ: u8 = 1 << 0;
@ -247,6 +249,26 @@ impl<A: Access> Ec<A> {
self.command(Cmd::LedSetColor, &mut data)
}
pub unsafe fn led_get_mode(&mut self) -> Result<(u8, u8), Error> {
let mut data = [
0,
0,
];
self.command(Cmd::LedGetMode, &mut data)?;
Ok((
data[0],
data[1]
))
}
pub unsafe fn led_set_mode(&mut self, mode: u8, speed: u8) -> Result<(), Error> {
let mut data = [
mode,
speed,
];
self.command(Cmd::LedSetMode, &mut data)
}
pub fn into_dyn(self) -> Ec<Box<dyn Access>>
where A: 'static {
Ec {

View File

@ -329,6 +329,15 @@ fn main() {
.validator(validate_from_str::<u8>)
)
)
.subcommand(SubCommand::with_name("led_mode")
.arg(Arg::with_name("mode")
.validator(validate_from_str::<u8>)
.requires("speed")
)
.arg(Arg::with_name("speed")
.validator(validate_from_str::<u8>)
)
)
.subcommand(SubCommand::with_name("print")
.arg(Arg::with_name("message")
.required(true)
@ -503,6 +512,30 @@ fn main() {
}
}
},
("led_mode", Some(sub_m)) => {
let mode = sub_m.value_of("mode").map(|x| x.parse::<u8>().unwrap());
let speed = sub_m.value_of("speed").map(|x| x.parse::<u8>().unwrap());
if let (Some(mode), Some(speed)) = (mode, speed) {
match unsafe { ec.led_set_mode(mode, speed) } {
Ok(()) => (),
Err(err) => {
eprintln!("failed to set mode {} at speed {}: {:X?}", mode, speed, err);
process::exit(1);
},
}
} else {
match unsafe { ec.led_get_mode() } {
Ok((mode, speed)) => {
println!("mode: {}", mode);
println!("speed: {}", speed);
},
Err(err) => {
eprintln!("failed to get mode: {:X?}", err);
process::exit(1);
},
}
}
},
("print", Some(sub_m)) => for arg in sub_m.values_of("message").unwrap() {
let mut arg = arg.to_owned();
arg.push('\n');