set screen brightness
Some checks failed
Rust / build (push) Failing after 50s

This commit is contained in:
Vinzenz Schroeter 2025-02-08 13:57:05 +01:00
parent 8390b739da
commit 442da63c90
2 changed files with 22 additions and 4 deletions

View file

@ -1,5 +1,5 @@
#[derive(clap::Parser, std::fmt::Debug)]
#[clap(version)]
#[clap(version, arg_required_else_help = true)]
pub struct Cli {
#[arg(
short,
@ -19,7 +19,7 @@ pub struct Cli {
#[clap(subcommand)]
pub command: Mode,
#[clap(short, long, help = "verbose logging")]
pub verbose: bool
pub verbose: bool,
}
#[derive(clap::Parser, std::fmt::Debug)]
@ -48,6 +48,12 @@ pub enum PixelCommand {
pub enum BrightnessCommand {
#[command(visible_alias = "r")]
Reset,
#[command(visible_alias = "s")]
Set {
brightness: u8,
},
Min,
Max,
}
#[derive(clap::ValueEnum, Clone, Debug)]

View file

@ -1,6 +1,6 @@
use crate::cli::{BrightnessCommand, Mode, PixelCommand};
use log::info;
use servicepoint::{Brightness, Command, Connection};
use crate::cli::{BrightnessCommand, Mode, PixelCommand};
pub fn execute_mode(mode: Mode, connection: Connection) {
match mode {
@ -22,6 +22,11 @@ fn pixels(connection: &Connection, pixel_command: PixelCommand) {
fn brightness(connection: &Connection, brightness_command: BrightnessCommand) {
match brightness_command {
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))
}
}
}
@ -38,3 +43,10 @@ fn brightness_reset(connection: &Connection) {
.expect("Failed to reset brightness to maximum");
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:?}");
}