This commit is contained in:
parent
8390b739da
commit
442da63c90
10
src/cli.rs
10
src/cli.rs
|
@ -1,5 +1,5 @@
|
||||||
#[derive(clap::Parser, std::fmt::Debug)]
|
#[derive(clap::Parser, std::fmt::Debug)]
|
||||||
#[clap(version)]
|
#[clap(version, arg_required_else_help = true)]
|
||||||
pub struct Cli {
|
pub struct Cli {
|
||||||
#[arg(
|
#[arg(
|
||||||
short,
|
short,
|
||||||
|
@ -19,7 +19,7 @@ pub struct Cli {
|
||||||
#[clap(subcommand)]
|
#[clap(subcommand)]
|
||||||
pub command: Mode,
|
pub command: Mode,
|
||||||
#[clap(short, long, help = "verbose logging")]
|
#[clap(short, long, help = "verbose logging")]
|
||||||
pub verbose: bool
|
pub verbose: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(clap::Parser, std::fmt::Debug)]
|
#[derive(clap::Parser, std::fmt::Debug)]
|
||||||
|
@ -48,6 +48,12 @@ pub enum PixelCommand {
|
||||||
pub enum BrightnessCommand {
|
pub enum BrightnessCommand {
|
||||||
#[command(visible_alias = "r")]
|
#[command(visible_alias = "r")]
|
||||||
Reset,
|
Reset,
|
||||||
|
#[command(visible_alias = "s")]
|
||||||
|
Set {
|
||||||
|
brightness: u8,
|
||||||
|
},
|
||||||
|
Min,
|
||||||
|
Max,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(clap::ValueEnum, Clone, Debug)]
|
#[derive(clap::ValueEnum, Clone, Debug)]
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
use crate::cli::{BrightnessCommand, Mode, PixelCommand};
|
||||||
use log::info;
|
use log::info;
|
||||||
use servicepoint::{Brightness, Command, Connection};
|
use servicepoint::{Brightness, Command, Connection};
|
||||||
use crate::cli::{BrightnessCommand, Mode, PixelCommand};
|
|
||||||
|
|
||||||
pub fn execute_mode(mode: Mode, connection: Connection) {
|
pub fn execute_mode(mode: Mode, connection: Connection) {
|
||||||
match mode {
|
match mode {
|
||||||
|
@ -22,6 +22,11 @@ fn pixels(connection: &Connection, pixel_command: PixelCommand) {
|
||||||
fn brightness(connection: &Connection, brightness_command: BrightnessCommand) {
|
fn brightness(connection: &Connection, brightness_command: BrightnessCommand) {
|
||||||
match brightness_command {
|
match brightness_command {
|
||||||
BrightnessCommand::Reset => brightness_reset(&connection),
|
BrightnessCommand::Reset => brightness_reset(&connection),
|
||||||
|
BrightnessCommand::Min => brightness_set(&connection, Brightness::MIN),
|
||||||
|
BrightnessCommand::Max => brightness_set(&connection, Brightness::MAX),
|
||||||
|
BrightnessCommand::Set { brightness } => {
|
||||||
|
brightness_set(&connection, Brightness::saturating_from(brightness))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,4 +42,11 @@ fn brightness_reset(connection: &Connection) {
|
||||||
.send(Command::Brightness(Brightness::MAX))
|
.send(Command::Brightness(Brightness::MAX))
|
||||||
.expect("Failed to reset brightness to maximum");
|
.expect("Failed to reset brightness to maximum");
|
||||||
info!("Reset brightness");
|
info!("Reset brightness");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn brightness_set(connection: &&Connection, brightness: Brightness) {
|
||||||
|
connection
|
||||||
|
.send(Command::Brightness(brightness))
|
||||||
|
.expect("Failed to set brightness");
|
||||||
|
info!("set brightness to {brightness:?}");
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue